Skip to content

Commit 3b47cde

Browse files
Copilotmwouts
andauthored
Fix Windows path separator issue in paired notebooks (#1454)
* Fix Windows path separator issue in paired_paths - Updated separator() function to handle bare filenames on Windows - Added test case for Windows pairing with relative paths - Fixes issue where notebooks\example.ipynb was not recognized in paired paths Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mwouts <29915202+mwouts@users.noreply.github.com> Co-authored-by: Marc Wouts <marc.wouts@gmail.com>
1 parent bc4f23e commit 3b47cde

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Jupytext ChangeLog
1515
- 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.
1616
- 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).
1717
- We have fixed a parsing error for R Markdown files ([#1429](https://github.com/mwouts/jupytext/issues/1429))
18+
- Complex pairing formats are now supported on Windows ([#1028](https://github.com/mwouts/jupytext/issues/1028))
1819

1920
**Changed**
2021
- 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))

src/jupytext/paired_paths.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ def join(left, right, sep):
6161

6262
def separator(path):
6363
"""Return the local path separator (always / in the contents manager)"""
64-
if os.path.sep == "\\" and "\\" in path:
64+
# On Windows, determine the appropriate separator
65+
if os.path.sep == "\\":
66+
# If path contains \, definitely use Windows separator
67+
if "\\" in path:
68+
return "\\"
69+
# If path contains / but not \, it's probably a format string or contents manager path
70+
if "/" in path:
71+
return "/"
72+
# Path has no separators (e.g., bare filename) - use OS separator
6573
return "\\"
6674
return "/"
6775

tests/unit/test_paired_paths.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ def test_paired_paths_windows_no_subfolder():
9999
paired_paths(nb_file, "notebooks///ipynb", formats)
100100

101101

102+
def test_paired_paths_windows_relative():
103+
"""Test Windows pairing with relative paths and backslash as path separator, issue #1028"""
104+
nb_file = "notebooks\\example.ipynb"
105+
formats = "notebooks///ipynb,scripts///py:percent"
106+
with mock.patch("os.path.sep", "\\"):
107+
# Should not raise InconsistentPath
108+
paths = paired_paths(nb_file, "notebooks///ipynb", formats)
109+
# Verify the notebook path is in the paired paths
110+
path_list = [p[0] for p in paths]
111+
assert nb_file in path_list, f"Expected {nb_file} to be in paired paths {path_list}"
112+
# Verify both paths use backslashes on Windows
113+
assert paths[0][0] == "notebooks\\example.ipynb"
114+
assert paths[1][0] == "scripts\\example.py"
115+
116+
102117
@pytest.mark.parametrize("os_path_sep", ["\\", "/"])
103118
def test_paired_path_dotdot_564(os_path_sep):
104119
main_path = os_path_sep.join(["examples", "tutorials", "colabs", "rigid_object_tutorial.ipynb"])

0 commit comments

Comments
 (0)