Does anyone have an idea why `pants check --lint-o...
# general
w
Does anyone have an idea why
pants check --lint-only=ruff-check
doesn't flag rules but invoking ruff itself does? i tried to manually set the config file and even to explicitly set this rule, but it didn't help. Also debugging it with
-ldebug
didn't give me any information. Maybe an idea on how to debug this? The one thing which is different in the output is that pants says:
Found 9 errors (9 fixed, 0 remaining).
(they arent fixed) and Ruff states:
Found 9 errors. [*] 9 fixable with the --fix option.
Edit: The rule in this case is D415.
I think i just found the cause myself, but i'm not sure if it's the intended behaviour: Running
pants check --lint-only=ruff-check
with the arg
--ruff-args="--no-fix"
resolves this problem. Executing
pants check --lint-only=ruff-check
fixes the errors, but probably only in a temporary file, because it shows:
Copy code
11:53:15.31 [INFO] Completed: Lint with `ruff check` - ruff check succeeded.
Found 9 errors (9 fixed, 0 remaining).
But my own file still has the errors in it. Since its a
check
command i woud expect pants to execute
ruff check
with the flag
--no-fix
and return the exit code and the error message.
w
I’d have to look into this to remember, but lint, format, fix all share a lot of common code, separated by an enum about which one you want to use specifically (they all run ruff under the hood with different flags) I would assume you’d want
pants lint
though, no?
https://github.com/pantsbuild/pants/blob/50804a37c13768e64735ec30e08717326504ecff/src/python/pants/backend/python/lint/ruff/common.py#L54
Copy code
if request.mode is RuffMode.FORMAT:
        extra_initial_args = ("format",)
    elif request.mode is RuffMode.FIX:
        extra_initial_args = ("check", "--fix")
    elif request.mode is RuffMode.LINT:
        extra_initial_args = ("check",)
    else:
        assert_never(request.mode)
w
Yes i totally meant
lint
!
I would expect lint to have
--no-fix
for
ruff check
because if not set, it wont report any error
w
Yeah,
pants lint
for ruff runs without
--fix
- I haven't checked ruff lately to see if defaults changed, but there might also be a weird reporting issue (e.g. are we running
fix
internally and then just not materializing the sandbox changes into the workspace) kinda thing
So, either way, that would just be on the reporting side. If you have a small reproduction repo, I could try it out to see if I can see what's happening
w
i found the issue of the issue. im not sure if pants should account for this case:
fix = true
was set in our
pyproject.toml
. Thats why pants fixed the problems even when only running
pants lint --lint-only=ruff-check
. But it seems that pants linted and fixed the files in a temporary file, because the file in my repo was unchanged. Does pants lint in a temp dir? Also, since the fix is only temporary, should pants lint always enforce
--no-fix
to always properly report errors?
w
Yeah, I was going to ask about that
fix=true
in a configuration as that seemed most likely, but it was worth testing otherwise. It definitely seems inconsistent, but pants usually operates with defaults that are easily overwritten (from pants.toml or pyproject, or wherever else). I think the only promise it makes is to not change the working directory. I could see a world where linting with fix=true (as odd as I personally find it) would be useful to know for seeing how many non-auto-fixable bugs a project has (for tracking). If we add no-fix, that might prevent someone from appending a fix later (no clue, never tested (--no-fix --fix) - whereas right now, the default is correct, overrides are correctly applied. In general, Pants tries to allow defaults with escape hatches wherever possible
You can create a "question" ticket in the repo, and see if anyone else chimes in?
w
I don't think its worth it. Seems like a niche problem.
And, thank you for your effort !