diff --git a/CHANGELOG.md b/CHANGELOG.md index d55e2108..f50c565c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Jupytext ChangeLog - Jupytext now support more characters in the cell metadata keys, to improve compatibility with `jupyterlab-slideshow` ([#1441](https://github.com/mwouts/jupytext/issues/1441)). Thanks to [Nicolas Thierry](https://github.com/nthiery) for this fix. - The function `find_jupytext_configuration_file` now works with relative directories ([#1440](https://github.com/mwouts/jupytext/issues/1440)). This fix was contributed by [Thierry Parmentelat](https://github.com/parmentelat). - We have fixed a parsing error for R Markdown files ([#1429](https://github.com/mwouts/jupytext/issues/1429)) +- Complex pairing formats are now supported on Windows ([#1028](https://github.com/mwouts/jupytext/issues/1028)) **Changed** - We have updated the pre-commit hooks. The code is now formatted using `ruff format`, and updated for Python 3.9+ using https://github.com/asottile/pyupgrade ([#1423](https://github.com/mwouts/jupytext/issues/1423)) diff --git a/src/jupytext/paired_paths.py b/src/jupytext/paired_paths.py index 0258215c..eaf08d4b 100644 --- a/src/jupytext/paired_paths.py +++ b/src/jupytext/paired_paths.py @@ -61,7 +61,15 @@ def join(left, right, sep): def separator(path): """Return the local path separator (always / in the contents manager)""" - if os.path.sep == "\\" and "\\" in path: + # On Windows, determine the appropriate separator + if os.path.sep == "\\": + # If path contains \, definitely use Windows separator + if "\\" in path: + return "\\" + # If path contains / but not \, it's probably a format string or contents manager path + if "/" in path: + return "/" + # Path has no separators (e.g., bare filename) - use OS separator return "\\" return "/" diff --git a/tests/unit/test_paired_paths.py b/tests/unit/test_paired_paths.py index 256df5b6..bf97f91e 100644 --- a/tests/unit/test_paired_paths.py +++ b/tests/unit/test_paired_paths.py @@ -99,6 +99,21 @@ def test_paired_paths_windows_no_subfolder(): paired_paths(nb_file, "notebooks///ipynb", formats) +def test_paired_paths_windows_relative(): + """Test Windows pairing with relative paths and backslash as path separator, issue #1028""" + nb_file = "notebooks\\example.ipynb" + formats = "notebooks///ipynb,scripts///py:percent" + with mock.patch("os.path.sep", "\\"): + # Should not raise InconsistentPath + paths = paired_paths(nb_file, "notebooks///ipynb", formats) + # Verify the notebook path is in the paired paths + path_list = [p[0] for p in paths] + assert nb_file in path_list, f"Expected {nb_file} to be in paired paths {path_list}" + # Verify both paths use backslashes on Windows + assert paths[0][0] == "notebooks\\example.ipynb" + assert paths[1][0] == "scripts\\example.py" + + @pytest.mark.parametrize("os_path_sep", ["\\", "/"]) def test_paired_path_dotdot_564(os_path_sep): main_path = os_path_sep.join(["examples", "tutorials", "colabs", "rigid_object_tutorial.ipynb"])