<#20525 Upgrading to 2.20 with ruff linting active...
# github-notifications
c
#20525 Upgrading to 2.20 with ruff linting active immediately starts using it for formatting too Issue created by huonw Describe the bug It seems the linter -> linter+formatter transition in #20098 causes issues on my work repo: • we use ruff for its linting • we use black and isort for formatting • doing that upgrade starts running ruff formatting automatically, but the format differs to black, so they end up fighting and
pants fmt ::
makes many changes, and/or
pants lint ::
fails Preferably Pants usually doesn't force people to make manual code changes for each upgrade (i.e. make it as easy as possible to stay up to date). To land an upgrade to 2.20, I'd have to go and either disable black/isort and use ruff, or somehow disable ruff's formatting while retaining its linting (which doesn't seem to be possible in pants). Reproducer:
Copy code
cd $(mktemp -d)

cat > pants.toml <<EOF
[GLOBAL]
pants_version = "2.19.0"

backend_packages = [
  "pants.backend.python",
  "pants.backend.python.lint.black",
  "pants.backend.experimental.python.lint.ruff",
]

[python]
interpreter_constraints = ["CPython==3.10.*"]
EOF

echo 'python_sources(name="foo")' > BUILD
# <https://docs.astral.sh/ruff/formatter/black/#single-element-tuples-are-always-parenthesized>
echo '(1, 2),' > foo.py

# OK: everything passes with 2.19.0
pants lint ::

# BUG: ruff now tries reformatting, and has changes the syntax
PANTS_VERSION=2.20.0.dev0 pants lint ::
The first
pants lint ::
run (
OK
) demonstrates that the code passes, while the second does the "upgrade" to the first release with #20098, demonstrating that ruff formatter now runs, but fails. That (ab)uses one of the differences between the ruff and black formatters that doesn't matter in the real world, but the same applies if black has configuration that isn't (yet) configured for ruff, e.g. if we had configured a longer line length, ruff might try squishing any lines that exceed its default (88?).
Copy code
# pyproject.toml
[tool.black]
line-length = 120
In #20510 (comment) and onwards, we discuss some options. Pants version 2.20.0.dev7 OS macOS Additional info N/A pantsbuild/pants