Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 12, 2025

Problem

When using the --set-formats command on Windows PowerShell to pair notebooks in different folders:

jupytext --set-formats notebooks//ipynb,scripts//py:percent notebooks/*.ipynb

The command failed with:

Paired paths 'notebooks/example.ipynb','scripts/example.py' do not include 
the current notebook path 'notebooks\example.ipynb'. Current format is 
'notebooks//ipynb', and paired formats are 'notebooks//ipynb,scripts//py:percent'.

Root Cause

The issue was in the separator() function in src/jupytext/paired_paths.py. When determining the appropriate path separator, the function checked if a backslash was present in the path:

if os.path.sep == "\\" and "\\" in path:
    return "\\"
return "/"

However, when base_path() stripped the directory prefix from notebooks\example.ipynb, it returned just 'example' (a bare filename with no separators). The separator('example') call then returned / on Windows because the string didn't contain \, causing a mismatch:

  • Input path: notebooks\example.ipynb (backslashes)
  • Generated paths: notebooks/example.ipynb, scripts/example.py (forward slashes)
  • Path comparison failed due to separator mismatch

Solution

Enhanced the separator() function to properly handle Windows paths in three cases:

  1. Path contains \ → return \ (Windows file path)
  2. Path contains / but not \ → return / (contents manager/format path)
  3. Path has no separators → return \ (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

  • Added test_paired_paths_windows_relative() to verify the fix with the exact reported scenario
  • Verified all existing Windows path tests still pass
  • Confirmed Unix/Linux behavior is unchanged
  • Verified Jupyter contents manager paths (using /) are preserved on Windows

Fixes issue where Windows users couldn't pair notebooks in different folders using relative paths.

Original prompt

This section details on the original issue you should resolve

<issue_title>Windows sync different folders</issue_title>
<issue_description>I'm using:

jupytext --set-formats notebooks//ipynb,scripts//py:percent notebooks/*.ipynb

in Windows PowerShell

That command resulted in:

Paired paths 'notebooks/example.ipynb','scripts/example.py' do not include the current notebook path 'notebooks\example.ipynb'. Current format is 'notebooks//ipynb', and paired formats are 'notebooks//ipynb,scripts//py:percent'.

I think this is OS specific bug?

NOTE: already using the latest pypi package of jupytext and using VSCode power shell</issue_description>

<agent_instructions>Hi @copilot, can you figure out what should be the pairing instructions on Windows?</agent_instructions>

Comments on the Issue (you are @copilot in this section)

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.

@github-actions
Copy link

Thank you for making this pull request.

Did you know? You can try it on Binder: Binder:lab or Binder:notebook.

Also, the version of Jupytext developed in this PR can be installed with pip:

HATCH_BUILD_HOOKS_ENABLE=true pip install git+https://github.com/mwouts/jupytext.git@copilot/fix-windows-sync-folders

(this requires nodejs, see more at Developing Jupytext)

- 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: mwouts <[email protected]>
Copilot AI changed the title [WIP] Fix folder syncing issue in Jupytext for Windows Fix Windows path separator issue in paired notebooks Oct 12, 2025
Copilot AI requested a review from mwouts October 12, 2025 19:48
@mwouts mwouts added this to the 1.18.0 milestone Oct 12, 2025
@mwouts mwouts marked this pull request as ready for review October 12, 2025 20:12
@mwouts mwouts merged commit 3b47cde into main Oct 12, 2025
4 of 16 checks passed
@mwouts mwouts deleted the copilot/fix-windows-sync-folders branch October 12, 2025 20:14
mwouts added a commit that referenced this pull request Oct 12, 2025
mwouts added a commit that referenced this pull request Oct 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows sync different folders

2 participants