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

Calling jupyter-execute runs the notebook but doesn't save it #306

Closed
wpk-nist-gov opened this issue Feb 29, 2024 · 5 comments · Fixed by #307
Closed

Calling jupyter-execute runs the notebook but doesn't save it #306

wpk-nist-gov opened this issue Feb 29, 2024 · 5 comments · Fixed by #307

Comments

@wpk-nist-gov
Copy link
Contributor

wpk-nist-gov commented Feb 29, 2024

I'm trying to execute notebooks from the command line using jupyter-execute with the minimum number of dependencies (I just want to run and save the notebook, and nbconvert is overkill for this). If I use an environment with only "nbclient" and "ipykernel", running jupyter execute notebook.ipynb runs the notebook, but does not save the results anywhere. There's no call back to nbformat.write anywhere in cli.py!.

Is this intended behavior? If not, I think adding nbformat.write(nb, input_path) after the notebook is executed will fix it.

Thanks!

wpk-nist-gov pushed a commit to wpk-nist-gov/nbclient that referenced this issue Feb 29, 2024
Fixes jupyter#306.

Now actually write out the executed notebook to the same path
as the input.
@davidbrochart
Copy link
Member

Yes, the intended behavior of the run_notebook method is just to run the notebook.

@wpk-nist-gov
Copy link
Contributor Author

wpk-nist-gov commented Mar 1, 2024

OK. Any chance this functionality could/should be added to cli.py with, e.g., a --to flag? Like I said, I'm trying to avoid using nbconvert.

I'm probably misunderstanding something, but I don't understand the purpose of the cli interface without the option to save.

@davidbrochart
Copy link
Member

The notebook could have side effects, like saving files. But I'm not against adding an option in the CLI to save the notebook. Let's see how other people feel about that.

@wpk-nist-gov
Copy link
Contributor Author

Sounds good. I'll put an optional write in the linked PR for demo purposes.

@wpk-nist-gov
Copy link
Contributor Author

wpk-nist-gov commented Mar 4, 2024

I updated #307 to optionally save the executed notebook.

blink1073 pushed a commit that referenced this issue Mar 12, 2024
* fix: Actually write out executed notebook in jupyter-execute

Fixes #306.

Now actually write out the executed notebook to the same path
as the input.

* feat:  Added cli options to save executed notebook

This commit adds two options to optionally save the executed notebook.

* `--inplace`:  Save the executed notebook to the input notebook path
* `--output`: Save the executed notebook to `output`.  This option
  can take a pattern like `{notebook_name}-new`, where `notebook_name` is
  the name of the input notebook without extension `.ipynb`.  Also, the
  output location is always relative to the input notebook location.

* chore: update mocker for opening files to remove error

---------

Co-authored-by: wpk <william.krekelberg@nist.gov>
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