From 4ab19d2dc656029b7f90599fca97fd6ebb9368df Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sun, 22 Oct 2023 13:34:21 +0000 Subject: [PATCH 01/12] Add config for ruff --- .devcontainer/devcontainer.json | 5 ++--- .vscode/extensions.json | 3 ++- .vscode/settings.json | 5 ----- pyproject.toml | 13 +++++++++++++ 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 pyproject.toml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c9b3aeb71a6..40b6f52c00a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -22,13 +22,12 @@ "vscode": { "extensions": [ "guyskk.language-cython", - "ms-python.isort", "ms-toolsai.jupyter", "ms-python.vscode-pylance", - "ms-python.pylint", "ms-python.python", "lextudio.restructuredtext", - "trond-snekvik.simple-rst" + "trond-snekvik.simple-rst", + "charliermarsh.ruff" ] } } diff --git a/.vscode/extensions.json b/.vscode/extensions.json index d0efd087bc9..a304fa28467 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,6 +2,7 @@ // List of extensions which should be recommended for developers when a workspace is opened for the first time. // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. "recommendations": [ - "ms-python.python" + "ms-python.python", + "charliermarsh.ruff" ], } diff --git a/.vscode/settings.json b/.vscode/settings.json index 86885e6ea4a..86eac03ffe9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,11 +24,6 @@ "--doctest-modules" ], "python.testing.unittestEnabled": false, - "python.linting.pycodestyleEnabled": true, - "python.linting.enabled": true, - // The following pycodestyle arguments are the same as the pycodestyle-minimal - // tox environnment, see the file SAGE_ROOT/src/tox.ini - "python.linting.pycodestyleArgs": ["--select= E111,E21,E222,E225,E227,E228,E25,E271,E303,E305,E306,E401,E502,E701,E702,E703,E71,E72,W291,W293,W391,W605"], "cSpell.words": [ "furo", "Conda", diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000000..d5ce3e63cda --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[tool.ruff] +# Assume Python 3.9 +target-version = "py39" + +select = [ + "E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e + "F", # pyflakes - https://docs.astral.sh/ruff/rules/#pyflakes-f + "I", # isort - https://docs.astral.sh/ruff/rules/#isort-i + "PL", # pylint - https://docs.astral.sh/ruff/rules/#pylint-pl +] +ignore = [ + "E501", # Line too long - hard to avoid in doctests, and better handled by black. +] From 0d6c6939cd3a01abe7288af154a7e0b8bcddf8bc Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 10:44:39 -0800 Subject: [PATCH 02/12] src/ruff.toml: Move ruff config here --- pyproject.toml => src/ruff.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename pyproject.toml => src/ruff.toml (86%) diff --git a/pyproject.toml b/src/ruff.toml similarity index 86% rename from pyproject.toml rename to src/ruff.toml index d5ce3e63cda..d6dd6fed1bd 100644 --- a/pyproject.toml +++ b/src/ruff.toml @@ -1,4 +1,5 @@ -[tool.ruff] +# https://docs.astral.sh/ruff/configuration/#config-file-discovery + # Assume Python 3.9 target-version = "py39" From 5f666ff21d510a1f805b325f991ca57abac9d1ca Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 11:38:10 -0800 Subject: [PATCH 03/12] tox.ini, src/tox.ini: New --- src/tox.ini | 6 ++++++ tox.ini | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/tox.ini b/src/tox.ini index 8e562cced8e..48b312c97e5 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -240,6 +240,12 @@ description = deps = cython-lint commands = cython-lint --no-pycodestyle {posargs:{toxinidir}/sage/} +[testenv:ruff] +description = + check against Python style conventions +deps = ruff +commands = ruff {posargs:{toxinidir}/sage/} + [flake8] rst-roles = # Sphinx diff --git a/tox.ini b/tox.ini index 3673833724c..b16702d9b8a 100644 --- a/tox.ini +++ b/tox.ini @@ -1045,3 +1045,11 @@ passenv = {[sage_src]passenv} envdir = {[sage_src]envdir} commands = {[sage_src]commands} allowlist_externals = {[sage_src]allowlist_externals} + +[testenv:ruff] +description = + check against Python style conventions +passenv = {[sage_src]passenv} +envdir = {[sage_src]envdir} +allowlist_externals = {[sage_src]allowlist_externals} +commands = tox -c {toxinidir}/src/tox.ini -e {envname} -- {posargs:src/sage/} From a470b694609284dc7a42df5d18be6add17e5e840 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 11:49:43 -0800 Subject: [PATCH 04/12] tox.ini, src/tox.ini: New environments ruff, ruff-minimal --- src/tox.ini | 6 ++++++ tox.ini | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/tox.ini b/src/tox.ini index 48b312c97e5..ef5e3d1cd1a 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -246,6 +246,12 @@ description = deps = ruff commands = ruff {posargs:{toxinidir}/sage/} +[testenv:ruff-minimal] +description = + check against Sage's minimal style conventions +deps = ruff +commands = ruff {posargs:{toxinidir}/sage/} + [flake8] rst-roles = # Sphinx diff --git a/tox.ini b/tox.ini index b16702d9b8a..4285c5a3790 100644 --- a/tox.ini +++ b/tox.ini @@ -1053,3 +1053,11 @@ passenv = {[sage_src]passenv} envdir = {[sage_src]envdir} allowlist_externals = {[sage_src]allowlist_externals} commands = tox -c {toxinidir}/src/tox.ini -e {envname} -- {posargs:src/sage/} + +[testenv:ruff-minimal] +description = + check against Sage's minimal style conventions +passenv = {[sage_src]passenv} +envdir = {[sage_src]envdir} +allowlist_externals = {[sage_src]allowlist_externals} +commands = tox -c {toxinidir}/src/tox.ini -e {envname} -- {posargs:src/sage/} From 1403f2183d0395653d9130692757411b381aea41 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 23 Oct 2023 12:53:46 -0700 Subject: [PATCH 05/12] src/tox.ini (ruff-minimal): Add --ignore. This is taken from https://github.com/sagemath/sage/pull/36512 --- src/tox.ini | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/tox.ini b/src/tox.ini index ef5e3d1cd1a..e18699c8b39 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -250,7 +250,52 @@ commands = ruff {posargs:{toxinidir}/sage/} description = check against Sage's minimal style conventions deps = ruff -commands = ruff {posargs:{toxinidir}/sage/} + # Ignore the following code style checks (currently failing): + # 3617 I001 [*] Import block is un-sorted or un-formatted + # 3554 PLR2004 [ ] Magic value used in comparison, consider replacing -0.5 with a constant variable + # 2065 F401 [*] `.PyPolyBoRi.Monomial` imported but unused + # 1939 E741 [ ] Ambiguous variable name: `I` + # 1635 F821 [ ] Undefined name `AA` + # 1500 PLR0912 [ ] Too many branches (102 > 12) + # 1156 PLR0913 [ ] Too many arguments to function call (10 > 5) + # 865 E402 [ ] Module level import not at top of file + # 660 PLR0915 [ ] Too many statements (100 > 50) + # 471 PLW2901 [ ] Outer `for` loop variable `ext` overwritten by inner `for` loop target + # 432 PLR5501 [ ] Use `elif` instead of `else` then `if`, to reduce indentation + # 423 PLR0911 [ ] Too many return statements (10 > 6) + # 354 E731 [*] Do not assign a `lambda` expression, use a `def` + # 351 F405 [ ] `ComplexField` may be undefined, or defined from star imports + # 300 PLR1714 [*] Consider merging multiple comparisons. Use a `set` if the elements are hashable. + # 240 F403 [ ] `from .abelian_gps.all import *` used; unable to detect undefined names + # 125 PLR0402 [*] Use `from matplotlib import cm` in lieu of alias + # 111 PLW0603 [ ] Using the global statement to update `AA_0` is discouraged + # 90 E713 [*] Test for membership should be `not in` + # 69 F841 [*] Local variable `B` is assigned to but never used + # 48 PLW0602 [ ] Using global for `D` but no assignment is done + # 44 E714 [*] Test for object identity should be `is not` + # 35 PLR1711 [*] Useless `return` statement at end of function + # 19 PLR1701 [*] Merge `isinstance` calls + # 17 PLW3301 [ ] Nested `max` calls can be flattened + # 15 E721 [ ] Do not compare types, use `isinstance()` + # 15 PLW1510 [ ] `subprocess.run` without explicit `check` argument + # 14 F811 [ ] Redefinition of unused `CompleteDiscreteValuationRings` from line 44 + # 14 PLW0120 [ ] `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + # 8 PLC0414 [*] Import alias does not rename original package + # 7 E743 [ ] Ambiguous function name: `I` + # 7 F541 [*] f-string without any placeholders + # 7 PLE0101 [ ] Explicit return in `__init__` + # 7 PLR0124 [ ] Name compared with itself, consider replacing `a == a` + # 5 PLW0127 [ ] Self-assignment of variable `a` + # 4 PLW1508 [ ] Invalid type for environment variable default; expected `str` or `None` + # 3 PLC3002 [ ] Lambda expression called directly. Execute the expression inline instead. + # 2 E742 [ ] Ambiguous class name: `I` + # 2 PLE0302 [ ] The special method `__len__` expects 1 parameter, 3 were given + # 1 E701 [ ] Multiple statements on one line (colon) + # 1 F402 [ ] Import `factor` from line 259 shadowed by loop variable + # 1 F823 [ ] Local variable `zero` referenced before assignment + # 1 PLC0208 [*] Use a sequence type instead of a `set` when iterating over values + # 1 PLW0129 [ ] Asserting on a non-empty string literal will always pass +commands = ruff --ignore I001,PLR2004,F401,E741,F821,PLR0912,PLR0913,E402,PLR0915,PLW2901,PLR5501,PLR0911,E731,F405,PLR1714,F403,PLR0402,PLW0603,E713,F841,PLW0602,E714,PLR1711,PLR1701,PLW3301,E721,PLW1510,F811,PLW0120,PLC0414,E743,F541,PLE0101,PLR0124,PLW0127,PLW1508,PLC3002,E742,PLE0302,E701,F402,F823,PLC0208,PLW0129,E902 {posargs:{toxinidir}/sage/} [flake8] rst-roles = From e652031974ebf67b689d4e821e4817362097a0d9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 11:56:01 -0800 Subject: [PATCH 06/12] src/tox.ini: Add ruff-minimal to envlist --- src/tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tox.ini b/src/tox.ini index e18699c8b39..df97205c9a2 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -21,7 +21,7 @@ ## in a virtual environment. ## [tox] -envlist = doctest, coverage, startuptime, pycodestyle-minimal, relint, codespell, rst +envlist = doctest, coverage, startuptime, pycodestyle-minimal, relint, codespell, rst, ruff-minimal # When adding environments above, also update the delegations in SAGE_ROOT/tox.ini skipsdist = true From 0bc1068d6640a118d8ad2a9667d037fb00397801 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 12:10:53 -0800 Subject: [PATCH 07/12] src/doc/en/developer/tools.rst: Update for ruff --- src/doc/en/developer/tools.rst | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/doc/en/developer/tools.rst b/src/doc/en/developer/tools.rst index 02be3f91b4b..fdb93020121 100644 --- a/src/doc/en/developer/tools.rst +++ b/src/doc/en/developer/tools.rst @@ -49,7 +49,7 @@ available:: --tox [options] -- general entry point for testing and linting of the Sage library -e -- run specific test environments; default: - doctest,coverage,startuptime,pycodestyle-minimal,relint,codespell,rst + doctest,coverage,startuptime,pycodestyle-minimal,relint,codespell,rst,ruff-minimal doctest -- run the Sage doctester (same as "sage -t") coverage -- give information about doctest coverage of files @@ -61,11 +61,13 @@ available:: (includes all patchbot pattern-exclusion plugins) codespell -- check for misspelled words in source code rst -- validate Python docstrings markup as reStructuredText + ruff-minimal -- check against Sage's minimal style conventions coverage.py -- run the Sage doctester with Coverage.py coverage.py-html -- run the Sage doctester with Coverage.py, generate HTML report pyright -- run the static typing checker pyright pycodestyle -- check against the Python style conventions of PEP8 cython-lint -- check Cython files for code style + ruff -- check against Python style conventions -p auto -- run test environments in parallel --help -- show tox help @@ -288,6 +290,21 @@ for Python code, written in Rust. It comes with a large choice of possible checks, and has the capacity to fix some of the warnings it emits. +Sage defines two configurations for ruff. The command ``./sage -tox -e ruff-minimal`` uses +ruff in a minimal configuration. As of Sage 10.3, the entire Sage library conforms to this +configuration. When preparing a Sage PR, developers should verify that +``./sage -tox -e ruff-minimal`` passes. + +The second configuration is used with the command ``./sage -tox -e ruff`` and runs a +more thorough check. When preparing a PR that adds new code, +developers should verify that ``./sage -tox -e ruff`` does not +issue warnings for the added code. This will avoid later cleanup +PRs as the Sage codebase is moving toward full PEP 8 compliance. + +On the other hand, it is usually not advisable to mix coding-style +fixes with productive changes on the same PR because this would +makes it harder for reviewers to evaluate the changes. + .. _section-tools-relint: Relint From 5ff85258074d3efa8d55b2e7f0c3557f918665d9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 12:22:48 -0800 Subject: [PATCH 08/12] .github/workflows/lint.yml: Run tox -e ruff-minimal --- .github/workflows/lint.yml | 9 ++++++++- src/tox.ini | 2 ++ tox.ini | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5d444594877..18bfdc167c7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -37,7 +37,14 @@ jobs: id: deps run: pip install tox - - name: Code style check with pycodestyle + - name: Code style check with ruff-minimal + if: (success() || failure()) && steps.deps.outcome == 'success' + run: tox -e ruff-minimal + env: + # https://github.com/ChartBoost/ruff-action/issues/7#issuecomment-1887780308 + RUFF_OUTPUT_FORMAT: github + + - name: Code style check with pycodestyle-minimal if: (success() || failure()) && steps.deps.outcome == 'success' run: tox -e pycodestyle-minimal diff --git a/src/tox.ini b/src/tox.ini index df97205c9a2..82ffe6a2079 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -250,6 +250,8 @@ commands = ruff {posargs:{toxinidir}/sage/} description = check against Sage's minimal style conventions deps = ruff +# https://github.com/ChartBoost/ruff-action/issues/7#issuecomment-1887780308 +passenv = RUFF_OUTPUT_FORMAT # Ignore the following code style checks (currently failing): # 3617 I001 [*] Import block is un-sorted or un-formatted # 3554 PLR2004 [ ] Magic value used in comparison, consider replacing -0.5 with a constant variable diff --git a/tox.ini b/tox.ini index 4285c5a3790..218c32586aa 100644 --- a/tox.ini +++ b/tox.ini @@ -1050,6 +1050,8 @@ allowlist_externals = {[sage_src]allowlist_externals} description = check against Python style conventions passenv = {[sage_src]passenv} + # https://github.com/ChartBoost/ruff-action/issues/7#issuecomment-1887780308 + RUFF_OUTPUT_FORMAT envdir = {[sage_src]envdir} allowlist_externals = {[sage_src]allowlist_externals} commands = tox -c {toxinidir}/src/tox.ini -e {envname} -- {posargs:src/sage/} From 88cacf3e031aed5c8ddac7363cb748b58e6045dd Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 13:05:27 -0800 Subject: [PATCH 09/12] src/ruff.toml: Update according to 'warning: The top-level linter settings are deprecated in favour of their counterparts in the lint section.' --- src/ruff.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ruff.toml b/src/ruff.toml index d6dd6fed1bd..b3070914153 100644 --- a/src/ruff.toml +++ b/src/ruff.toml @@ -3,12 +3,12 @@ # Assume Python 3.9 target-version = "py39" -select = [ +lint.select = [ "E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e "F", # pyflakes - https://docs.astral.sh/ruff/rules/#pyflakes-f "I", # isort - https://docs.astral.sh/ruff/rules/#isort-i "PL", # pylint - https://docs.astral.sh/ruff/rules/#pylint-pl ] -ignore = [ +lint.ignore = [ "E501", # Line too long - hard to avoid in doctests, and better handled by black. ] From 9a73dedae26469f43981c60f2830dbda336d392d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 13:20:02 -0800 Subject: [PATCH 10/12] src/tox.ini (ruff-minimal): Document command to obtain statistics, update ignored codes --- src/tox.ini | 92 ++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/tox.ini b/src/tox.ini index 82ffe6a2079..cf013e89fbd 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -252,52 +252,52 @@ description = deps = ruff # https://github.com/ChartBoost/ruff-action/issues/7#issuecomment-1887780308 passenv = RUFF_OUTPUT_FORMAT - # Ignore the following code style checks (currently failing): - # 3617 I001 [*] Import block is un-sorted or un-formatted - # 3554 PLR2004 [ ] Magic value used in comparison, consider replacing -0.5 with a constant variable - # 2065 F401 [*] `.PyPolyBoRi.Monomial` imported but unused - # 1939 E741 [ ] Ambiguous variable name: `I` - # 1635 F821 [ ] Undefined name `AA` - # 1500 PLR0912 [ ] Too many branches (102 > 12) - # 1156 PLR0913 [ ] Too many arguments to function call (10 > 5) - # 865 E402 [ ] Module level import not at top of file - # 660 PLR0915 [ ] Too many statements (100 > 50) - # 471 PLW2901 [ ] Outer `for` loop variable `ext` overwritten by inner `for` loop target - # 432 PLR5501 [ ] Use `elif` instead of `else` then `if`, to reduce indentation - # 423 PLR0911 [ ] Too many return statements (10 > 6) - # 354 E731 [*] Do not assign a `lambda` expression, use a `def` - # 351 F405 [ ] `ComplexField` may be undefined, or defined from star imports - # 300 PLR1714 [*] Consider merging multiple comparisons. Use a `set` if the elements are hashable. - # 240 F403 [ ] `from .abelian_gps.all import *` used; unable to detect undefined names - # 125 PLR0402 [*] Use `from matplotlib import cm` in lieu of alias - # 111 PLW0603 [ ] Using the global statement to update `AA_0` is discouraged - # 90 E713 [*] Test for membership should be `not in` - # 69 F841 [*] Local variable `B` is assigned to but never used - # 48 PLW0602 [ ] Using global for `D` but no assignment is done - # 44 E714 [*] Test for object identity should be `is not` - # 35 PLR1711 [*] Useless `return` statement at end of function - # 19 PLR1701 [*] Merge `isinstance` calls - # 17 PLW3301 [ ] Nested `max` calls can be flattened - # 15 E721 [ ] Do not compare types, use `isinstance()` - # 15 PLW1510 [ ] `subprocess.run` without explicit `check` argument - # 14 F811 [ ] Redefinition of unused `CompleteDiscreteValuationRings` from line 44 - # 14 PLW0120 [ ] `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it - # 8 PLC0414 [*] Import alias does not rename original package - # 7 E743 [ ] Ambiguous function name: `I` - # 7 F541 [*] f-string without any placeholders - # 7 PLE0101 [ ] Explicit return in `__init__` - # 7 PLR0124 [ ] Name compared with itself, consider replacing `a == a` - # 5 PLW0127 [ ] Self-assignment of variable `a` - # 4 PLW1508 [ ] Invalid type for environment variable default; expected `str` or `None` - # 3 PLC3002 [ ] Lambda expression called directly. Execute the expression inline instead. - # 2 E742 [ ] Ambiguous class name: `I` - # 2 PLE0302 [ ] The special method `__len__` expects 1 parameter, 3 were given - # 1 E701 [ ] Multiple statements on one line (colon) - # 1 F402 [ ] Import `factor` from line 259 shadowed by loop variable - # 1 F823 [ ] Local variable `zero` referenced before assignment - # 1 PLC0208 [*] Use a sequence type instead of a `set` when iterating over values - # 1 PLW0129 [ ] Asserting on a non-empty string literal will always pass -commands = ruff --ignore I001,PLR2004,F401,E741,F821,PLR0912,PLR0913,E402,PLR0915,PLW2901,PLR5501,PLR0911,E731,F405,PLR1714,F403,PLR0402,PLW0603,E713,F841,PLW0602,E714,PLR1711,PLR1701,PLW3301,E721,PLW1510,F811,PLW0120,PLC0414,E743,F541,PLE0101,PLR0124,PLW0127,PLW1508,PLC3002,E742,PLE0302,E701,F402,F823,PLC0208,PLW0129,E902 {posargs:{toxinidir}/sage/} +# Output of currently failing, from "./sage -tox -e ruff -- check --statistics": +# +# 3579 PLR2004 [ ] Magic value used in comparison, consider replacing `- 0.5` with a constant variable +# 3498 I001 [*] Import block is un-sorted or un-formatted +# 2146 F401 [*] `.PyPolyBoRi.Monomial` imported but unused +# 1964 E741 [ ] Ambiguous variable name: `I` +# 1676 F821 [ ] Undefined name `AA` +# 1513 PLR0912 [ ] Too many branches (102 > 12) +# 1159 PLR0913 [ ] Too many arguments in function definition (10 > 5) +# 815 E402 [ ] Module level import not at top of file +# 671 PLR0915 [ ] Too many statements (100 > 50) +# 483 PLW2901 [ ] Outer `for` loop variable `ext` overwritten by inner `for` loop target +# 433 PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation +# 428 PLR0911 [ ] Too many return statements (10 > 6) +# 404 E731 [*] Do not assign a `lambda` expression, use a `def` +# 351 F405 [ ] `ComplexField` may be undefined, or defined from star imports +# 306 PLR1714 [*] Consider merging multiple comparisons. Use a `set` if the elements are hashable. +# 236 F403 [ ] `from .abelian_gps.all import *` used; unable to detect undefined names +# 116 PLR0402 [*] Use `from matplotlib import cm` in lieu of alias +# 111 PLW0603 [ ] Using the global statement to update `AA_0` is discouraged +# 78 F841 [*] Local variable `B` is assigned to but never used +# 64 E713 [*] Test for membership should be `not in` +# 48 PLW0602 [ ] Using global for `D` but no assignment is done +# 33 PLR1711 [*] Useless `return` statement at end of function +# 24 E714 [*] Test for object identity should be `is not` +# 20 PLR1701 [*] Merge `isinstance` calls +# 17 PLW3301 [ ] Nested `max` calls can be flattened +# 16 PLW1510 [*] `subprocess.run` without explicit `check` argument +# 14 E721 [ ] Do not compare types, use `isinstance()` +# 14 PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents +# 12 F811 [*] Redefinition of unused `CompleteDiscreteValuationRings` from line 49 +# 8 PLC0414 [*] Import alias does not rename original package +# 7 E743 [ ] Ambiguous function name: `I` +# 7 PLE0101 [ ] Explicit return in `__init__` +# 7 PLR0124 [ ] Name compared with itself, consider replacing `a == a` +# 5 PLW0127 [ ] Self-assignment of variable `a` +# 4 F541 [*] f-string without any placeholders +# 4 PLW1508 [ ] Invalid type for environment variable default; expected `str` or `None` +# 3 PLC3002 [ ] Lambda expression called directly. Execute the expression inline instead. +# 2 E742 [ ] Ambiguous class name: `I` +# 2 PLE0302 [ ] The special method `__len__` expects 1 parameter, 3 were given +# 2 PLW0129 [ ] Asserting on a non-empty string literal will always pass +# 1 F402 [ ] Import `factor` from line 259 shadowed by loop variable +# 1 PLC0208 [*] Use a sequence type instead of a `set` when iterating over values +# +commands = ruff --ignore I001,PLR2004,F401,E741,F821,PLR0912,PLR0913,E402,PLR0915,PLW2901,PLR5501,PLR0911,E731,F405,PLR1714,F403,PLR0402,PLW0603,E713,F841,PLW0602,E714,PLR1711,PLR1701,PLW3301,E721,PLW1510,F811,PLW0120,PLC0414,E743,F541,PLE0101,PLR0124,PLW0127,PLW1508,PLC3002,E742,PLE0302,F402,PLC0208,PLW0129 {posargs:{toxinidir}/sage/} [flake8] rst-roles = From f6a8a6302ac733f65356cfa87aa9e1c8c8b1bf5d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 13:40:11 -0800 Subject: [PATCH 11/12] tox.ini, src/tox.ini: Passenv RUFF_OUTPUT_FORMAT in both rust envs --- src/tox.ini | 1 + tox.ini | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/tox.ini b/src/tox.ini index cf013e89fbd..4b7bd566d2c 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -244,6 +244,7 @@ commands = cython-lint --no-pycodestyle {posargs:{toxinidir}/sage/} description = check against Python style conventions deps = ruff +passenv = RUFF_OUTPUT_FORMAT commands = ruff {posargs:{toxinidir}/sage/} [testenv:ruff-minimal] diff --git a/tox.ini b/tox.ini index 218c32586aa..fc932501597 100644 --- a/tox.ini +++ b/tox.ini @@ -1060,6 +1060,8 @@ commands = tox -c {toxinidir}/src/tox.ini -e {envname} -- {posargs:src/sage/} description = check against Sage's minimal style conventions passenv = {[sage_src]passenv} + # https://github.com/ChartBoost/ruff-action/issues/7#issuecomment-1887780308 + RUFF_OUTPUT_FORMAT envdir = {[sage_src]envdir} allowlist_externals = {[sage_src]allowlist_externals} commands = tox -c {toxinidir}/src/tox.ini -e {envname} -- {posargs:src/sage/} From 1d46dc72e4ff72262a804604ff946a382ba59a35 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 13:27:26 -0800 Subject: [PATCH 12/12] src/tox.ini (ruff-minimal): Do not --ignore PLW0129 --- src/tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tox.ini b/src/tox.ini index 4b7bd566d2c..2c0364869c6 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -298,7 +298,7 @@ passenv = RUFF_OUTPUT_FORMAT # 1 F402 [ ] Import `factor` from line 259 shadowed by loop variable # 1 PLC0208 [*] Use a sequence type instead of a `set` when iterating over values # -commands = ruff --ignore I001,PLR2004,F401,E741,F821,PLR0912,PLR0913,E402,PLR0915,PLW2901,PLR5501,PLR0911,E731,F405,PLR1714,F403,PLR0402,PLW0603,E713,F841,PLW0602,E714,PLR1711,PLR1701,PLW3301,E721,PLW1510,F811,PLW0120,PLC0414,E743,F541,PLE0101,PLR0124,PLW0127,PLW1508,PLC3002,E742,PLE0302,F402,PLC0208,PLW0129 {posargs:{toxinidir}/sage/} +commands = ruff --ignore I001,PLR2004,F401,E741,F821,PLR0912,PLR0913,E402,PLR0915,PLW2901,PLR5501,PLR0911,E731,F405,PLR1714,F403,PLR0402,PLW0603,E713,F841,PLW0602,E714,PLR1711,PLR1701,PLW3301,E721,PLW1510,F811,PLW0120,PLC0414,E743,F541,PLE0101,PLR0124,PLW0127,PLW1508,PLC3002,E742,PLE0302,F402,PLC0208 {posargs:{toxinidir}/sage/} [flake8] rst-roles =