Fix Windows path separator issue in paired notebooks #1454
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When using the
--set-formatscommand on Windows PowerShell to pair notebooks in different folders:The command failed with:
Root Cause
The issue was in the
separator()function insrc/jupytext/paired_paths.py. When determining the appropriate path separator, the function checked if a backslash was present in the path:However, when
base_path()stripped the directory prefix fromnotebooks\example.ipynb, it returned just'example'(a bare filename with no separators). Theseparator('example')call then returned/on Windows because the string didn't contain\, causing a mismatch:notebooks\example.ipynb(backslashes)notebooks/example.ipynb,scripts/example.py(forward slashes)Solution
Enhanced the
separator()function to properly handle Windows paths in three cases:\→ return\(Windows file path)/but not\→ return/(contents manager/format path)\(bare filename on Windows - the key fix)This ensures that when rebuilding paths from a bare filename on Windows, the OS separator is used, maintaining consistency with the input path.
Testing
test_paired_paths_windows_relative()to verify the fix with the exact reported scenario/) are preserved on WindowsFixes issue where Windows users couldn't pair notebooks in different folders using relative paths.
Original prompt
Fixes #1028
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.