Skip to content

Commit

Permalink
Ignore hidden config files when allow_hidden=False (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jun 30, 2022
1 parent 9a8b38f commit 112c6a3
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 20 deletions.
7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
-------------------

Expand Down
23 changes: 16 additions & 7 deletions jupytext/contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"""
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion jupytext/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Jupytext's version number"""

__version__ = "1.13.8"
__version__ = "1.13.9-dev"
5 changes: 5 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 3 additions & 5 deletions tests/test_cm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")

Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pre_commit_1_sync_with_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pre_commit_3_sync_black_nbstripout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pre_commit_5_reformat_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pre_commit_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 112c6a3

Please sign in to comment.