Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

Allow .nb.py as an alternative notebook extension #5

Closed
mwouts opened this issue Aug 14, 2018 · 3 comments
Closed

Allow .nb.py as an alternative notebook extension #5

mwouts opened this issue Aug 14, 2018 · 3 comments

Comments

@mwouts
Copy link
Owner

mwouts commented Aug 14, 2018

Allowing companion python scripts to have .nb.py extension rather than .py would possibly improve the user experience, as it

  • indicates more explicitly that the new file is a notebook
  • would support the case when a python script exists with the same name than the notebook (but with another content)
mwouts added a commit to mwouts/jupytext that referenced this issue Aug 15, 2018
@mwouts
Copy link
Owner Author

mwouts commented Aug 15, 2018

An initial implementation is available on branch v0.5.0. If I set the default config to

c.ContentsManager.default_nbrmd_formats = 'ipynb,nb.py'

then a jupyter notebook 'notebook.ipynb' is duplicated to a python only version with name 'notebook.nb.py', as expected. If I modify that file and reopen the notebook, then the inputs are up to date.

However, when I open a plain python file, say 'script.py' as a notebook, and save it, two additional files are created: 'script.ipynb' and also 'script.nb.py' (with contents identical to 'script.py'). Clearly

I will at least avoid generating two notebooks with the same extensions (not generate 'script.nb.py'), and think a bit more to the second case: should 'ipynb' files be generated only for extensions that are in 'nbrmd_formats' ? Or even, should 'nbrmd_formats' become a dictionary that tells which formats to save to, given the opened one?

mwouts added a commit to mwouts/jupytext that referenced this issue Aug 15, 2018
@mwouts
Copy link
Owner Author

mwouts commented Aug 18, 2018

The new format for nbrmd_formats, for version 0.5.0, is a list of extension groups. It is mostly compatible with the previous one.

  • when nbrmd_formats=="ipynb" (the default value), then py and Rmd files can be opened as notebooks, and an ipynb file is created when they are saved. Outputs are taken from there when file is reloaded. However, opening the ipynb file does not read nor py nor Rmd file.
  • when nbrmd_formats=="ipynb,py" then py is the source file for ipynb notebooks. Rmd notebook can be opened, but no ipynb file is created when Rmd is saved
  • when nbrmd_formats=="ipynb,py;ipynb,Rmd" then py is the source file for ipynb notebooks. Rmd notebook can be opened, and a ipynb file is updated/created when the Rmd is saved
  • when nbrmd_formats=="ipynb,py,Rmd" then py is the source file for ipynb notebooks. All three extensions are updated when one of these notebooks is saved.
  • when nbrmd_formats=="ipynb,nb.py;script.ipynb,py" then nb.py is the source file for ipynb notebooks and script.ipynb is the output file for py files.

mwouts added a commit to mwouts/jupytext that referenced this issue Aug 18, 2018
mwouts added a commit to mwouts/jupytext that referenced this issue Aug 21, 2018
@mwouts mwouts closed this as completed Aug 21, 2018
@grst
Copy link

grst commented Aug 27, 2018

This is indeed getting complicated.

I believe that instead of thinking of the configuration options first, we should think of the expected user experience first, and then how it can be implemented.

My expectations:

  • when opening a file of a certain extension (.py, .nb.py, .Rmd, .rmd, ...) the file is saved with the same extension
  • if configured correspondingly, create an .ipynb alongside to preserve outputs

To discuss

  • When opening an .ipynb, either

    • save as .ipynb, no text-only format changed, or
    • save as .ipynb + a predefined text-only format
  • When creating a new notebook, which extension to use?

    • ipynb only? -> in jupyterlab one can create arbitrary files manually
    • a text-only format specified in configuration (+ ipynb, if desired)
  • Should we support saving multiple text-only formats for the same file, e.g. ipynb + Rmd + nb.py?

    • Personally, I don't see a use-case in having a synchronized copy of e.g. Rmd and .nb.py. I am therefor in favor of supporting only a single text-only format per notebook, as it keeps things simpler. There is still the CLI to convert to different formats, if required.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants