Skip to content

Commit c01db9f

Browse files
committed
Use ruff instead of flake8 to check PEP8
1 parent 7e997ae commit c01db9f

File tree

9 files changed

+51
-131
lines changed

9 files changed

+51
-131
lines changed

.flake8

-91
This file was deleted.

.github/workflows/reviewdog.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ permissions:
66
contents: read
77

88
jobs:
9-
flake8:
10-
name: flake8
9+
ruff:
10+
name: ruff
1111
runs-on: ubuntu-latest
1212
permissions:
1313
checks: write
@@ -21,19 +21,19 @@ jobs:
2121
with:
2222
python-version: '3.10'
2323

24-
- name: Install flake8
25-
run: pip3 install -r requirements/testing/flake8.txt
24+
- name: Install ruff
25+
run: pip3 install ruff
2626

2727
- name: Set up reviewdog
2828
uses: reviewdog/action-setup@e04ffabe3898a0af8d0fb1af00c188831c4b5893 # v1.3.9
2929

30-
- name: Run flake8
30+
- name: Run ruff
3131
env:
3232
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3333
run: |
3434
set -o pipefail
35-
flake8 --docstring-convention=all | \
36-
reviewdog -f=pep8 -name=flake8 \
35+
ruff check --output-format rdjson | \
36+
reviewdog -f=rdjson \
3737
-tee -reporter=github-check -filter-mode nofilter
3838
mypy:
3939
name: mypy

.pre-commit-config.yaml

+7-8
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ repos:
4141
args: ["--config-file=pyproject.toml", "lib/matplotlib"]
4242
files: lib/matplotlib # Only run when files in lib/matplotlib are changed.
4343
pass_filenames: false
44-
- repo: https://github.com/pycqa/flake8
45-
rev: 7.1.1
44+
45+
- repo: https://github.com/astral-sh/ruff-pre-commit
46+
# Ruff version.
47+
rev: v0.11.0
4648
hooks:
47-
- id: flake8
48-
additional_dependencies:
49-
- pydocstyle>5.1.0
50-
- flake8-docstrings>1.4.0
51-
- flake8-force
52-
args: ["--docstring-convention=all"]
49+
# Run the linter.
50+
- id: ruff
51+
args: [--fix, --show-fixes]
5352
- repo: https://github.com/codespell-project/codespell
5453
rev: v2.3.0
5554
hooks:

doc/devel/coding_guide.rst

+16-10
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,28 @@ consistency, and maintainability of the code base.
1515

1616
.. _code-style:
1717

18-
PEP8, as enforced by flake8
19-
===========================
18+
PEP8, as enforced by ruff
19+
=========================
2020

21-
Formatting should follow the recommendations of PEP8_, as enforced by flake8_.
21+
Formatting should follow the recommendations of PEP8_, as enforced by ruff_.
2222
Matplotlib modifies PEP8 to extend the maximum line length to 88
23-
characters. You can check flake8 compliance from the command line with ::
23+
characters. You can check PEP8 compliance from the command line with ::
24+
25+
python -m pip install ruff
26+
ruff check /path/to/module.py
27+
28+
or your editor may provide integration with it. To check all files,
29+
and fix any errors in-place (where possible) run ::
30+
31+
ruff check --fix
2432

25-
python -m pip install flake8
26-
flake8 /path/to/module.py
2733

28-
or your editor may provide integration with it. Note that Matplotlib intentionally
29-
does not use the black_ auto-formatter (1__), in particular due to its inability
30-
to understand the semantics of mathematical expressions (2__, 3__).
34+
Matplotlib intentionally does not use the black_ auto-formatter (1__),
35+
in particular due to its inability to understand the semantics of
36+
mathematical expressions (2__, 3__).
3137

3238
.. _PEP8: https://www.python.org/dev/peps/pep-0008/
33-
.. _flake8: https://flake8.pycqa.org/
39+
.. _ruff: https://docs.astral.sh/ruff/
3440
.. _black: https://black.readthedocs.io/
3541
.. __: https://github.com/matplotlib/matplotlib/issues/18796
3642
.. __: https://github.com/psf/black/issues/148

doc/install/dependencies.rst

-3
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ otherwise they must be installed manually:
346346
- pikepdf_ used in some tests for the pgf and pdf backends
347347
- psutil_ used in testing the interactive backends
348348
- pytest-cov_ (>= 2.3.1) to collect coverage information
349-
- pytest-flake8_ to test coding standards using flake8_
350349
- pytest-timeout_ to limit runtime in case of stuck tests
351350
- pytest-xdist_ to run tests in parallel
352351
- pytest-xvfb_ to run tests without windows popping up (Linux)
@@ -373,15 +372,13 @@ them will be skipped by pytest.
373372
.. _Ghostscript: https://ghostscript.com/
374373
.. _Inkscape: https://inkscape.org
375374
.. _WenQuanYi Zen Hei: http://wenq.org/en/
376-
.. _flake8: https://pypi.org/project/flake8/
377375
.. _nbconvert: https://pypi.org/project/nbconvert/
378376
.. _nbformat: https://pypi.org/project/nbformat/
379377
.. _pandas: https://pypi.org/project/pandas/
380378
.. _pikepdf: https://pypi.org/project/pikepdf/
381379
.. _psutil: https://pypi.org/project/psutil/
382380
.. _pytz: https://fonts.google.com/noto/use#faq
383381
.. _pytest-cov: https://pytest-cov.readthedocs.io/en/latest/
384-
.. _pytest-flake8: https://pypi.org/project/pytest-flake8/
385382
.. _pytest-timeout: https://pypi.org/project/pytest-timeout/
386383
.. _pytest-xdist: https://pypi.org/project/pytest-xdist/
387384
.. _pytest-xvfb: https://pypi.org/project/pytest-xvfb/

environment.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ dependencies:
5555
# testing
5656
- black<24
5757
- coverage
58-
- flake8>=3.8,<7.2
59-
- flake8-docstrings>=1.4.0
6058
- gtk4
6159
- ipykernel
6260
- nbconvert[execute]!=6.0.0,!=6.0.1,!=7.3.0,!=7.3.1
@@ -72,4 +70,5 @@ dependencies:
7270
- pytest-xdist
7371
- tornado
7472
- pytz
73+
- ruff
7574
- tox

pyproject.toml

+19
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ exclude = [
9999
"tools/gh_api.py",
100100
".tox",
101101
".eggs",
102+
# TODO: fix .pyi files
103+
"*.pyi",
104+
# TODO: fix .ipynb files
105+
"*.ipynb"
102106
]
103107
line-length = 88
104108
target-version = "py310"
@@ -112,15 +116,28 @@ ignore = [
112116
"D104",
113117
"D105",
114118
"D106",
119+
"D107",
115120
"D200",
116121
"D202",
122+
"D203",
117123
"D204",
118124
"D205",
125+
"D212",
119126
"D301",
120127
"D400",
121128
"D401",
129+
"D402",
122130
"D403",
123131
"D404",
132+
"D413",
133+
"D415",
134+
"D416",
135+
"D417",
136+
"E24",
137+
"E266",
138+
"E305",
139+
"E306",
140+
"E721",
124141
"E741",
125142
"F841",
126143
]
@@ -180,6 +197,7 @@ convention = "numpy"
180197
"galleries/examples/user_interfaces/pylab_with_gtk4_sgskip.py" = ["E402"]
181198
"galleries/examples/userdemo/pgf_preamble_sgskip.py" = ["E402"]
182199

200+
"lib/matplotlib/__init__.py" = ["F822"]
183201
"lib/matplotlib/_cm.py" = ["E202", "E203"]
184202
"lib/matplotlib/_mathtext.py" = ["E221"]
185203
"lib/matplotlib/_mathtext_data.py" = ["E203"]
@@ -194,6 +212,7 @@ convention = "numpy"
194212
"lib/mpl_toolkits/mplot3d/proj3d.py" = ["E201"]
195213

196214
"galleries/users_explain/artists/paths.py" = ["E402"]
215+
"galleries/users_explain/quick_start.py" = ["E402"]
197216
"galleries/users_explain/artists/patheffects_guide.py" = ["E402"]
198217
"galleries/users_explain/artists/transforms_tutorial.py" = ["E402", "E501"]
199218
"galleries/users_explain/colors/colormaps.py" = ["E501"]

requirements/dev/dev-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
-r ../doc/doc-requirements.txt
33
-r ../testing/all.txt
44
-r ../testing/extra.txt
5-
-r ../testing/flake8.txt
5+
ruff

requirements/testing/flake8.txt

-9
This file was deleted.

0 commit comments

Comments
 (0)