-
Notifications
You must be signed in to change notification settings - Fork 394
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
Add --check-metadata to CLI script #146
Comments
Hello @goerz , thanks for your suggestion. I completely agree that the pairing information would be very helpful for the vim plugin, and that the notebook pairing, when it exists, could have precedence over the default vim plugin format. Jupytext CLI could certainly have a mode that gives that information. I am not completely sure however that For now, let me add that you can extract the metadata from a notebook with
Also, I do not think that editing a paired notebook in another format will mess up the notebook. I just tried it with a ipynb/py paired notebook, edited as a md file in vim. I agree that the |
That's good to hear. I'll let you figure out what you want to do with the metadata in the next release before looking into this further. |
Hello @goerz , I've made some progresses towards the next release of Jupytext (in branch 1.0.0). Regarding this issue, I was thinking of adding two more arguments to jupytext command line:
Do you think that should be enough for |
So this is for a situation where there are multiple linked files for the same notebook? Like a markdown and a Python file at the same time? Sounds good to me! Besides the pathnames in Do I understand correctly that |
Exactly (print nothing and exit without error when there is no linked file)
Well, with the
If the notebook is not paired to any text representation, VIM would convert the notebook to a text file, in the format given by the user in the config file (that is the only case where I expect that VIM provides the format information to On a separate subject: I plan to allow linked files in different folders. Do you have an input on how this could be encoded in the format information? I have a proposal there, your feedback is welcome! |
I think that would work fine. There is one place where the vim plugin as currently implemented still relies knowing the exact format: This maps jupytext formats to vim "filetypes", which regulates syntax highlighting (and potentially other custom settings like ftplugins). So if you don't expose the format through Just out of curiosity, where will |
Hello @goerz, I have implemented the new arguments in jupytext CLI, as well as the automatic detection of the format when notebook is read from stdin (#148). Would you like to test the latest version in branch 1.0.0 ? Thanks for your comments! I think your two use cases also correspond to mine. Don't you think we could compute automatically the best format for a notebook (e.g. markdown when markdown content is more than 10% of the total, script otherwise) ? Also, the paired paths are computed using the notebook metadata |
I'm currently getting ready to travel to a conference, but I will test the new version in branch 1.0.0. when I get back at the end of next week. Automatic detection of whether a notebook is predominantly code or has significant markdown content is certainly an interesting idea! |
Hello @goerz , sure! There's no hurry here. In that case, I even suggest that we test directly the RC when available - I will let you know when it's published on pypi. |
Thanks for testing @goerz . And for covering your findings with such details! I agree with your reports - none of this is not expected to happen. I will add more tests and fix that... |
Tests and fix are available in the latest RC |
It would be helpful if the
jupytext
CLI had an option--check-metadata
. When passed, the program prints the content of the "jupytext" metadata to STDOUT (in json format) and exits. The option should further take values to filter down to a particular field, which then should be printed as an unquoted value.For example, assume
notebook.ipynb
contains the following:Then I would like
If
notebook.ipynb
does not contain the "jupytext" metadata, nothing should be printed.This would be a tremendous help for
jupytext.vim
plugin. Basically, what I want to achieve is forvim notebook.ipynb
, wherenotebook.ipynb
hasjupytext
metadata, to use the "format_name" from that metadata instead of the defaultg:jupytext_fmt
from the.vimrc
. Only if the notebook does not have metadata would I fall back to theg:jupytext_fmt
.Otherwise, I think that using the plugin on ipynb files that already have a linked text representation would potentially be a problem: If the setting
g:jupytext_fmt
does not match the format of the linked file, an additional text-representation file would be written (and deleted when vim closes), and the metadata innotebook.ipynb
would be overwritten to point to the new (now missing) file. Thus, the link between the notebook and the original text-representation files would be severed. I don't think people who use the automatic linking feature throughc.ContentsManager
would like that at all.Parsing out the metadata from inside vimscript will be quite difficult, I think. I could do it in Python, but then I would have to assume that vim has been compiled with python support, which I would like to avoid. Similarly using an external utility like
jq
. The one dependency I can guarantee in the plugin is that thejupytext
CLI script is available (otherwise, the plugin is pointless in the first place). Thus, it would be easiest ifjupytext
could handle the extraction of the necessary data.@mwouts: Let me know if you think this is ok. Of course, I don't really care if the flag is called
--check-metadata
or something else). If this is not extremely trivial for you to implement, maybe I can have a crack at it and make a pull request.The text was updated successfully, but these errors were encountered: