Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set-formats on fresh text file based on configuration #544

Closed
DancingQuanta opened this issue Jun 16, 2020 · 2 comments · Fixed by #609
Closed

Set-formats on fresh text file based on configuration #544

DancingQuanta opened this issue Jun 16, 2020 · 2 comments · Fixed by #609
Milestone

Comments

@DancingQuanta
Copy link

This is an extension of a related issue #485.

I would like to be able to set the format on a fresh text file or modify the text file based on the current configuration (local if available else global) without specifying the argument to --set-formats.

For example, for the configuration in local .jupyter

# Pair notebooks
default_jupytext_formats = "markdown//md,notebooks//ipynb,scripts//py:percent"

and we have a a directory structure with a .md file in markdown directory:

.
├── .jupytext
├── markdown
│   └── intro.md
├── notebooks
└── scripts

And the pairing setup of the markdown file could be:

  • Within parent directory
jupytext --set-formats markdown/00-intro.md
  • or within markdown directory
jupytext --set-formats 00-intro.md

Above two command examples should be informed by the configuration that the markdown file is in the markdown directory.

To check what the current version (1.5.0) does, I ran both commands and got the same error

Traceback (most recent call last):
  File "C:\Users\at17\.conda\envs\sthm\Scripts\jupytext-script.py", line 9, in <module>
    sys.exit(jupytext())
  File "C:\Users\at17\.conda\envs\sthm\lib\site-packages\jupytext\cli.py", line 376, in jupytext
    exit_code += jupytext_single_file(nb_file, args, log)
  File "C:\Users\at17\.conda\envs\sthm\lib\site-packages\jupytext\cli.py", line 389, in jupytext_single_file
    raise ValueError("Cannot sync a notebook on stdin")
ValueError: Cannot sync a notebook on stdin

Is this usecase not yet supported or is there a different command I should use?
Lastly, I wonder if commandline operations can be used with the configuration which will save me from typing same arguments repetitively.

@mwouts
Copy link
Owner

mwouts commented Jun 19, 2020

Hello @DancingQuanta , that's an interesting example!

The problem here is that you pass a file name to the --set-formats option rather than a format name.

I am sure you're not the only one to try this... a few days ago I found myself doing jupytext --to dest_file.md which is wrong for the same reason (a format name is expected there, not a file name). So I'll think of adding a warning when the value passed to --from, --to and --set-formats is a file name 😃 (please don't close this issue so that I don't forget)

So, on your side, you should do jupytext --sync markdown/00-intro.md, or jupytext --sync 00-intro.md in the markdown folder, or even jupytext --sync markdown/*, i.e. use --sync, not --set-formats.

Lastly, I wonder if commandline operations can be used with the configuration which will save me from typing same arguments repetitively.

You should be able to use jupytext --sync markdown/* - or are you looking for something else?

@DancingQuanta
Copy link
Author

Got it --sync is the right one here!

My suggestion on the warning message is to check is the argument match the format specification and warn about it.

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 a pull request may close this issue.

2 participants