diff --git a/.flake8 b/.flake8 index 3fba9604fab8..ec8be001a430 100644 --- a/.flake8 +++ b/.flake8 @@ -2,16 +2,7 @@ max-line-length = 88 select = # flake8 default - C90, E, F, W, - # docstring-convention=numpy - D100, D101, D102, D103, D104, D105, D106, - D200, D201, D202, D204, D205, D206, D207, D208, - D209, D210, D211, D214, D215, - D300, D301, D302, - D400, D401, D403, D404, D405, D406, D407, D408, - D409, D410, D411, D412, D414, - # matplotlib-specific extra pydocstyle errors - D213, + D, E, F, W, ignore = # flake8 default E121,E123,E126,E226,E24,E704,W503,W504, @@ -19,15 +10,15 @@ ignore = E127, E131, E266, E305, E306, - E722, E741, + E741, F841, - # Some new flake8 ignores: - N801, N802, N803, N806, N812, # pydocstyle - D100, D101, D102, D103, D104, D105, D106, D107, - D200, D202, D203, D204, D205, D207, D212, + D100, D101, D102, D103, D104, D105, D106, + D200, D202, D204, D205, D301, - D400, D401, D402, D403, D404, D413, + D400, D401, D403, D404 + # ignored by pydocstyle numpy docstring convention + D107, D203, D212, D213, D402, D413, D415, D416, D417, exclude = .git @@ -42,7 +33,6 @@ exclude = per-file-ignores = setup.py: E402 - lib/matplotlib/__init__.py: E402, F401 lib/matplotlib/_animation_data.py: E501 lib/matplotlib/_api/__init__.py: F401 @@ -81,9 +71,6 @@ per-file-ignores = tutorials/text/mathtext.py: E501 tutorials/text/text_intro.py: E402 tutorials/text/text_props.py: E501 - tutorials/text/usetex.py: E501 - tutorials/toolkits/axes_grid.py: E501 - tutorials/toolkits/axisartist.py: E501 examples/animation/frame_grabbing_sgskip.py: E402 examples/images_contours_and_fields/tricontour_demo.py: E201 @@ -93,7 +80,6 @@ per-file-ignores = examples/misc/print_stdout_sgskip.py: E402 examples/misc/table_demo.py: E201 examples/style_sheets/bmh.py: E501 - examples/style_sheets/plot_solarizedlight2.py: E501 examples/subplots_axes_and_figures/demo_constrained_layout.py: E402 examples/text_labels_and_annotations/custom_legends.py: E402 examples/ticks/date_concise_formatter.py: E402 diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index 849644145856..da118ed0b978 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -63,7 +63,6 @@ def __init__(self, xpad=0., ypad=0., update_func=None): """ Parameters ---------- - xpad : float, optional Padding in x-direction. ypad : float, optional diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index e278c7464cc0..e57a9735db80 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -98,7 +98,7 @@ def __init__(self, axis): # constructor docstring, which would otherwise end up interpolated into # the docstring of Axis.set_scale. """ - """ + """ # noqa: D419 def set_default_locators_and_formatters(self, axis): # docstring inherited diff --git a/lib/matplotlib/tests/test_backend_qt.py b/lib/matplotlib/tests/test_backend_qt.py index 64d59b853fb0..cf82b900bf39 100644 --- a/lib/matplotlib/tests/test_backend_qt.py +++ b/lib/matplotlib/tests/test_backend_qt.py @@ -128,7 +128,7 @@ def test_sigint(target, kwargs): try: proc.wait_for('DRAW') stdout, _ = proc.communicate(timeout=_test_timeout) - except: + except Exception: proc.kill() stdout, _ = proc.communicate() raise @@ -182,7 +182,7 @@ def test_other_signal_before_sigint(target, kwargs): proc.wait_for('SIGUSR1') os.kill(proc.pid, signal.SIGINT) stdout, _ = proc.communicate(timeout=_test_timeout) - except: + except Exception: proc.kill() stdout, _ = proc.communicate() raise diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index 3724db1e1b43..966539088e42 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -317,7 +317,7 @@ def test_get_font_names(): font = ft2font.FT2Font(path) prop = ttfFontProperty(font) ttf_fonts.append(prop.name) - except: + except Exception: pass available_fonts = sorted(list(set(ttf_fonts))) mpl_font_names = sorted(fontManager.get_font_names()) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 71cdf3d1ccc5..3afd8f216475 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -91,7 +91,7 @@ class Text3D(mtext.Text): ---------------- **kwargs All other parameters are passed on to `~matplotlib.text.Text`. - """ + """ def __init__(self, x=0, y=0, z=0, text='', zdir='z', **kwargs): mtext.Text.__init__(self, x, y, text, **kwargs) diff --git a/pyproject.toml b/pyproject.toml index 8c51b1556a3b..c8b76f1e61de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,6 @@ requires = [ "setuptools_scm>=7", ] - [tool.isort] known_mpltoolkits = "mpl_toolkits" known_pydata = "numpy, matplotlib.pyplot" @@ -15,3 +14,117 @@ known_firstparty = "matplotlib" sections = "FUTURE,STDLIB,THIRDPARTY,PYDATA,FIRSTPARTY,MPLTOOLKITS,LOCALFOLDER" no_lines_before = "MPLTOOLKITS" force_sort_within_sections = true + +[tool.ruff] +exclude = [ + ".git", + "build", + "doc/gallery", + "doc/tutorials", + "tools/gh_api.py", + ".tox", + ".eggs", +] +ignore = [ + "D100", + "D101", + "D102", + "D103", + "D104", + "D105", + "D106", + "D200", + "D202", + "D204", + "D205", + "D301", + "D400", + "D401", + "D403", + "D404", + "E741", + "F841", +] +line-length = 88 +select = [ + "D", + "E", + "F", + "W", +] + +# The following error codes are not supported by ruff v0.0.240 +# They are planned and should be selected once implemented +# even if they are deselected by default. +# These are primarily whitespace/corrected by autoformatters (which we don't use). +# See https://github.com/charliermarsh/ruff/issues/2402 for status on implementation +external = [ + "E122", + "E201", + "E202", + "E203", + "E221", + "E251", + "E261", + "E272", + "E302", + "E703", +] + +target-version = "py39" + +[tool.ruff.pydocstyle] +convention = "numpy" + +[tool.ruff.per-file-ignores] +"setup.py" = ["E402"] + +"doc/conf.py" = ["E402"] +"examples/animation/frame_grabbing_sgskip.py" = ["E402"] +"examples/lines_bars_and_markers/marker_reference.py" = ["E402"] +"examples/misc/print_stdout_sgskip.py" = ["E402"] +"examples/style_sheets/bmh.py" = ["E501"] +"examples/subplots_axes_and_figures/demo_constrained_layout.py" = ["E402"] +"examples/text_labels_and_annotations/custom_legends.py" = ["E402"] +"examples/ticks/date_concise_formatter.py" = ["E402"] +"examples/ticks/date_formatters_locators.py" = ["F401"] +"examples/user_interfaces/embedding_in_gtk3_panzoom_sgskip.py" = ["E402"] +"examples/user_interfaces/embedding_in_gtk3_sgskip.py" = ["E402"] +"examples/user_interfaces/embedding_in_gtk4_panzoom_sgskip.py" = ["E402"] +"examples/user_interfaces/embedding_in_gtk4_sgskip.py" = ["E402"] +"examples/user_interfaces/gtk3_spreadsheet_sgskip.py" = ["E402"] +"examples/user_interfaces/gtk4_spreadsheet_sgskip.py" = ["E402"] +"examples/user_interfaces/mpl_with_glade3_sgskip.py" = ["E402"] +"examples/user_interfaces/pylab_with_gtk3_sgskip.py" = ["E402"] +"examples/user_interfaces/pylab_with_gtk4_sgskip.py" = ["E402"] +"examples/userdemo/pgf_preamble_sgskip.py" = ["E402"] + +"lib/matplotlib/__init__.py" = ["E402", "F401"] +"lib/matplotlib/_animation_data.py" = ["E501"] +"lib/matplotlib/_api/__init__.py" = ["F401"] +"lib/matplotlib/axes/__init__.py" = ["F401", "F403"] +"lib/matplotlib/backends/backend_template.py" = ["F401"] +"lib/matplotlib/font_manager.py" = ["E501"] +"lib/matplotlib/image.py" = ["F401", "F403"] +"lib/matplotlib/pylab.py" = ["F401", "F403"] +"lib/matplotlib/pyplot.py" = ["F401", "F811"] +"lib/matplotlib/tests/test_mathtext.py" = ["E501"] +"lib/mpl_toolkits/axisartist/__init__.py" = ["F401"] +"lib/pylab.py" = ["F401", "F403"] + +"tutorials/advanced/path_tutorial.py" = ["E402"] +"tutorials/advanced/patheffects_guide.py" = ["E402"] +"tutorials/advanced/transforms_tutorial.py" = ["E402", "E501"] +"tutorials/colors/colormaps.py" = ["E501"] +"tutorials/colors/colors.py" = ["E402"] +"tutorials/intermediate/artists.py" = ["E402"] +"tutorials/intermediate/constrainedlayout_guide.py" = ["E402"] +"tutorials/intermediate/legend_guide.py" = ["E402"] +"tutorials/intermediate/tight_layout_guide.py" = ["E402"] +"tutorials/introductory/animation_tutorial.py" = ["E501"] +"tutorials/introductory/images.py" = ["E501"] +"tutorials/introductory/pyplot.py" = ["E402", "E501"] +"tutorials/text/annotations.py" = ["E402", "E501"] +"tutorials/text/mathtext.py" = ["E501"] +"tutorials/text/text_intro.py" = ["E402"] +"tutorials/text/text_props.py" = ["E501"]