should pants support `[tool.ruff]` in `pyproject.t...
# general
f
should pants support
[tool.ruff]
in
pyproject.toml
already, or is this maybe different due to the experimantel status of it?
h
You have to enable the backend. Add
pants.backend.experimental.python.lint.ruff
to your
backend_packages
f
yes, did that. somehow though it seems that the pyproject config isn't applied.
in this case I've added a file to the exclude settings for ruff but I still get lint errors for it
h
Hmm, it does look like config discovery is enabled for this backend, so it should know about pyproject.toml
So Ruff runs, but it doesn't pick up the config?
f
yes.
Copy code
[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
    ".bzr",
    ".direnv",
    ".eggs",
    ".git",
    ".git-rewrite",
    ".hg",
    ".mypy_cache",
    ".nox",
    ".pants.d",
    ".pytype",
    ".ruff_cache",
    ".svn",
    ".tox",
    ".venv",
    "__pypackages__",
    "_build",
    "buck-out",
    "build",
    "dist",
    "node_modules",
    "venv",
    "edmmp/service_a/service_a/settings.py",
]
# Same as Django and Black.
line-length = 88

# Assume Python 3.11
target-version = "py311"

[tool.isort]
profile = "black"
line_length = 88
the exclude list is just copied from ruff documentation + the last line I've added for the settings.py
Copy code
pants lint ::
15:21:03.94 [INFO] Completed: Format with Black - black made no changes.
15:21:03.94 [INFO] Completed: Format with isort - isort made no changes.
15:21:04.34 [ERROR] Completed: Lint with ruff - ruff failed (exit code 1).
edmmp/service_a/service_a/settings.py:90:89: E501 Line too long (91 > 88 characters)
Found 1 error.



15:21:04.34 [INFO] Completed: Fix with ruff - ruff --fix made no changes.
15:21:04.39 [ERROR] Completed: Lint with Flake8 - flake8 failed (exit code 1).
Partition: ['CPython==3.11.*']
edmmp/service_a/service_a/settings.py:23:80: E501 line too long (81 > 79 characters)
edmmp/service_a/service_a/settings.py:90:80: E501 line too long (91 > 79 characters)
edmmp/service_a/service_a/settings.py:93:80: E501 line too long (81 > 79 characters)
edmmp/service_a/service_a/settings.py:96:80: E501 line too long (82 > 79 characters)
edmmp/service_a/service_a/settings.py:99:80: E501 line too long (83 > 79 characters)
edmmp/util/settings_for_tests.py:26:80: E501 line too long (80 > 79 characters)




✓ black succeeded.
✕ flake8 failed.
✓ isort succeeded.
✕ ruff failed.
✓ ruff --fix succeeded.
h
huh
Next step is to run with
--keep-sandboxes=always
and inspect the sandbox
See if it has the pyproject.toml, and what it contains
f
executed, how can I check the content?
h
You can run the process inside the sandbox (look at
__run.sh
) and modify the cmd line to see if you can figure out what's going on
It has logged all the process sandboxes
It should tell you which dir it ran ruff in
so you can cd into that dir
f
run-tracker?
no results for
find . -name '__run.sh'
after running
pants lint :: --keep-sandboxes=always
h
Look at the log output
it should be listing all the sandbox dirs for each process it ran
f
ah ok
ok there is __run.sh
Copy code
cat __run.sh --style=plain
#!/usr/bin/env bash
# This command line should execute the same process as pants did internally.
cd /private/var/folders/ll/98hnvg_n5l3by0224q_qybc40000gn/T/pants-sandbox-oaUH8r
env -i PEX_EXTRA_SYS_PATH=__plugins ./flake8.pex_pex_shim.sh $'--jobs=8' edmmp/service_a/app_a/__init__.py edmmp/service_a/app_a/admin.py edmmp/service_a/app_a/apps.py edmmp/service_a/app_a/conftest.py edmmp/service_a/app_a/models.py edmmp/service_a/app_a/tests/test_views.py edmmp/service_a/app_a/urls.py edmmp/service_a/app_a/views.py edmmp/service_a/service_a/__init__.py edmmp/service_a/service_a/asgi.py edmmp/service_a/service_a/settings.py edmmp/service_a/service_a/urls.py edmmp/service_a/service_a/wsgi.py edmmp/util/settings_for_tests.py
not sure what to figure out here 🤔
in case the pyproject.toml is expected to be part of the sandbox, it seems it isn't
h
is there a pyproject.toml in that sandbox?
f
haha ^ 😉
h
OK, so there's the issue
Can you file a bug? Thanks
f
sure
here
<https://github.com/pantsbuild/pants>
?
h
Yep
👍 1
If you can link to a small repo that reproduces the issue, that would be golden
A consistent reproduction is the key to bugfixing
f
sure, let me edit
ok, have a look now please
h
Thanks!
@freezing-fall-2672 you add ruff and flake8 here, was that intentional?: https://github.com/elmcrest/example-django-multiple-monoliths-pantsbuild/commit/1e96d4e2576568d12d5827ec39fa58b64fcc92ab And you don't add a flake8 config for max-line-length: https://flake8.pycqa.org/en/2.5.5/config.html#settings
h
Ah yes, good eye. @freezing-fall-2672, you have to find the specific sandbox that is running ruff (the logs tell you which is which). When I run in your repo and look at the correct sandbox pyproject.toml is in there.
Ruff is failing with
edmmp/service_a/service_a/settings.py:90:89: E501 Line too long (91 > 88 characters)
, so it is picking up your config (that is where the 88 comes from). For some reason the exclude is not taking effect, but you should debug that outside of Pants, by running ruff directly, to see if your config file is valid in the first place.
Ah, there is an actual Pants bug underneath all this though
👀 1
Ruff doesn't apply excludes to files passed directly to it on the command line, unless you add
--force-exclude
to the command line, which we don't (https://beta.ruff.rs/docs/settings/#force-exclude)
r
I've replaced
flake8
+
isort
with
ruff
, while keeping
black
. As
black
takes care of the line length enforcements with a few exceptions, it is recommended to disable `ruff`'s own line length check by ignoring
E501
.
It seems that the experimental ruff backend works fine, but I had a gotcha that its auto-fixers are invoked only with
pants fix
, but not with
pants fmt
.
...and it seems that it runs auto-fixers even with
pants lint
but it has no effects because it seems to modify the pex env's copied source files, while
pants fix
properly updates the original source files.
f
hey again. thx for the updates, and sorry for mixing the wrong sandbox in, wasn't intentional of course. Ok, so in conclusion there is no bug, right? Excludes aren't applied until enabled via flag by ruff, so no fault from pants. the other points mentioned by @rhythmic-morning-87313 are probably still worth to have a look at but aren't in the scope of the issue I've created, right?
e
Pants is totally at fault, although the bug is not what it appeared to be by your report. Pants passes an explicit list of files so it must pass force excludes or it must stop passing a list of files. Pants integrated poorly / incompletely with Ruff IOW.
f
Ah ok, I see.