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

nbrmd creates .py file although not specified. #16

Closed
grst opened this issue Jul 18, 2018 · 6 comments
Closed

nbrmd creates .py file although not specified. #16

grst opened this issue Jul 18, 2018 · 6 comments

Comments

@grst
Copy link
Contributor

grst commented Jul 18, 2018

In my jupyter config I set:

c.NotebookApp.contents_manager_class = 'nbrmd.RmdFileContentsManager'
c.ContentsManager.default_nbrmd_formats = ['.ipynb', '.Rmd']

I created a minimal .Rmd file test.Rmd

# My RMD notebook

```{python}
print("Hello World!2")
```

Some more markdown text.

and open it in jupyter. When I re-save the notebook, the following files are created:

test.Rmd
test.ipynb
test.py

Given my configuration, I think the test.py should not be there.

When I investigate test.Rmd in a text editor, the following metadata has been added:

 nbrmd_formats:
  - .ipynb
  - .Rmd
  - .py
  nbrmd_sourceonly_format: .Rmd

I am using the 0.3.0 release from pypi.

@mwouts
Copy link
Owner

mwouts commented Jul 18, 2018

Thanks @grst for reporting. This is interesting, I will have a look.

@mwouts
Copy link
Owner

mwouts commented Jul 18, 2018

Well, I don't get the .py file on my first config, but anyway there seem to be something wrong... Jupyter says

[W 00:07:00.788 NotebookApp] Config option `default_nbrmd_formats` not recognized by `RmdFileContentsManager`.

@mwouts
Copy link
Owner

mwouts commented Jul 18, 2018

Gregor, I have not been able to reproduce yet, but I have fixed the error message above.
Flag 'default_nbrmd_formats' is now a Unicode configurable in version 0.4.0.
Would you mind to update your jupyter config to the below?

c.NotebookApp.contents_manager_class = 'nbrmd.RmdFileContentsManager'
c.ContentsManager.default_nbrmd_formats = 'ipynb,Rmd'

Also, if the issue remains, could you please quote the content of the py file?
Thanks

@grst
Copy link
Contributor Author

grst commented Jul 20, 2018

I can confirm that the py file is gone.

The following issue remains: (not sure if that's expected)

Procedure:

  • config just contains this line: c.NotebookApp.contents_manager_class = 'nbrmd.RmdFileContentsManager'.
  • create a minimal test.Rmd (e.g. from above)
  • open in jupyter notebook, make a change and save.

Results:

  • Rmd is updated
  • ipynb is created (or overwritten)

Intuitively, I would have expected the ipynb to be created only if both formats are specified using the default_nbrmd_formats flag.

If I close the Rmd file and open the ipynb file and make changes to it, these are only written to ipynb and not Rmd (expected).


With the default_nbrmd_formats flag enabled, both notebooks are synchronized as expected 🎉


Current version v0.4.1 from pip.

@mwouts
Copy link
Owner

mwouts commented Jul 20, 2018

The default value for default_nbrmd_formats is 'ipynb', and that is responsible for what you observe. The point in having that default value is to preserve outputs for source-only notebooks.

If you want to only have the Rmd notebook updated, you could use

c.NotebookApp.contents_manager_class = 'nbrmd.RmdFileContentsManager'
c.ContentsManager.default_nbrmd_formats = ''

As you point out, with the default value for default_nbrmd_formats='ipynb', the files being updated depend on the one you actually opened in Jupyter. If you open and save Rmd, both files are updated, while if you open the other, only the ipynb one is updated. Maybe we should add to the ipynb file some flag to indicate that it works in pair with the Rmd one? And be careful not causing #17 again?

@grst
Copy link
Contributor Author

grst commented Jul 20, 2018

The default value for default_nbrmd_formats is 'ipynb', and that is responsible for what you observe. The point in having that default value is to preserve outputs for source-only notebooks.

In that case, why not make

c.ContentsManager.default_nbrmd_formats = 'ipynb,Rmd'

the default?

Otherwise, I'm also happy to leave everything as it is, maybe just make the behavior clear in the docs.

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

No branches or pull requests

2 participants