mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.65k stars 386 forks source link

cli glob processing on windows #629

Open delmarrerikaine opened 4 years ago

delmarrerikaine commented 4 years ago

jupytext.paired_paths.InconsistentPath is thrown when using glob patterns on windows10 with jupytext cli Steps to reproduce: 1) jupytext.yml configuration file:

default_jupytext_formats: "notebooks///ipynb,scripts///py:percent"
default_notebook_metadata_filter: "jupytext"

2) put any py:percent script inside of scripts directory 3) run jupytext --sync scripts/*.py

Expected:

Actual:

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

The difference between expected path and received is: "scripts/example.py" - "scripts\example.py" If we will run jupytext --sync scripts/example.py the behavior matches to the expected one.

Are there any workarounds to execute cli with glob on windows?

mwouts commented 4 years ago

Thank you @delmarrerikaine for the clear report. I'll try to reproduce this with a test, and fix it.

mwouts commented 4 years ago

Hi @delmarrerikaine , I was having a look at this. Is this test representative of your issue? https://github.com/mwouts/jupytext/blob/8244821e70fce94b947ebe1b260c9a2e99380bc9/tests/test_cli_config.py#L148-L161

The tests is in success at least here locally... soon we'll see on the CI. And if I run the commands in an Anaconda Powershell Prompt, they seem to yield the expected result: image

So maybe the problem is elsewhere... Can you let me know

delmarrerikaine commented 4 years ago

Hi @mwouts, Thanks for looking into this! Your example is representative of my issue.

The difference between my and yours:

Therefore my needs are resolved with this change. Thanks!

jupytext version is 1.6.0 nothing specific in py:percent file Please let me know if there are any other details I can provide.

mwouts commented 4 years ago

Good news! Well then I think it is a matter of which console you are using, not of the glob expansion. Just to check, what is the outcome of jupytext --sync scripts\example.py? Do you need to do jupytext --sync .\scripts\example.py to get it to work?

delmarrerikaine commented 4 years ago

I am using cmd The following comands are working:

jupytext --sync .\scripts\example.py
jupytext --sync scripts/example.py
jupytext --sync ./scripts/example.py
jupytext --sync .\scripts\*.py

The following are failing with jupytext.paired_paths.InconsistentPath:

jupytext --sync scripts\example.py
jupytext --sync scripts\*.py
jupytext --sync ./scripts/*.py
jupytext --sync scripts/*.py

Perhaps it might be usefull to add a new error message if current notebook path differs from one of expected ones only by slash\backslash.

mwouts commented 4 years ago

Interesting! Do when all fail with the same error message? Rather than a new error message I'd prefer to support \ as a path separator on Windows as well, that would solve your issue, right?

delmarrerikaine commented 4 years ago

The:

jupytext --sync scripts\example.py
jupytext --sync scripts\*.py
jupytext --sync scripts/*.py

fails with:

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

Therefore I believe support of \ as a path separator on Windows should solve this.

The jupytext --sync ./scripts/*.py fails with:

jupytext.paired_paths.InconsistentPath: Path './scripts\example.py' matches none of the export formats. Please make sure that jupytext.formats covers the current file (e.g. add 'py' to the export formats)
mwouts commented 4 years ago

With the new tests above we do catch the four problems: image