Add jupyter and toml file types#44
Add jupyter and toml file types#44charliermarsh merged 2 commits intoastral-sh:mainfrom hamdanal:jupyter
jupyter and toml file types#44Conversation
|
Thanks! Do you mind adding |
|
Thanks! |
|
Hi @charliermarsh, does ruff lint toml files? Or did you ask for toml to be added so that ruff has access to the configuration in I tried this with one of my projects - repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.277
hooks:
- id: ruff
types_or: [python, pyi, jupyter, toml]
args: [--fix, --exit-non-zero-on-fix]And ruff started failing on the Thank you for ruff by the way, it is an amazing tool. |
|
Yeah, Ruff lints |
|
I'll send a PR to revert it and see how can we add |
|
Can you refresh my memory -- if we revert both of these, what happens if someone adds this to their configuration? Will Ruff still end up linting Jupyter notebooks? - repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.277
hooks:
- id: ruff
types_or: [python, pyi, jupyter]
args: [--fix, --exit-non-zero-on-fix] |
|
We may actually want to revert Jupyter too for now -- it should be considered opt-in, not on-by-default. |
Yes, you can override |
What about another hook like what black does. This way jupyter stays opt-in but also users don't have to learn about low level pre-commit configuration to make it work with notebooks. |
|
I think my preference for now would be to revert, and add an example to the docs that users can copy-paste to add Jupyter support. |
Done in #45 |
|
Thank you, sorry for the churn! |
## Summary This PR adds a higher-level enum (`SourceType`) around `PySourceType` to allow us to use the same detection path to handle TOML files. Right now, we have ad hoc `is_pyproject_toml` checks littered around, and some codepaths are omitting that logic altogether (like `add_noqa`). Instead, we should always be required to check the source type and handle TOML files as appropriate. This PR will also help with our pre-commit capabilities. If we add `toml` to pre-commit (to support `pyproject.toml`), pre-commit will start to pass _other_ files to Ruff (along with `poetry.lock` and `Pipfile` -- see [identify](https://github.com/pre-commit/identify/blob/b59996304fea80025d32abc3ac8f7212a9e7380d/identify/extensions.py#L355)). By detecting those files and handling those cases, we avoid attempting to parse them as Python files, which would lead to pre-commit errors. (We tried to add `toml` to pre-commit here (astral-sh/ruff-pre-commit#44), but had to revert here (astral-sh/ruff-pre-commit#45) as it led to the pre-commit hook attempting to parse `poetry.lock` files as Python files.)
Fixes #43
Summary
Add
jupyterto the file types that ruff pre-commit hook runs onTest Plan
This is what pre-commit uses to identify ".ipynb" files. See https://github.com/pre-commit/identify/blob/dc75a76b7fd7093a7a1d4159d6741884343af694/identify/extensions.py#L100
Also black does this https://github.com/psf/black/blob/main/.pre-commit-hooks.yaml