From 24c4d9835a4471c56ed7698bbe6d4c0b17aacb9f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Jul 2023 23:03:23 +0200 Subject: [PATCH] DX!: switch to Ruff as linter (#28) * MAINT: apply Ruff autofixes * MAINT: autoupdate pre-commit hooks * MAINT: implement updates from pre-commit hooks * MAINT: remove pylint ignore comments --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: GitHub Co-authored-by: Remco de Boer <29308176+redeboer@users.noreply.github.com> --- .cspell.json | 5 +- .flake8 | 32 ------ .github/workflows/ci.yml | 2 +- .gitpod.yml | 6 +- .mypy.ini | 19 ---- .pre-commit-config.yaml | 54 +++------- .pydocstyle | 11 -- .pylintrc | 33 ------ .vscode/extensions.json | 13 ++- .vscode/settings.json | 15 ++- README.md | 2 +- pyproject.toml | 140 +++++++++++++++++++++++++- pyrightconfig.json | 25 ----- pytest.ini | 19 ---- setup.cfg | 17 +--- setup.py | 1 - src/sphinxcontrib/hep/pdgref/entry.py | 8 +- src/sphinxcontrib/hep/pdgref/role.py | 17 ++-- src/sphinxcontrib/hep/pdgref/url.py | 13 ++- tests/.pydocstyle | 4 - tests/conftest.py | 2 +- tests/test_entry.py | 2 +- 22 files changed, 198 insertions(+), 242 deletions(-) delete mode 100644 .flake8 delete mode 100644 .mypy.ini delete mode 100644 .pydocstyle delete mode 100644 .pylintrc delete mode 100644 pyrightconfig.json delete mode 100644 pytest.ini delete mode 100644 tests/.pydocstyle diff --git a/.cspell.json b/.cspell.json index b621e9a..5ca40a3 100644 --- a/.cspell.json +++ b/.cspell.json @@ -24,14 +24,11 @@ "*particle*.*ml", ".constraints/*.txt", ".editorconfig", - ".flake8*", ".gitignore", ".gitpod.*", ".mypy.ini", ".pre-commit-config.yaml", ".prettierignore", - ".pydocstyle*", - ".pylintrc", ".readthedocs.yml", ".vscode/*", ".vscode/.gitignore", @@ -55,7 +52,7 @@ "typings" ], "language": "en-US", - "words": ["ComPWA", "conda", "doctests", "pdgref", "pylint", "pytest"], + "words": ["ComPWA", "conda", "doctests", "pdgref", "pytest"], "ignoreWords": [ "MAINT", "PYTHONHASHSEED", diff --git a/.flake8 b/.flake8 deleted file mode 100644 index dc3aac1..0000000 --- a/.flake8 +++ /dev/null @@ -1,32 +0,0 @@ -[flake8] -application-import-names = - sphinxcontrib -filename = - ./docs/*.py - ./src/*.py - ./tests/*.py -exclude = - **/__pycache__ - **/_build - /typings/** -ignore = - # https://github.com/psf/black#slices - E203 - # allowed by black - E231 - # https://github.com/psf/black#line-length - E501 - # block quote ends without a blank line (black formatting) - RST201 - # missing pygments - RST299 - # unexpected indentation (related to google style docstring) - RST301 - # enforce type ignore with mypy error codes (combined --extend-select=TI100) - TI1 - # https://github.com/psf/black#line-breaks--binary-operators - W503 -extend-select = - TI100 -rst-roles = - file, diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0b8cd4..b0d07fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: uses: ComPWA/actions/.github/workflows/pytest.yml@v1 with: coverage-target: sphinxcontrib - macos-python-version: "3.7" + macos-python-version: "3.9" specific-pip-packages: ${{ inputs.specific-pip-packages }} style: if: inputs.specific-pip-packages == '' diff --git a/.gitpod.yml b/.gitpod.yml index 192bd10..2b60651 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -13,15 +13,15 @@ github: vscode: extensions: + - charliermarsh.ruff - christian-kohler.path-intellisense - davidanson.vscode-markdownlint - eamodio.gitlens - editorconfig.editorconfig - esbenp.prettier-vscode + - garaioag.garaio-vscode-unwanted-recommendations - github.vscode-github-actions - - ms-python.flake8 - - ms-python.isort - - ms-python.pylint + - ms-python.mypy-type-checker - ms-python.python - ms-python.vscode-pylance - redhat.vscode-yaml diff --git a/.mypy.ini b/.mypy.ini deleted file mode 100644 index a42d332..0000000 --- a/.mypy.ini +++ /dev/null @@ -1,19 +0,0 @@ -[mypy] -disallow_incomplete_defs = True -disallow_untyped_defs = True -show_error_codes = True -warn_unused_configs = True -files = - **/*.py, - **/*.pyi, - -[mypy-tests.*] -check_untyped_defs = True -disallow_incomplete_defs = False -disallow_untyped_defs = False -[mypy-typings.*] -ignore_errors = True - -; External packages that miss stubs or type hints -[mypy-pyquery.*] -ignore_missing_imports = True diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 925157c..2216901 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,9 +2,7 @@ ci: autoupdate_commit_msg: "MAINT: autoupdate pre-commit hooks" autoupdate_schedule: quarterly # already done by requirements-cron.yml skip: - - flake8 - mypy - - pylint - pyright - taplo @@ -43,7 +41,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/ComPWA/repo-maintenance - rev: 0.0.179 + rev: 0.0.192 hooks: - id: check-dev-files args: @@ -57,7 +55,7 @@ repos: - id: black - repo: https://github.com/asottile/blacken-docs - rev: 1.13.0 + rev: 1.15.0 hooks: - id: blacken-docs @@ -67,7 +65,7 @@ repos: - id: cspell - repo: https://github.com/editorconfig-checker/editorconfig-checker.python - rev: 2.7.1 + rev: 2.7.2 hooks: - id: editorconfig-checker name: editorconfig @@ -77,22 +75,8 @@ repos: .*\.py )$ - - repo: local - hooks: - - id: flake8 - name: flake8 - entry: flake8 - language: system - types: - - python - - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.33.0 + rev: v0.35.0 hooks: - id: markdownlint @@ -106,39 +90,29 @@ repos: - python - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.0-alpha.6 + rev: v3.0.0 hooks: - id: prettier - - repo: https://github.com/pycqa/pydocstyle - rev: 6.3.0 - hooks: - - id: pydocstyle - - - repo: local - hooks: - - id: pylint - name: pylint - entry: pylint - args: - - --rcfile=.pylintrc - - --score=no - language: system - types: - - python - - repo: https://github.com/ComPWA/mirrors-pyright - rev: v1.1.303 + rev: v1.1.316 hooks: - id: pyright - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 + rev: v3.9.0 hooks: - id: pyupgrade args: - --py36-plus + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.277 + hooks: + - id: ruff + args: + - --fix + - repo: https://github.com/ComPWA/mirrors-taplo rev: v0.8.0 hooks: diff --git a/.pydocstyle b/.pydocstyle deleted file mode 100644 index 285e8c5..0000000 --- a/.pydocstyle +++ /dev/null @@ -1,11 +0,0 @@ -[pydocstyle] -convention = google -add_ignore = - D101, # class docstring - D102, # method docstring - D103, # function docstring - D105, # magic method docstring - D107, # init docstring - D203, # conflicts with D211 - D213, # multi-line docstring should start at the second line - D407, # missing dashed underline after section diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index ac27303..0000000 --- a/.pylintrc +++ /dev/null @@ -1,33 +0,0 @@ -# To see other available options: -# pylint --generate-rcfile > .pylintrc_new -# and compare the output - -[VARIABLES] -init-import=yes - -[MESSAGES CONTROL] -disable= - C0114, # done by pydocstyle - C0115, # done by pydocstyle - C0116, # done by pydocstyle - R0801, # similar lines # https://github.com/PyCQA/pylint/issues/214 - import-error, # handled by pyright - logging-fstring-interpolation, - no-name-in-module, # handled by pyright - not-callable, - unused-import, # https://www.flake8rules.com/rules/F401 - -[MASTER] -ignore= - conf.py -ignore-patterns= - .*\.pyi - -[DESIGN] -# Minimum number of public methods for a class (see R0903). Default is 2. -# We decrease this to 0, since some rules are "empty" but get decorated. -# Note that some interface classes also just have a single method -min-public-methods=0 - -[SIMILARITIES] -ignore-imports=yes # https://stackoverflow.com/a/30007053 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index a236bcb..d8a39b7 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,14 +1,14 @@ { "recommendations": [ + "charliermarsh.ruff", "christian-kohler.path-intellisense", "davidanson.vscode-markdownlint", "eamodio.gitlens", "editorconfig.editorconfig", "esbenp.prettier-vscode", + "garaioag.garaio-vscode-unwanted-recommendations", "github.vscode-github-actions", - "ms-python.flake8", - "ms-python.isort", - "ms-python.pylint", + "ms-python.mypy-type-checker", "ms-python.python", "ms-python.vscode-pylance", "redhat.vscode-yaml", @@ -18,5 +18,12 @@ "tamasfe.even-better-toml", "tyriar.sort-lines", "yzhang.markdown-all-in-one" + ], + "unwantedRecommendations": [ + "bungcip.better-toml", + "ms-python.flake8", + "ms-python.isort", + "ms-python.pylint", + "travisillig.vscode-json-stable-stringify" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 3d65835..4168a87 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,11 +23,11 @@ "[yaml]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, - "cSpell.enabled": true, "coverage-gutters.coverageFileNames": ["coverage.xml"], "coverage-gutters.coverageReportFileName": "**/htmlcov/index.html", "coverage-gutters.showGutterCoverage": false, "coverage-gutters.showLineCoverage": true, + "cSpell.enabled": true, "editor.formatOnSave": true, "editor.rulers": [88], "files.watcherExclude": { @@ -36,29 +36,28 @@ "**/.git/**": true, "**/.tox/**": true }, - "flake8.importStrategy": "fromEnvironment", "git.rebaseWhenSync": true, "github-actions.workflows.pinned.refresh.enabled": true, "github-actions.workflows.pinned.workflows": [".github/workflows/ci.yml"], - "isort.check": true, - "isort.importStrategy": "fromEnvironment", - "pylint.importStrategy": "fromEnvironment", + "mypy-type-checker.args": ["--config-file", "pyproject.toml"], + "mypy-type-checker.importStrategy": "fromEnvironment", "python.analysis.autoImportCompletions": false, - "python.analysis.diagnosticMode": "workspace", "python.analysis.inlayHints.pytestParameters": true, "python.analysis.typeCheckingMode": "strict", "python.formatting.provider": "black", "python.linting.banditEnabled": false, "python.linting.enabled": true, "python.linting.flake8Enabled": false, - "python.linting.mypyEnabled": true, - "python.linting.pydocstyleEnabled": true, + "python.linting.mypyEnabled": false, + "python.linting.pydocstyleEnabled": false, "python.linting.pylamaEnabled": false, "python.linting.pylintEnabled": false, "python.testing.pytestArgs": ["--color=no", "--no-cov"], "python.testing.pytestEnabled": true, "python.testing.unittestEnabled": false, "rewrap.wrappingColumn": 88, + "ruff.enable": true, + "ruff.organizeImports": true, "search.exclude": { "**/tests/**/__init__.py": true, "*/.pydocstyle": true, diff --git a/README.md b/README.md index d07560e..739f959 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [![Spelling checked](https://img.shields.io/badge/cspell-checked-brightgreen.svg)](https://github.com/streetsidesoftware/cspell/tree/master/packages/cspell) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) -[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort) +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) This package is a [Sphinx extension](https://www.sphinx-doc.org/en/master/usage/extensions/index.html) diff --git a/pyproject.toml b/pyproject.toml index 2ff7e9b..cf07dec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,140 @@ target-version = [ 'py39', ] -[tool.isort] -profile = "black" -src_paths = ["src", "tests"] +[tool.coverage.run] +branch = true +source = ["src"] + + +[tool.mypy] +disallow_incomplete_defs = true +disallow_untyped_defs = true +files = [ + "**/*.py", + "**/*.pyi", +] +show_error_codes = true +warn_unused_configs = true + +[[tool.mypy.overrides]] +check_untyped_defs = true +disallow_incomplete_defs = false +disallow_untyped_defs = false +module = ["tests.*"] + +[[tool.mypy.overrides]] +ignore_errors = true +module = ["typings.*"] + +[[tool.mypy.overrides]] +ignore_missing_imports = true +module = ["pyquery.*"] + +[tool.pyright] +exclude = [ + "**/.git", + "**/.ipynb_checkpoints", + "**/.mypy_cache", + "**/.pytest_cache", + "**/.tox", + "**/__pycache__", + "**/_build", +] +reportGeneralTypeIssues = false +reportMissingImports = false +reportMissingParameterType = false +reportMissingTypeArgument = false +reportUnboundVariable = false +reportUnknownArgumentType = false +reportUnknownMemberType = false +reportUnknownParameterType = false +reportUnknownVariableType = false +reportUnusedClass = true +reportUnusedFunction = true +reportUnusedImport = true +reportUnusedVariable = true +typeCheckingMode = "strict" + +[tool.pytest.ini_options] +addopts = """ +--color=yes +--doctest-continue-on-failure +--doctest-modules +--durations=3""" +filterwarnings = [ + "error", + "ignore:'imghdr' is deprecated and slated for removal in Python 3.13:DeprecationWarning", + "ignore:The distutils package is deprecated.*:DeprecationWarning", +] +markers = ["slow: marks tests as slow (deselect with '-m \"not slow\"')"] +testpaths = [ + "src", + "tests", +] + +[tool.ruff] +extend-select = [ + "A", + "B", + "BLE", + "C4", + "C90", + "D", + "EM", + "ERA", + "I", + "ICN", + "INP", + "ISC", + "N", + "NPY", + "PGH", + "PIE", + "PL", + "Q", + "RET", + "RSE", + "RUF", + "S", + "SIM", + "T20", + "TCH", + "TID", + "TRY", + "UP", + "YTT", +] +ignore = [ + "D101", + "D102", + "D103", + "D105", + "D107", + "D203", + "D213", + "D407", + "D416", + "E501", + "SIM108", +] +show-fixes = true +src = [ + "src", + "tests", +] +target-version = "py37" +task-tags = ["cspell"] + +[tool.ruff.per-file-ignores] +"setup.py" = ["D100"] +"tests/*" = [ + "D", + "INP001", + "PGH001", + "PLR0913", + "PLR2004", + "S101", +] + +[tool.ruff.pydocstyle] +convention = "google" diff --git a/pyrightconfig.json b/pyrightconfig.json deleted file mode 100644 index fe72235..0000000 --- a/pyrightconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "exclude": [ - "**/__pycache__", - "**/_build", - "**/.git", - "**/.ipynb_checkpoints", - "**/.mypy_cache", - "**/.pytest_cache", - "**/.tox" - ], - "reportGeneralTypeIssues": false, - "reportMissingImports": false, - "reportMissingParameterType": false, - "reportMissingTypeArgument": false, - "reportUnboundVariable": false, - "reportUnknownArgumentType": false, - "reportUnknownMemberType": false, - "reportUnknownParameterType": false, - "reportUnknownVariableType": false, - "reportUnusedClass": true, - "reportUnusedFunction": true, - "reportUnusedImport": true, - "reportUnusedVariable": true, - "typeCheckingMode": "strict" -} diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 31d8d1f..0000000 --- a/pytest.ini +++ /dev/null @@ -1,19 +0,0 @@ -[coverage:run] -branch = True -source = src - -[pytest] -addopts = - --color=yes - --doctest-continue-on-failure - --doctest-modules - --durations=3 -filterwarnings = - error - ignore:'imghdr' is deprecated and slated for removal in Python 3.13:DeprecationWarning - ignore:The distutils package is deprecated.*:DeprecationWarning -markers = - slow: marks tests as slow (deselect with '-m "not slow"') -testpaths = - src - tests diff --git a/setup.cfg b/setup.cfg index 1511558..f587c78 100644 --- a/setup.cfg +++ b/setup.cfg @@ -57,28 +57,13 @@ test = pytest-xdist format = black - isort -flake8 = - flake8 >=4 # extend-select - flake8-blind-except - flake8-bugbear - flake8-builtins - flake8-comprehensions - flake8-pytest-style - flake8-rst-docstrings - flake8-type-ignore; python_version >="3.8.0" - flake8-use-fstring - pep8-naming mypy = mypy >=0.730 # attrs and error code support types-docutils types-setuptools lint = - %(flake8)s %(mypy)s - pep8-naming - pydocstyle - pylint + ruff sty = pre-commit >=1.4.0 %(format)s diff --git a/setup.py b/setup.py index 2e57703..9329697 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -# noqa: D100 from setuptools import setup setup( diff --git a/src/sphinxcontrib/hep/pdgref/entry.py b/src/sphinxcontrib/hep/pdgref/entry.py index 7d99efb..75087da 100644 --- a/src/sphinxcontrib/hep/pdgref/entry.py +++ b/src/sphinxcontrib/hep/pdgref/entry.py @@ -47,8 +47,9 @@ def from_str(text: str) -> "PDGEntry": PDGEntry(section='Resonances', year=2020, pages=None) """ segments = text.split(";") - if len(segments) > 3: - raise ValueError(f'Input string "{text}" contains more than 3 segments') + if len(segments) > 3: # noqa: PLR2004 + msg = f'Input string "{text}" contains more than 3 segments' + raise ValueError(msg) section = text year = DEFAULT_YEAR pages = None @@ -69,7 +70,8 @@ def get_first_page(text: str) -> int: text = text.strip() matches = re.match(r"p?p?\.?\s*(\d+).*", text) if matches is None: - raise ValueError(f'Badly formatted page numbers "{text}"') + msg = f'Badly formatted page numbers "{text}"' + raise ValueError(msg) first_page_nr = matches.group(1) return int(first_page_nr) diff --git a/src/sphinxcontrib/hep/pdgref/role.py b/src/sphinxcontrib/hep/pdgref/role.py index ca0e4f0..2ca5981 100644 --- a/src/sphinxcontrib/hep/pdgref/role.py +++ b/src/sphinxcontrib/hep/pdgref/role.py @@ -12,7 +12,7 @@ def pdgref(pattern: URLPattern) -> RoleFunction: - def role( # pylint: disable=too-many-arguments, unused-argument + def role( # noqa: PLR0913 name: str, rawtext: str, text: str, @@ -25,15 +25,14 @@ def role( # pylint: disable=too-many-arguments, unused-argument pdg_entry = PDGEntry.from_str(text) link_text = create_link_text(pdg_entry, pattern=pattern) url = create_url(pdg_entry, pattern=pattern) - except ValueError: - raise ValueError( # pylint: disable=raise-missing-from - "Badly formatted argument:\n" - f" {rawtext}\n" - "This role requires at most 3 semicolon-separated arguments:" - " section; [year; [page number(s)]]" - ' with page numbers something like "p12", or "pp. 12-15, 17".' - " The order does not matter" + except ValueError as e: + msg = ( + f"Badly formatted argument:\n {rawtext}\nThis role requires at most 3" + " semicolon-separated arguments: section; [year; [page number(s)]]" + ' with page numbers something like "p12", or "pp. 12-15, 17". The' + " order does not matter" ) + raise ValueError(msg) from e if options is None: options = {} # cspell:ignore refuri diff --git a/src/sphinxcontrib/hep/pdgref/url.py b/src/sphinxcontrib/hep/pdgref/url.py index c1e270e..84159f5 100644 --- a/src/sphinxcontrib/hep/pdgref/url.py +++ b/src/sphinxcontrib/hep/pdgref/url.py @@ -12,8 +12,8 @@ class URLPattern(str, Enum): - LISTING = "https://pdg.lbl.gov/{0}/listings/rpp{0}-list-{1}.pdf" # noqa: FS003 - REVIEW = "https://pdg.lbl.gov/{0}/reviews/rpp{0}-rev-{1}.pdf" # noqa: FS003 + LISTING = "https://pdg.lbl.gov/{0}/listings/rpp{0}-list-{1}.pdf" + REVIEW = "https://pdg.lbl.gov/{0}/reviews/rpp{0}-rev-{1}.pdf" def create_url(entry: PDGEntry, *, pattern: URLPattern) -> str: @@ -22,9 +22,11 @@ def create_url(entry: PDGEntry, *, pattern: URLPattern) -> str: elif pattern == URLPattern.REVIEW: url = _create_review_url(entry) else: - raise NotImplementedError(f"No implementation for {pattern}") + msg = f"No implementation for {pattern}" + raise NotImplementedError(msg) if " " in url or "," in url: - raise ValueError("URL cannot contain spaces or commas") + msg = "URL cannot contain spaces or commas" + raise ValueError(msg) return url @@ -54,7 +56,8 @@ def create_link_text(entry: PDGEntry, *, pattern: URLPattern) -> str: return _create_short_link_text(entry) if pattern == URLPattern.REVIEW: return _create_extended_link_text(entry) - raise NotImplementedError(f"No implementation for {pattern}") + msg = f"No implementation for {pattern}" + raise NotImplementedError(msg) def _create_extended_link_text(entry: PDGEntry) -> str: diff --git a/tests/.pydocstyle b/tests/.pydocstyle deleted file mode 100644 index 26d0703..0000000 --- a/tests/.pydocstyle +++ /dev/null @@ -1,4 +0,0 @@ -; ignore all pydocstyle errors in this folder - -[pydocstyle] -add_ignore = D diff --git a/tests/conftest.py b/tests/conftest.py index 32791b3..62c0662 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,7 @@ import pytest from sphinx.testing.path import path -pytest_plugins = "sphinx.testing.fixtures" # pylint: disable=invalid-name +pytest_plugins = "sphinx.testing.fixtures" collect_ignore = ["roots"] diff --git a/tests/test_entry.py b/tests/test_entry.py index a764d7b..c5c4afc 100644 --- a/tests/test_entry.py +++ b/tests/test_entry.py @@ -48,7 +48,7 @@ def test_from_str( entry = PDGEntry.from_str(text) assert entry == expected assert entry.first_page == first_page - from_eval = eval(str(entry)) # pylint: disable=eval-used + from_eval = eval(str(entry)) # noqa: S307 assert entry == from_eval