Skip to content

Commit

Permalink
Notebook extensions may be prefixed with .nb only #87
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Sep 29, 2018
1 parent 498d59e commit d91b15a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Release History
is straightforward - just add a new entry to _SCRIPT_EXTENSIONS in languages.py, a sample notebook
and a mirror test (#61)

**BugFixes**

- Notebooks extensions can only be prefixed with `.nb` to solve #87


0.7.1 (2018-09-24)
++++++++++++++++++++++
Expand Down
5 changes: 4 additions & 1 deletion jupytext/contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ def file_fmt_ext(path):
"""
file, ext = os.path.splitext(path)
file, intermediate_ext = os.path.splitext(file)
return file, intermediate_ext + ext, ext
if intermediate_ext in ['.nb']:
return file, intermediate_ext + ext, ext
else:
return file + intermediate_ext, ext, ext


class TextFileContentsManager(FileContentsManager, Configurable):
Expand Down
28 changes: 28 additions & 0 deletions tests/test_contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ def test_load_save_rename_nbpy(nb_file, tmpdir):
assert os.path.isfile(str(tmpdir.join('new.nb.py')))


@skip_if_dict_is_not_ordered
@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_py'))
def test_load_save_rename_notebook_with_dot(nb_file, tmpdir):
tmp_ipynb = '1.notebook.ipynb'
tmp_nbpy = '1.notebook.py'

cm = jupytext.TextFileContentsManager()
cm.default_jupytext_formats = 'ipynb,py'
cm.root_dir = str(tmpdir)

# open ipynb, save nb.py, reopen
nb = jupytext.readf(nb_file)
cm.save(model=dict(type='notebook', content=nb), path=tmp_nbpy)
nbpy = cm.get(tmp_nbpy)
compare_notebooks(nb, nbpy['content'])

# save ipynb
cm.save(model=dict(type='notebook', content=nb), path=tmp_ipynb)

# rename py
cm.rename(tmp_nbpy, '2.new.py')
assert not os.path.isfile(str(tmpdir.join(tmp_ipynb)))
assert not os.path.isfile(str(tmpdir.join(tmp_nbpy)))

assert os.path.isfile(str(tmpdir.join('2.new.ipynb')))
assert os.path.isfile(str(tmpdir.join('2.new.py')))


@skip_if_dict_is_not_ordered
@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_py'))
def test_load_save_rename_nbpy_default_config(nb_file, tmpdir):
Expand Down

0 comments on commit d91b15a

Please sign in to comment.