Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dlt commands as Jupyter Notebook magic commands #793

Open
wants to merge 91 commits into
base: devel
Choose a base branch
from

Conversation

Vasilije1990
Copy link
Collaborator

@Vasilije1990 Vasilije1990 commented Nov 29, 2023

Description

Non-interactive ipython magics that work in the notebooks or in the Ipython shell

  • [ x] add magics for init, pipeline and other commands

  • [ x] there's a known limitation on Colab - their file editor cannot show files starting with . the result is that users do not see the .dlt folder with secrets and configs. we should solve this somehow. ie. by dlt init that detects running on colab (there's a helper) and then creates a link ie. _dlt that is visible

  • add a demo colab notebook and documentation to reference section of the docs -> Note, documentation was added, but there is a question of the colab notebook.

  • run a notebook in Databrics

Implements #502

Copy link

netlify bot commented Nov 29, 2023

Deploy Preview for dlt-hub-docs canceled.

Name Link
🔨 Latest commit 91d2f72
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/65ae5823bde90b00087c2a7c

Copy link
Collaborator

@rudolfix rudolfix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this PR. it looks good! adding magics is really like writing cli with click library. maybe we'll switch from argparse to click.

what is most important in review:

  1. please investigate if we really cannot take user input. I was able to take it when launching dlt cli via !dlt ...
    maybe regular Python input works. ie like in here. just placing input in a cell definitely works
from IPython.core.magic import register_line_magic

@register_line_magic
def confirm_magic(line):
    # Splitting the arguments if you have any
    args = line.split()

    # Your custom operation logic
    print("Starting the operation...")

    # Interactive part
    confirmation = input("Do you want to continue? [y/n]: ")
    if confirmation.lower() == 'y':
        print("Operation confirmed.")
        # Place the rest of your operation here
    else:
        print("Operation cancelled.")

# Use the line magic with '%confirm_magic'
  1. if that does not work - I have an idea how to use non interactive mode and some slight echo.confirm modifications instead of all ifs you added. please see my review
  2. please see my remarks in pyproject.toml

what else we need

  1. docs are started but not yet finished
  2. we need to figure out if there's any decent way to write a test for a magic. this may be complicated. I can surely help with that

dlt/__init__.py Outdated Show resolved Hide resolved
dlt/__init__.py Outdated Show resolved Hide resolved
dlt/cli/deploy_command_helpers.py Outdated Show resolved Hide resolved
dlt/cli/echo.py Outdated Show resolved Hide resolved
dlt/cli/init_command.py Outdated Show resolved Hide resolved
dlt/cli/magics.py Outdated Show resolved Hide resolved
# Import get_ipython from IPython
from IPython import get_ipython
# Get the class name of the current IPython instance
shell = get_ipython().__class__.__name__
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you have a false positive? so notebook detected while not being in the environment? what was wrong with previous function?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you can have get_ipython() returning true without actually being a notebook?

dlt/common/runtime/exec_info.py Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
dlt/cli/magics.py Outdated Show resolved Hide resolved
This reverts commit d5bf33f.
Copy link
Collaborator

@rudolfix rudolfix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my quick manual testing:

  • detecting notebook presence was changed and now colab is not detected as notebook
  • so the _dlt alias is not created
  • documentation to magics does not mention that you need import dlt first
  • magics are decorated in a way that positional arguments are optional that should not be the case
  • would be cool to tell people how to get help ie %init? gives you argument for init
    @sh-rp @AstrakhantsevaAA still it would be good to merge it somehow... on a notebook it will be really helpful

@burnash burnash changed the title Resolves issue #502 Add dlt commands as Jupyter Notebook magic commands Feb 18, 2024
@sultaniman sultaniman self-assigned this Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants