You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using JupyterBook to publish docs in a way that allows users to open the notebooks on colab or binder.
To ensure colab has access to our package, our notebooks typically start with a block like this:
Normally one would immediately follow that shell command with another import package, but we perform that down below so that we can strip the above code from our published docs.
When testing the notebooks using Jupytext, the next line of code will cause an IndentError.
For instance, if the next line of code is:
import numpy as np
Then when running:
jupytext --check 'pytest {}' my_notebook.ipynb
we'd see something like:
File "/var/folders/v5/8bxf_lxx6wz5t5s099qr99w00000gq/T/paraboloid_sczvu3bt.py", line 35
import numpy as np
^
IndentationError: expected an indented block
We can fix this by including an indented pass after the shell command:
It seems as if the shell command is just being stripped from the code, and therefore python needs the next line to be indented. Would it be possible to just replace the shell command with pass so the explicit pass isn't necessary?
The text was updated successfully, but these errors were encountered:
which is not a complete Python paragraph. As you mention, adding an explicit pass below the bash command is one way to solve this, and I have seen this approach in use at other places like #694.
Maybe another possibility would be to comment out entirely that cell in the .py representation passed to pytest. Would you like to try adding an active-ipynb cell tag to the try/pip install cell?
Regarding your suggestion that Jupytext itself could insert the pass command, I'd prefer not to explore that direction as it would make round trips more difficult to handle (e.g. how could we determine whether pass was initially in the notebook, or not?)
I'm using JupyterBook to publish docs in a way that allows users to open the notebooks on colab or binder.
To ensure colab has access to our package, our notebooks typically start with a block like this:
Normally one would immediately follow that shell command with another
import package
, but we perform that down below so that we can strip the above code from our published docs.When testing the notebooks using Jupytext, the next line of code will cause an IndentError.
For instance, if the next line of code is:
Then when running:
we'd see something like:
We can fix this by including an indented
pass
after the shell command:It seems as if the shell command is just being stripped from the code, and therefore python needs the next line to be indented. Would it be possible to just replace the shell command with
pass
so the explicitpass
isn't necessary?The text was updated successfully, but these errors were encountered: