diff --git a/HISTORY.rst b/HISTORY.rst index db6fbc165..addc78636 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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) ++++++++++++++++++++++ diff --git a/jupytext/contentsmanager.py b/jupytext/contentsmanager.py index f96acd348..795a317d5 100644 --- a/jupytext/contentsmanager.py +++ b/jupytext/contentsmanager.py @@ -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): diff --git a/tests/test_contentsmanager.py b/tests/test_contentsmanager.py index 5b89e2d52..333449fc7 100644 --- a/tests/test_contentsmanager.py +++ b/tests/test_contentsmanager.py @@ -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):