Skip to content

Commit b21a864

Browse files
committed
Remove ruff from tox, update developer tools docs
1 parent fc69e93 commit b21a864

File tree

3 files changed

+28
-75
lines changed

3 files changed

+28
-75
lines changed

src/doc/en/developer/tools.rst

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ available
6464
--tox [options] <files|dirs> -- general entry point for testing
6565
and linting of the Sage library
6666
-e <envlist> -- run specific test environments; default:
67-
doctest,coverage,startuptime,pycodestyle-minimal,relint,codespell,rst,ruff-minimal
67+
doctest,coverage,startuptime,pycodestyle-minimal,relint,codespell,rst
6868
doctest -- run the Sage doctester
6969
(same as "sage -t")
7070
coverage -- give information about doctest coverage of files
@@ -75,13 +75,11 @@ available
7575
relint -- check whether some forbidden patterns appear
7676
codespell -- check for misspelled words in source code
7777
rst -- validate Python docstrings markup as reStructuredText
78-
ruff-minimal -- check against Sage's minimal style conventions
7978
coverage.py -- run the Sage doctester with Coverage.py
8079
coverage.py-html -- run the Sage doctester with Coverage.py, generate HTML report
8180
pyright -- run the static typing checker pyright
8281
pycodestyle -- check against the Python style conventions of PEP8
8382
cython-lint -- check Cython files for code style
84-
ruff -- check against Python style conventions
8583
-p auto -- run test environments in parallel
8684
--help -- show tox help
8785
@@ -310,20 +308,33 @@ for Python code, written in Rust.
310308
It comes with a large choice of possible checks, and has the capacity
311309
to fix some of the warnings it emits.
312310

313-
Sage defines two configurations for ruff. The command ``./sage -tox -e ruff-minimal`` uses
314-
ruff in a minimal configuration. As of Sage 10.3, the entire Sage library conforms to this
315-
configuration. When preparing a Sage PR, developers should verify that
316-
``./sage -tox -e ruff-minimal`` passes.
311+
Sage we have two configuration files for ruff. `pyproject.toml` in the root of the
312+
repository defines all rules we wish to follow. `.github/workflows/ruff.toml` takes
313+
the configuration in `pyproject.toml` and disables all rules that we do not already
314+
follow throughout the repository. Our lint GitHub Action workflow requires
315+
``ruff check --config .github/workflows/ruff.toml --preview`` to pass. To speed up the
316+
code review process, developers should verify that this passes locally before submitting a PR.
317+
To make sure you are running the same version of `ruff` locally as GitHub Actions, use the command
318+
``uv run --frozen --only-group lint -- ruff check --config .github/workflows/ruff.toml --preview``.
319+
320+
Developers are encouraged to locally run ``ruff check [path to changed files]``
321+
to run the stricter configuration defined in `pyproject.toml` and fix any linter
322+
failures on their new code. This will help to avoid follow-up formatting PRs as
323+
Sage moves toward full PEP 8 compliance. Developers may also choose to fix existing
324+
linter failures on files that they modify, but use common sense when deciding whether
325+
or not to do so. A small bug fix PR should not include a large number of
326+
code-style changes as this makes it harder for reviewers to evaluate the important changes.
327+
328+
When working on PRs to improve our alignment with our linter rules, the ``--statistics``
329+
option can be passed to ``ruff`` to print out a list of all rules that are enabled in
330+
`pyproject.toml` but are not currently followed throughout the repository and how many
331+
times each rule is violated. This is useful for finding low-hanging fruit for formatting PRs.
332+
Developers can also use ``--select [RULE CODES]`` to override the list of rules enabled in
333+
`pyproject.toml` when testing additional rules to add to `pyproject.toml`, or
334+
``--select-extend [RULE CODES]`` to add new rules to the existing confirmation.
335+
See the `Ruff documentation <https://docs.astral.sh/ruff/>`_ to see all features and rules
336+
available.
317337

318-
The second configuration is used with the command ``./sage -tox -e ruff`` and runs a
319-
more thorough check. When preparing a PR that adds new code,
320-
developers should verify that ``./sage -tox -e ruff`` does not
321-
issue warnings for the added code. This will avoid later cleanup
322-
PRs as the Sage codebase is moving toward full PEP 8 compliance.
323-
324-
On the other hand, it is usually not advisable to mix coding-style
325-
fixes with productive changes on the same PR because this would
326-
makes it harder for reviewers to evaluate the changes.
327338

328339
.. _section-tools-relint:
329340

src/tox.ini

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
## in a virtual environment.
2222
##
2323
[tox]
24-
envlist = doctest, coverage, startuptime, pycodestyle-minimal, relint, codespell, rst, ruff-minimal
24+
envlist = doctest, coverage, startuptime, pycodestyle-minimal, relint, codespell, rst
2525
# When adding environments above, also update the delegations in SAGE_ROOT/tox.ini
2626
skipsdist = true
2727

@@ -258,44 +258,6 @@ description =
258258
deps = cython-lint
259259
commands = cython-lint --no-pycodestyle {posargs:{toxinidir}/sage/}
260260

261-
[testenv:ruff]
262-
description =
263-
check against Python style conventions
264-
deps = ruff
265-
passenv = RUFF_OUTPUT_FORMAT
266-
commands = ruff check {posargs:{toxinidir}/sage/}
267-
268-
[testenv:ruff-minimal]
269-
description =
270-
check against Sage minimal style conventions
271-
deps = ruff
272-
# https://github.com/ChartBoost/ruff-action/issues/7#issuecomment-1887780308
273-
passenv = RUFF_OUTPUT_FORMAT
274-
# Output of currently failing, from "./sage -tox -e ruff -- --statistics":
275-
# 2872 I001 [*] unsorted-imports
276-
# 495 PLW0211 [ ] bad-staticmethod-argument
277-
# 473 PLW2901 [ ] redefined-loop-name
278-
# 375 PLR5501 [*] collapsible-else-if
279-
# 372 E731 [ ] lambda-assignment
280-
# 162 W292 [*] missing-newline-at-end-of-file
281-
# 94 PLW0603 [ ] global-statement
282-
# 90 PLR0402 [*] manual-from-import
283-
# 61 PLW0642 [ ] self-or-cls-assignment
284-
# 56 PLR1704 [ ] redefined-argument-from-local
285-
# 43 PLW0602 [ ] global-variable-not-assigned
286-
# 39 PLC0206 [ ] dict-index-missing-items
287-
# 16 PLW1510 [*] subprocess-run-without-check
288-
# 8 PLW1508 [ ] invalid-envvar-default
289-
# 7 PLR0124 [ ] comparison-with-itself
290-
# 5 E721 [ ] type-comparison
291-
# 3 PLC3002 [ ] unnecessary-direct-lambda-call
292-
# 3 PLE0302 [ ] unexpected-special-method-signature
293-
# 3 PLW3301 [ ] nested-min-max
294-
# 2 E742 [ ] ambiguous-class-name
295-
commands =
296-
ruff check {posargs:{toxinidir}/sage/}
297-
ruff check --preview {posargs:{toxinidir}/sage/}
298-
299261
[flake8]
300262
rst-roles =
301263
# Sphinx

tox.ini

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,23 +1098,3 @@ passenv = {[sage_src]passenv}
10981098
envdir = {[sage_src]envdir}
10991099
commands = {[sage_src]commands}
11001100
allowlist_externals = {[sage_src]allowlist_externals}
1101-
1102-
[testenv:ruff]
1103-
description =
1104-
check against Python style conventions
1105-
passenv = {[sage_src]passenv}
1106-
# https://github.com/ChartBoost/ruff-action/issues/7#issuecomment-1887780308
1107-
RUFF_OUTPUT_FORMAT
1108-
envdir = {[sage_src]envdir}
1109-
allowlist_externals = {[sage_src]allowlist_externals}
1110-
commands = tox -c {toxinidir}/src/tox.ini -e {envname} -- {posargs:src/sage/}
1111-
1112-
[testenv:ruff-minimal]
1113-
description =
1114-
check against Sage's minimal style conventions
1115-
passenv = {[sage_src]passenv}
1116-
# https://github.com/ChartBoost/ruff-action/issues/7#issuecomment-1887780308
1117-
RUFF_OUTPUT_FORMAT
1118-
envdir = {[sage_src]envdir}
1119-
allowlist_externals = {[sage_src]allowlist_externals}
1120-
commands = tox -c {toxinidir}/src/tox.ini -e {envname} -- {posargs:src/sage/}

0 commit comments

Comments
 (0)