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

Fix notebook code formatting #329

Closed
davidorme opened this issue Oct 16, 2024 · 0 comments · Fixed by #330
Closed

Fix notebook code formatting #329

davidorme opened this issue Oct 16, 2024 · 0 comments · Fixed by #330
Labels
bug Something isn't working

Comments

@davidorme
Copy link
Collaborator

Describe the bug

We want the Python code in notebooks to get auto-formatted.

At the moment, we're using jupytext --pipe black as a pre-commit hook, which does the job but is not configured quite correctly. The way it works is a bit complex:

mwouts/jupytext#1267

The main issue is that the piping process causes code-cell language info to be removed and that breaks pygments lexing in VSCode. In order to retain that, we need to the notebooks to include language-info notebook metadata, which jupyter adds but is not retained in the minimal filtered Myst notebook metadata when it passes through jupytext.

It is possible that in the future we might be able to use ruff to do this job but at present only the .ipynb format for notebooks is supported by ruff-format and it's a pain to have to convert all our '.mdfiles to.ipynband then back again (usingjupytext`) just to format the Python.

astral-sh/ruff#8800 (comment)

So:

  1. Add retaining the language_info notebook metadata to the project settings.
  2. Add that language_info metadata to the files (at the moment this is manual or open and save in jupyter after step 1)
  3. Add {code-cell} ipython3 to code cells.
@davidorme davidorme added the bug Something isn't working label Oct 16, 2024
@davidorme davidorme moved this to In Progress in ICCS development board Oct 16, 2024
@davidorme davidorme linked a pull request Oct 16, 2024 that will close this issue
10 tasks
@github-project-automation github-project-automation bot moved this from In Progress to Done in ICCS development board Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant