Hi all I recently upgraded to pants 2.20.0 to try ...
# general
d
Hi all I recently upgraded to pants 2.20.0 to try out the new
ruff
integration. I’m seeing differences between running when running ruff inside an exported virutalenv vs via pants I’m using a pinned version of ruff
0.3.0
Copy code
[ruff]
install_from_resolve = "python-default"
Copy code
pants export --resolve=python-default
When I run the local venv version:
Copy code
dist/export/python/virtualenvs/python-default/3.11.8/bin/ruff check <file>
No changes ...
VS when I run via pants
Copy code
pants lint <file>
12:46:51.29 [ERROR] Completed: Lint with `ruff check` - environment:macos - ruff check failed (exit code 1).
<file>:1:1: I001 [*] Import block is un-sorted or un-formatted
Found 1 error.
[*] 1 fixable with the `--fix` option.
Unsure what’s going on here. It’s obviously discovering the config correctly because the rule in question
I001
is configured in my
pyproject.toml
Is there a way to confirm pants is running the correct version here?
1
g
This took me about 2 hours to figure out in our monorepo. I used ruff's
--verbose
flag to figure it out. It turns out that ruff was categorizing things different based on the context of where ruff is called. I saw it start when we upgraded from ruff 0.1.8 to the 0.3.x. I first obvserved the difference between ruff in pre-commit and running ruff via
poetry run ruff
. I ended up fixing it by using ruff's known-first-party configuration. Pretty annoying actually, but it solved the problem for us. I hope this helps.
👀 1
👍 1
Sample ruff logs with
--verbose
flag:
Copy code
[2024-04-22][06:55:18][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'altdev.commands.ado' as Known(FirstParty) (KnownFirstParty)
[2024-04-22][06:55:18][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'logging' as Known(StandardLibrary) (KnownStandardLibrary)
[2024-04-22][06:55:18][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'time' as Known(StandardLibrary) (KnownStandardLibrary)
[2024-04-22][06:55:18][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'json' as Known(StandardLibrary) (KnownStandardLibrary)
[2024-04-22][06:55:18][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'os' as Known(StandardLibrary) (KnownStandardLibrary)
We ended up finding out that ruff's heuristics for identifying 1st/3rd party was actually wrong the whole time for some packages so this became the catalyst for us to fix that once and for all as well.
b
In case you’re wondering, this is a fairly old bug: https://github.com/pantsbuild/pants/issues/18410
c
Related to even older related issue, but for `isort`: https://github.com/pantsbuild/pants/issues/15069
d
Thanks all for pointing to issues. Glad I’m not the only/first person to be bitten by this. the
known-first-party
fixed my issues
👍 2