Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 9 additions & 1 deletion src/jupytext/paired_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "/"

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_paired_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
Loading