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

Be able to specify --execute run_path from CLI #595

Closed
Skylion007 opened this issue Aug 26, 2020 · 5 comments · Fixed by #612
Closed

Be able to specify --execute run_path from CLI #595

Skylion007 opened this issue Aug 26, 2020 · 5 comments · Fixed by #612
Milestone

Comments

@Skylion007
Copy link
Contributor

Skylion007 commented Aug 26, 2020

So I have some ipynb files that only work if run the root of my project, but there doesn't seem to be an easy way to specify that the run_path should be the CWD instead of the path of input path or output path of the arguments. The only way to get something like this behavior appears to specify that the the output = '-', but this can be restrictive. Would you consider a CLI flag to specify what the run_path of the file should be? Perhaps as an optional parameter to--execute?

Alternatively, it might be useful as override similar to --output.

@mwouts
Copy link
Owner

mwouts commented Aug 30, 2020

Hello @Skylion007 , thanks for asking! Well I have a few questions/comments about this

So I have some ipynb files that only work if run the root of my project

Do these ipynb files run in Jupyter? I mean, are they located at the root of the project? Aren't the text versions at the same location? May Jupytext infer the correct location for running the notebook through the pairing information?

Would you consider a CLI flag to specify what the run_path of the file should be?

Well, I would have said that such an option should have been in jupyter nbconvert --execute rather than in jupytext --execute, but it does not seem to be in nbconvert... Maybe we see first if if we can automatically find the appropriate location for running the notebook, cf. my questions above?

@mwouts mwouts added this to the 1.6.0 milestone Aug 30, 2020
@Skylion007
Copy link
Contributor Author

They are located in an 'examples subfolder, but rely on data that is conventionally stored in the root folder of the project. So they aren't expect to run at either the location of the iPyNB.

Currently, I get around it by hard coding a %cd to the root of the project by using gitpython to find the root location of the project.

The ReadMe and such say that all scripts should be run from the root folder, so they are executed as python examples/script.py. The installation script for Colab CDs to the location of the root. This was partially driven by the fact that I couldn't find an equivalent to the __file__ attribute in iPython (it only exists in Python) and the fact the Colab notebooks only have direct access to themselves and nothing else (so the first thing the notebook has to do is clone the repo).

@mwouts
Copy link
Owner

mwouts commented Aug 30, 2020

I see... this was rather simple to implement. In the upcoming release 1.6.0 you will be able to execute the notebook with either one of:

jupytext script.py --run-path /absolute/path
jupytext script.py --run-path path/relative/to/notebook/path
jupytext script.py --run-path path/relative/to/current/path

@mwouts
Copy link
Owner

mwouts commented Aug 30, 2020

A release candidate is available here:

pip install jupytext==1.6.0rc0

@mwouts
Copy link
Owner

mwouts commented Sep 1, 2020

@Skylion007 , do you think you would have the opportunity to give a try to the RC? On my side everything seems OK, so I am thinking of doing the release tonight. Cheers!

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 a pull request may close this issue.

2 participants