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

Test: Export to Python Scripts without needing to install nbconvert #135666

Closed
2 tasks done
IanMatthewHuff opened this issue Oct 22, 2021 · 2 comments
Closed
2 tasks done

Comments

@IanMatthewHuff
Copy link
Member

IanMatthewHuff commented Oct 22, 2021

Refs: microsoft/vscode-jupyter#5222

Complexity: 3
Author: @IanMatthewHuff

Create Issue


File bugs on the Jupyter repo here: https://github.com/microsoft/vscode-jupyter/issues

Previously we did all exporting to python from the interactive window or from a jupyter notebook document via a single global install of the nbconvert python package. This caused the following issues 1. NBConvert must be installed somewhere, 2. Requires running Python code 3. NBConvert is slow to work. So we did work this last sprint to allow for a much quicker plain export of notebooks (or interactive window) to python scripts just using typescript code.

We now have a setting jupyter.pythonExportMethod with three settings. direct moves over the exact code from notebook cells into the python file as is, and is the default setting. This does mean that ipython magic commands such as %whos (which are not valid python) are copied over as is. commentMagics setting does a very basic per line check to comment out one line magics and shell commands from the notebook code when converting to the python file. nbconvert setting uses nbconvert as the previous code did. Nb convert will do a full conversion of ipython syntax (!shell commands %magic commands) into valid python syntax.

If you have never done an export before you might get a prompt to install 'nbconvert' python module when using the 'nbconvert' mode. We didn't specifically address any issues with that mode, but we have had some reports of the install not working correctly here, so if you see issues please file them regarding that as well.

Testing for this is as follows:

  1. Install the latest Jupyter Insiders Extension + Python Extension
  2. Grab or create a few notebook documents (not providing any as the more variety that we have here the better). Documents should have both code and markdown cells.
  3. Open the documents in Visual Studio Code
  4. Using the "Jupyter: Export" commands or the Export button in the notebook UI try exporting the documents using all three of the settings above.
  5. The export should create a new .py file for all three settings. In 'direct' mode magic commands like %whos should be ported directly. In 'commentMagics' lines leading with a jupyter magic or shell command should be commented out. In 'nbconvert' mode magics and shells should be converted to get_ipython() syntax.
  6. Markdown cells should have a markdown cell marker in the .py file (# %% [markdown]) by default and should be commented out.
  7. Run some sample code in the python interactive window. Perform the same steps from the interactive window for all three exports as above.

Example:

image
image
Expected file with 'direct' export:
image
Expected file with 'commentMagics' export:
image
Expected file with 'nbconvert' export:
image

Known issues:
The commentMagics setting is very basic, it will just comment out magics and shell commands that lead lines. It won't comment out things like cell or magic assignments: https://ipython.readthedocs.io/en/stable/interactive/python-ipython-diff.html such as my_files = !ls.

Note: I'll be out the first day or two of endgame, but available for help starting Wed the 27th.

@bamurtaugh
Copy link
Member

@IanMatthewHuff Removing my assignment for now as I've gone through variations of the steps mentioned above. But since I can't seem to find a way to get the nbconvert setting to work, if you'd like me re-test with a different set up or with some troubleshooting, please just reassign me. Thank you!

@bamurtaugh bamurtaugh removed their assignment Oct 26, 2021
@rzhao271 rzhao271 removed their assignment Oct 26, 2021
@IanMatthewHuff
Copy link
Member Author

@bamurtaugh No don't worry about it. Thanks for the testing. We added the new paths to export without requiring nbconvert, but the nbconvert still has a path that doesn't correctly prompt for the install. We're going to handle this with a follow up fix next release.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants