From 112c6a338d03f72aea9809f91aa9710bf33b3f7e Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Thu, 30 Jun 2022 11:07:49 +0200 Subject: [PATCH] Ignore hidden config files when allow_hidden=False (#965) --- docs/CHANGELOG.md | 7 ++++++ jupytext/contentsmanager.py | 23 +++++++++++++------ jupytext/version.py | 2 +- tests/test_cli.py | 5 ++++ tests/test_cm_config.py | 8 +++---- tests/test_pre_commit_1_sync_with_config.py | 2 +- ...test_pre_commit_3_sync_black_nbstripout.py | 4 ++-- tests/test_pre_commit_5_reformat_markdown.py | 4 ++-- tests/test_pre_commit_mode.py | 4 ++-- 9 files changed, 39 insertions(+), 20 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9d34262aa..e76980f04 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,13 @@ Jupytext ChangeLog ================== +1.13.9 (2022-06-30) +------------------- + +**Changed** +- Hidden configuration files like `.jupytext.toml` or `.jupytext.py` are now ignored by Jupytext's contents manager when `allow_hidden=False` (that option was introduced in `jupyter_server==2.0.0a1`) ([#964](https://github.com/mwouts/jupytext/issues/964)). + + 1.13.8 (2022-04-04) ------------------- diff --git a/jupytext/contentsmanager.py b/jupytext/contentsmanager.py index 2a67715bc..076107edc 100644 --- a/jupytext/contentsmanager.py +++ b/jupytext/contentsmanager.py @@ -504,6 +504,11 @@ def get_config_file(self, directory): for jupytext_config_file in JUPYTEXT_CONFIG_FILES: path = directory + "/" + jupytext_config_file if self.file_exists(path): + if not self.allow_hidden and jupytext_config_file.startswith("."): + self.log.warning( + f"Ignoring config file {path} (see Jupytext issue #964)" + ) + continue return path pyproject_path = directory + "/" + PYPROJECT_FILE @@ -529,10 +534,16 @@ def load_config_file(self, config_file, is_os_path=False): if config_file.endswith(".py") and not is_os_path: config_file = self._get_os_path(config_file) is_os_path = True - if is_os_path: - return load_jupytext_configuration_file(config_file) - model = self.super.get(config_file, content=True, type="file") - return load_jupytext_configuration_file(config_file, model["content"]) + + config_content = None + if not is_os_path: + try: + model = self.super.get(config_file, content=True, type="file") + config_content = model["content"] + except HTTPError: + pass + + return load_jupytext_configuration_file(config_file, config_content) def get_config(self, path, use_cache=False): """Return the Jupytext configuration for the given path""" @@ -548,9 +559,7 @@ def get_config(self, path, use_cache=False): self.cached_config.config = self.load_config_file(config_file) else: config_file = find_global_jupytext_configuration_file() - self.cached_config.config = self.load_config_file( - config_file, True - ) + self.cached_config.config = self.load_config_file(config_file) self.cached_config.config_file = config_file self.cached_config.path = parent_dir except JupytextConfigurationError as err: diff --git a/jupytext/version.py b/jupytext/version.py index 044049a09..91f66e0f6 100644 --- a/jupytext/version.py +++ b/jupytext/version.py @@ -1,3 +1,3 @@ """Jupytext's version number""" -__version__ = "1.13.8" +__version__ = "1.13.9-dev" diff --git a/tests/test_cli.py b/tests/test_cli.py index d30342d6f..6027e59b4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1174,6 +1174,11 @@ def no_warning(): "and will be removed in a future release" in str(record.message) ): continue # pragma: no cover + if ( + "unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>" + in str(record.message) + ): + continue # pragma: no cover raise RuntimeError(record) diff --git a/tests/test_cm_config.py b/tests/test_cm_config.py index 35a850164..7f540bd49 100644 --- a/tests/test_cm_config.py +++ b/tests/test_cm_config.py @@ -24,7 +24,7 @@ def test_local_config_overrides_cm_config(tmpdir): cm.formats = "ipynb,py" nested = tmpdir.mkdir("nested") - with open(str(nested.join(".jupytext.yml")), "w") as fp: + with open(str(nested.join("jupytext.yml")), "w") as fp: fp.write("formats: ''\n") cm.save(notebook_model(SAMPLE_NOTEBOOK), "notebook.ipynb") @@ -61,7 +61,7 @@ def test_pairing_through_config_leaves_ipynb_unmodified(tmpdir): cm = jupytext.TextFileContentsManager() cm.root_dir = str(tmpdir) - cfg_file = tmpdir.join(".jupytext.yml") + cfg_file = tmpdir.join("jupytext.yml") nb_file = tmpdir.join("notebook.ipynb") py_file = tmpdir.join("notebook.py") @@ -84,8 +84,6 @@ def test_pairing_through_config_leaves_ipynb_unmodified(tmpdir): ("jupytext.toml", "not_a_jupytext_option = true"), ("pyproject.toml", "[tool.jupytext]\nnot_a_jupytext_option = true"), ("jupytext.json", '{"notebook_metadata_filter":"-all",}'), - (".jupytext.py", "c.not_a_jupytext_option = True"), - (".jupytext.py", "c.hide_notebook_metadata = true"), ], ) @pytest.mark.filterwarnings( @@ -199,7 +197,7 @@ def test_test_no_text_representation_metadata_in_ipynb_900( tmpdir, python_notebook, ): - tmpdir.join(".jupytext.toml").write('formats = "ipynb,py:percent"\n') + tmpdir.join("jupytext.toml").write('formats = "ipynb,py:percent"\n') # create a test notebook and save it in Jupyter nb = python_notebook diff --git a/tests/test_pre_commit_1_sync_with_config.py b/tests/test_pre_commit_1_sync_with_config.py index 17dd9380f..1bb3adaec 100644 --- a/tests/test_pre_commit_1_sync_with_config.py +++ b/tests/test_pre_commit_1_sync_with_config.py @@ -34,7 +34,7 @@ def test_pre_commit_hook_sync_with_config( tmp_repo.git.add(".pre-commit-config.yaml") pre_commit(["install", "--install-hooks", "-f"]) - tmpdir.join(".jupytext.toml").write('formats = "ipynb,py:percent"\n') + tmpdir.join("jupytext.toml").write('formats = "ipynb,py:percent"\n') # create a test notebook and save it in Jupyter nb = python_notebook diff --git a/tests/test_pre_commit_3_sync_black_nbstripout.py b/tests/test_pre_commit_3_sync_black_nbstripout.py index cb2cec306..db04796b9 100644 --- a/tests/test_pre_commit_3_sync_black_nbstripout.py +++ b/tests/test_pre_commit_3_sync_black_nbstripout.py @@ -46,8 +46,8 @@ def test_pre_commit_hook_sync_black_nbstripout( tmp_repo.git.add(".pre-commit-config.yaml") pre_commit(["install", "--install-hooks", "-f"]) - tmpdir.join(".jupytext.toml").write('formats = "ipynb,py:percent"') - tmp_repo.git.add(".jupytext.toml") + tmpdir.join("jupytext.toml").write('formats = "ipynb,py:percent"') + tmp_repo.git.add("jupytext.toml") tmp_repo.index.commit("pair notebooks") # write a test notebook diff --git a/tests/test_pre_commit_5_reformat_markdown.py b/tests/test_pre_commit_5_reformat_markdown.py index a0885335b..86c04e1ee 100644 --- a/tests/test_pre_commit_5_reformat_markdown.py +++ b/tests/test_pre_commit_5_reformat_markdown.py @@ -55,8 +55,8 @@ def test_pre_commit_hook_sync_reformat_code_and_markdown( tmp_repo.git.add(".pre-commit-config.yaml") pre_commit(["install", "--install-hooks", "-f"]) - tmpdir.join(".jupytext.toml").write('formats = "ipynb,py:percent"') - tmp_repo.git.add(".jupytext.toml") + tmpdir.join("jupytext.toml").write('formats = "ipynb,py:percent"') + tmp_repo.git.add("jupytext.toml") tmp_repo.index.commit("pair notebooks") # write a test notebook diff --git a/tests/test_pre_commit_mode.py b/tests/test_pre_commit_mode.py index a552b4360..ec35f08dc 100644 --- a/tests/test_pre_commit_mode.py +++ b/tests/test_pre_commit_mode.py @@ -65,7 +65,7 @@ def test_alert_untracked_alerts_when_using_sync(tmpdir, cwd_tmpdir, tmp_repo, ca tmpdir.join("test.py").write("print('hello')\n") tmp_repo.git.add("test.py") - tmpdir.join(".jupytext.toml").write('formats = "ipynb,py"') + tmpdir.join("jupytext.toml").write('formats = "ipynb,py"') # Run jupytext status = jupytext(["--sync", "--pre-commit-mode", "test.py"]) @@ -133,7 +133,7 @@ def test_alert_inconsistent_versions(tmpdir, cwd_tmpdir, tmp_repo, capsys): def test_pre_commit_local_config(tmpdir, cwd_tmpdir, tmp_repo, python_notebook, capsys): - tmpdir.join(".jupytext.toml").write_text( + tmpdir.join("jupytext.toml").write_text( """notebook_metadata_filter = "-all" cell_metadata_filter = "-all" formats = "ipynb,py:percent"