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

feat: use jupytext for demonstrator notebooks #92

Merged
merged 11 commits into from
Feb 3, 2023

Conversation

ekauffma
Copy link
Collaborator

Paired markdown and py:percent files are added for the ATLAS analysis notebook (via Jupytext). A pre-commit config file is also included. In order to run using the pre-commit hook (which ensures all files are synced via Jupytext when committing), the developer must make sure the pre-commit hook is installed by running "pre-commit install" while in the repository. Instructions for this are also included in Markdown in the file itself.

@matthewfeickert
Copy link
Member

Nice. :) You have the pre-commit hook, but if you also wanted to have files be autopaired you could also add the following to a pyproject.toml in the top level directory

[tool.jupytext]
# Always pair ipynb notebooks to py:percent files
formats = ["ipynb", "py:percent"]
notebook_metadata_filter = "all,-jupytext.text_representation.jupytext_version"

That may or may not be of interest though.

@ekauffma
Copy link
Collaborator Author

Nice. :) You have the pre-commit hook, but if you also wanted to have files be autopaired you could also add the following to a pyproject.toml in the top level directory

[tool.jupytext]
# Always pair ipynb notebooks to py:percent files
formats = ["ipynb", "py:percent"]
notebook_metadata_filter = "all,-jupytext.text_representation.jupytext_version"

That may or may not be of interest though.

Thanks! Yes I did want to do this as well, although I think that @oshadura wanted to avoid creating paired files for the notebooks in the workshops/ directory.. I think I remember some way to do this though.. will look into it!

@matthewfeickert
Copy link
Member

Yeah, you can't do exclude patterns (AFAIK) so you either would need to specify the directories that you do want paired notebooks to be generated for in the config (c.f. mwouts/jupytext#1033) or have a jupytext.toml per directory.

@alexander-held
Copy link
Member

@matthewfeickert when does this auto-pairing happen? I am trying to understand the following scenarios:

  1. A pair of .py and .ipynb already exist in the repository and a user updates the notebook. The syncing is automatic via the pre-commit hook I believe?
  2. A user creates and commits a new .ipynb notebook. Does the pre-commit hook create a synced .py? Do we need the pyproject.toml for that?

@alexander-held alexander-held changed the title Notebook to jupytext feat: use jupytext for demonstrator notebooks Feb 3, 2023
Copy link
Member

@alexander-held alexander-held left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you! I re-synced the ttbar notebook with the current HEAD version to avoid changing anything else in this PR.

@alexander-held alexander-held merged commit 344af98 into iris-hep:main Feb 3, 2023
@matthewfeickert
Copy link
Member

when does this auto-pairing happen? I am trying to understand the following scenarios:

Sorry @alexander-held missed these. The auto-pairing happens at creation time if you're using a pyproject.toml config or a jupytext.toml config. So if you created an example.ipynb and then saved it, jupytext would automatically create a paired example.py at save.

  1. A pair of .py and .ipynb already exist in the repository and a user updates the notebook. The syncing is automatic via the pre-commit hook I believe?

Hm that's a good question about the pre-commit hook. I assume yes, but I'd have to try it myself (I hadn't used the pre-commit hook yet). I'm assuming that @ekauffma knows given they added the pre-commit hook. I can try this out on another project though tonight at report back.

  1. A user creates and commits a new .ipynb notebook. Does the pre-commit hook create a synced .py? Do we need the pyproject.toml for that?

I would assume that here the pre-commit hook would do this, but as mentioned above if you either manually select a notebook to be paired with a py:percent format or specify this in a jupytext config then it will sync on save.

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.

3 participants