8000 Use ruff instead of flake8 to check PEP8 by dstansby · Pull Request #29762 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Use ruff instead of flake8 to check PEP8 #29762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 0 additions & 91 deletions .flake8

This file was deleted.

14 changes: 7 additions & 7 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ permissions:
contents: read

jobs:
flake8:
name: flake8
ruff:
name: ruff
runs-on: ubuntu-latest
permissions:
checks: write
Expand All @@ -21,19 +21,19 @@ jobs:
with:
python-version: '3.10'

- name: Install flake8
run: pip3 install -r requirements/testing/flake8.txt
- name: Install ruff
run: pip3 install ruff

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

- name: Run flake8
- name: Run ruff
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -o pipefail
flake8 --docstring-convention=all | \
reviewdog -f=pep8 -name=flake8 \
ruff check --output-format rdjson | \
reviewdog -f=rdjson \
-tee -reporter=github-check -filter-mode nofilter
mypy:
name: mypy
Expand Down
15 changes: 7 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ repos:
args: ["--config-file=pyproject.toml", "lib/matplotlib"]
files: lib/matplotlib # Only run when files in lib/matplotlib are changed.
pass_filenames: false
- repo: https://github.com/pycqa/flake8
rev: 7.1.1

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.11.0
hooks:
- id: flake8
additional_dependencies:
- pydocstyle>5.1.0
- flake8-docstrings>1.4.0
- flake8-force
args: ["--docstring-convention=all"]
# Run the linter.
- id: ruff
args: [--fix, --show-fixes]
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
Expand Down
26 changes: 16 additions & 10 deletions doc/devel/coding_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,28 @@ consistency, and maintainability of the code base.

.. _code-style:

PEP8, as enforced by flake8
===========================
PEP8, as enforced by ruff
=========================

Formatting should follow the recommendations of PEP8_, as enforced by flake8_.
Formatting should follow the recommendations of PEP8_, as enforced by ruff_.
Matplotlib modifies PEP8 to extend the maximum line length to 88
characters. You can check flake8 compliance from the command line with ::
characters. You can check PEP8 compliance from the command line with ::

python -m pip install ruff
ruff check /path/to/module.py

or your editor may provide integration with it. To check all files,
and fix any errors in-place (where possible) run ::

ruff check --fix

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

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

.. _PEP8: https://www.python.org/dev/peps/pep-0008/
.. _flake8: https://flake8.pycqa.org/
.. _ruff: https://docs.astral.sh/ruff/
.. _black: https://black.readthedocs.io/
.. __: https://github.com/matplotlib/matplotlib/issues/18796
.. __: https://github.com/psf/black/issues/148
Expand Down
3 changes: 0 additions & 3 deletions doc/install/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ otherwise they must be installed manually:
- pikepdf_ used in some tests for the pgf and pdf backends
- psutil_ used in testing the interactive backends
- pytest-cov_ (>= 2.3.1) to collect coverage information
- pytest-flake8_ to test coding standards using flake8_
- pytest-timeout_ to limit runtime in case of stuck tests
- pytest-xdist_ to run tests in parallel
- pytest-xvfb_ to run tests without windows popping up (Linux)
Expand All @@ -373,15 +372,13 @@ them will be skipped by pytest.
.. _Ghostscript: https://ghostscript.com/
.. _Inkscape: https://inkscape.org
.. _WenQuanYi Zen Hei: http://wenq.org/en/
.. _flake8: https://pypi.org/project/flake8/
.. _nbconvert: https://pypi.org/project/nbconvert/
.. _nbformat: https://pypi.org/project/nbformat/
.. _pandas: https://pypi.org/project/pandas/
.. _pikepdf: https://pypi.org/project/pikepdf/
.. _psutil: https://pypi.org/project/psutil/
.. _pytz: https://fonts.google.com/noto/use#faq
.. _pytest-cov: https://pytest-cov.readthedocs.io/en/latest/
.. _pytest-flake8: https://pypi.org/project/pytest-flake8/
.. _pytest-timeout: https://pypi.org/project/pytest-timeout/
.. _pytest-xdist: https://pypi.org/project/pytest-xdist/
.. _pytest-xvfb: https://pypi.org/project/pytest-xvfb/
Expand Down
3 changes: 1 addition & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ dependencies:
# testing
- black<24
- coverage
- flake8>=3.8,<7.2
- flake8-docstrings>=1.4.0
- gtk4
- ipykernel
- nbconvert[execute]!=6.0.0,!=6.0.1,!=7.3.0,!=7.3.1
Expand All @@ -72,4 +70,5 @@ dependencies:
- pytest-xdist
- tornado
- pytz
- ruff
- tox
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/mplot3d/tests/test_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ def test_rotate(style):

c = np.sqrt(3)/2
expectations = {
('azel', 0, 1, 0): (0, -45, 0),
('azel', 0, 1, 0): (0, -45, 0),
('azel', 0, 0, 1): (-45, 0, 0),
('azel', 0, 0.5, c): (-38.971143, -22.5, 0),
('azel', 0, 2, 0): (0, -90, 0),
Expand Down
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ exclude = [
"tools/gh_api.py",
".tox",
".eggs",
# TODO: fix .pyi files
"*.pyi",
# TODO: fix .ipynb files
"*.ipynb"
]
line-length = 88
target-version = "py310"
Expand All @@ -112,15 +116,28 @@ ignore = [
"D104",
"D105",
"D106",
"D107",
"D200",
"D202",
"D203",
"D204",
"D205",
"D212",
"D301",
"D400",
"D401",
"D402",
"D403",
"D404",
"D413",
"D415",
"D416",
"D417",
"E24",
"E266",
"E305",
"E306",
"E721",
"E741",
"F841",
]
Expand Down Expand Up @@ -180,6 +197,7 @@ convention = "numpy"
"galleries/examples/user_interfaces/pylab_with_gtk4_sgskip.py" = ["E402"]
"galleries/examples/userdemo/pgf_preamble_sgskip.py" = ["E402"]

"lib/matplotlib/__init__.py" = ["F822"]
"lib/matplotlib/_cm.py" = ["E202", "E203"]
"lib/matplotlib/_mathtext.py" = ["E221"]
"lib/matplotlib/_mathtext_data.py" = ["E203"]
Expand All @@ -194,6 +212,7 @@ convention = "numpy"
"lib/mpl_toolkits/mplot3d/proj3d.py" = ["E201"]

"galleries/users_explain/artists/paths.py" = ["E402"]
"galleries/users_explain/quick_start.py" = ["E402"]
"galleries/users_explain/artists/patheffects_guide.py" = ["E402"]
"galleries/users_explain/artists/transforms_tutorial.py" = ["E402", "E501"]
"galleries/users_explain/colors/colormaps.py" = ["E501"]
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev/dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
-r ../doc/doc-requirements.txt
-r ../testing/all.txt
-r ../testing/extra.txt
-r ../testing/flake8.txt
ruff
9 changes: 0 additions & 9 deletions requirements/testing/flake8.txt
< 5E40 div class="file-actions pt-0 mb-md-0 mb-2 ml-md-2 flex-shrink-0 flex-md-justify-end">

This file was deleted.

Loading
0