-
Notifications
You must be signed in to change notification settings - Fork 41
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
Ruff configuration from pyproject.toml is ignored #54
Comments
Hmm, a bit of a tough one to debug. When you switch between |
Yes they are in the same directory. I tried it on another laptop with a small example project and this problem did not occur. I try to find a way to reproduce the problem and give you an update. |
I could reproduce the problem and find a solution. If I use a project with already added code and a pyproject.toml to the git repo and then
When I first commit the |
same issue with v0.1.0 but committing the config doesn't change anything
by default line-length is not checked, seems strange no ? |
@klow68 - We removed |
@beajifu I'm unable to reproduce with the steps mentioned although I'm using Gist: https://gist.github.com/dhruvmanila/8c796087330cb22699f3b20e929fde45
Steps
$ pre-commit run
ruff.....................................................................Failed
- hook id: ruff
- exit code: 1
test.py:1:8: F401 [*] `os` imported but unused
Found 1 error.
[*] 1 potentially fixable with the --fix option.
$ pre-commit run
ruff.....................................................................Passed |
My configuration in pyproject.toml also seems to be having an issue. Running ruff without any config: 3 errors Running ruff with 3 select = ["ALL"] in pyproject.toml: 389 errors Running ruff through pre-commit: 89 errors. It seems like running ruff through pre-commit is using more rules than default but ignoring the rules in pyproject.toml |
Chiming in just in case it may help someone. In my case, clearing the precommit cache ( |
This still seems to be an issue; using |
Would really appreciate if you could share some more information -- we weren't able to reproduce it above and it doesn't seem to be a common issue, so we need some help. What behavior are you seeing? What commands are you running? How is your project structured? Have you tried clearing the cache, as above? Thank you in advance! |
It seems I have more than one project reliably producing this bug (even after clearing caches), and I constructed a new project as a minimal example for @charliermarsh to reproduce the bug reliably. The new project I made ended up reading the |
[tool.ruff]
select = ["E"]
# Never enforce `E501` (line length violations).
ignore = ["E501"] don't these go in tool.ruff.lint? |
@rafalkrupinski I double checked docs, and you're right. I have been busy with other tasks, but I saved this thread for later. I'll retest, and repost. |
@caerulescens - Both are accepted right now -- putting |
I realized the same thing just now; I'll retest |
I re-verified that I can [still] produce this bug with projects I'm working on; the |
@charliermarsh just created repo in which pre-commit hook ignores |
@Quatters Hi, thanks for providing the repository for the problem you're facing. But, I don't think it's a bug with Ruff or pre-commit, I've described in detail about what's happening here: astral-sh/ruff#9696 (comment). One solution would be to use repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.15
hooks:
- id: ruff
pass_filenames: false This solves your problem. That said, maybe Ruff's pre-commit hook should do that by default? |
@dhruvmanila thank you for the quick response. Yes, providing
I'm not sure about doing that by default (will there be any side effects/breaking changes?). Anyway, I think information about |
Wouldn't that make ruff to check all files every time? I think pre-commit users expect it to only check changed files, even if it is fast. Even if pre-commit passes filenames to |
Agreed, running with It does help narrow down the issue though, good find! |
@dhruvmanila That is not a usable work around for the reasons that @dougthor42 mentions. @charliermarsh I played around with this issue tonight, and I have discovered more behavior surrounding this issue. I did something similar to the squeeze theorem but with code; I constructed a minimal project that doesn't have the issue, and I have a fully featured project with the issue (for the same rule). I've been removing parts of the larger project until I identify the issue.
[tool.ruff]
line-length = 88 # Not relevant
target-version = "py310" # Not relevant
src = ["src", "tests", "docs"] # Not relevant
select = ["F", "E", "W", "C90", "S", "I", "N", "D", "UP"]
ignore = ["D100", "D104", "N999"]
[tool.ruff.pydocstyle]
convention = "pep257" # Not relevant Will produce:
Then, removing rule
This means that |
@charliermarsh I think I solved it! The problem occurs when there's another This issue can be closed as |
This happens to me and I have a single pyproject.toml file |
@rpop0 Could you elaborate further? This issue doesn't seem to be a problem; do you have other types of configurations present like |
No other types of configurations besides the single pyproject.toml file. |
@rpop0 How are you reproducing this bug? Could you post a minimal example repository for us or maybe zip a folder and attach here? |
At the very least, the title for this issue is incorrect because |
I have been having the same issue where the ruff pre-commit hook was ignoring the I am using VSCode and the Ruff VSCode extension. Console commands in VSCode were working fine, but pre-commit would undo the formatting done by the VSCode extension. When I disabled the VSCode extension, the problematic behavior went away and the precommit behavior starting working as expected. I was also able to reenable the Ruff VSCode extension and the issue has not yet returned. I hope this is helpful. |
I have the same problem that ruff-pre-commit does not load ruff config from pyproject.toml. I resolved it by adding the config in the args. - repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.3
hooks:
# Run the linter.
- id: ruff
args: ["--select", "E,W,F,I,C,B,UP", "--ignore", "E203,B008,C901"]
# Run the formatter.
- id: ruff-format |
Same here, but more explicitly for the --exclude config which is not accounted for |
I had the same problem and I fixed it with this config, passing the config file to the args explicitly. repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.5
hooks:
# Run the linter.
- id: ruff
args: [ --fix, --config=pyproject.toml ]
# Run the formatter.
- id: ruff-format |
If you think your config is ignored. Add - repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff: Formatter and Linter.
rev: v0.5.1
hooks:
- id: ruff-format
args: [--verbose, ]
- id: ruff
args: [--verbose, --fix,] Then you can run The output for me is: ruff-format..............................................................Passed
- hook id: ruff-format
- duration: 0.08s
[ruff::resolve][DEBUG] Using configuration file (via parent) at: SOMEPATH/pyproject_template\pyproject.toml |
I upgraded from 0.4.5 to 0.5.1, and Ruff detects pyproject.toml automatically. # See https://pre-commit.com for more information
default_language_version:
python: python3.12
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.1
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format |
It works now for me too, but one thing I stumbled upon was when updating some ruff rules or exceptions and not commiting them with the python files (for whatever reason), the hook uses the last commited version of pyproject.toml, which does not have the new rule (or exclusion) and thus produces other results when calling ruff check from console. |
@Blumenkind111 This is expected behavior of pre-commit. Pre-Commit Issue #818 |
I'm currently also running into this. My issue was that the
Moving it back to |
In case that might help someone. In my case I noticed that the In order to be able to have ignore rules defined in one or multiple |
Hi,
I'm trying to use the pre-commit hook for Ruff, but it ignores my settings from the
pyproject.toml
. I want Ruff to ignore the line-length but if I commit a file with lines that exceed this limit it is complaining about it. If I use aruff.toml
to configure Ruff it works as expected.I use version 0.0.292.
My settings in
.pre-commit-config.yaml
:Ruff configuration part in my
pyproject.toml
(same is used in theruff.toml
)The text was updated successfully, but these errors were encountered: