From 813b906d401b4ad3fbc4f059945314f827a1223a Mon Sep 17 00:00:00 2001 From: Steffen Allner Date: Thu, 21 Sep 2023 14:28:11 +0200 Subject: [PATCH] Move all linters to pre-commit. --- .github/workflows/pre-commit.yml | 16 +++++++++++ .github/workflows/tests.yml | 3 --- .pre-commit-config.yaml | 33 ++++++++++++++++++++++- src/OFS/DTMLDocument.py | 2 ++ src/Shared/DC/Scripts/Signature.py | 5 +++- src/ZPublisher/HTTPRequest.py | 8 +++--- tox.ini | 43 +----------------------------- 7 files changed, 59 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000000..ed54875801 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,16 @@ +on: + pull_request: + push: + branches: [master] + +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - uses: pre-commit/action@v3.0.0 + - uses: pre-commit-ci/lite-action@v1.0.1 + if: always() diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dffa2b81f2..307c33fc23 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,7 +22,6 @@ jobs: - ["macos", "macos-11"] config: # [Python version, tox env] - - ["3.9", "lint"] - ["3.7", "py37"] - ["3.8", "py38"] - ["3.9", "py39"] @@ -32,10 +31,8 @@ jobs: - ["3.9", "docs"] - ["3.9", "coverage"] exclude: - - { os: ["windows", "windows-latest"], config: ["3.9", "lint"] } - { os: ["windows", "windows-latest"], config: ["3.9", "docs"] } - { os: ["windows", "windows-latest"], config: ["3.9", "coverage"] } - - { os: ["macos", "macos-11"], config: ["3.9", "lint"] } - { os: ["macos", "macos-11"], config: ["3.9", "docs"] } - { os: ["macos", "macos-11"], config: ["3.9", "coverage"] } # macOS/Python 3.11+ is set up for universal2 architecture diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7ec6849357..2089cb479d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,37 @@ +ci: + autofix_prs: true + repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.6.2 + rev: "v2.6.2" hooks: - id: pyupgrade args: [--py36-plus] + - repo: https://github.com/pycqa/isort + rev: "5.12.0" + hooks: + - id: isort + - repo: https://github.com/PyCQA/docformatter + rev: "v1.7.5" + hooks: + - id: docformatter + - repo: https://github.com/pre-commit/mirrors-autopep8 + rev: "v2.0.2" + hooks: + - id: autopep8 + args: [--in-place, --aggressive, --aggressive] + - repo: https://github.com/PyCQA/flake8 + rev: "6.1.0" + hooks: + - id: flake8 + additional_dependencies: + - flake8-coding + - flake8-debugger + - repo: https://github.com/mgedmin/check-manifest + rev: "0.49" + hooks: + - id: check-manifest + - repo: https://github.com/mgedmin/check-python-versions + rev: "0.21.3" + hooks: + - id: check-python-versions diff --git a/src/OFS/DTMLDocument.py b/src/OFS/DTMLDocument.py index cb0eab113f..6290ef2555 100644 --- a/src/OFS/DTMLDocument.py +++ b/src/OFS/DTMLDocument.py @@ -48,8 +48,10 @@ class DTMLDocument(PropertyManager, DTMLMethod): # Replace change_dtml_methods by change_dtml_documents __ac_permissions__ = tuple([ + # fmt: off (perms[0] == change_dtml_methods) and # NOQA: W504 (change_dtml_documents, perms[1]) or perms + # fmt: on for perms in DTMLMethod.__ac_permissions__]) def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): diff --git a/src/Shared/DC/Scripts/Signature.py b/src/Shared/DC/Scripts/Signature.py index af0d81b829..c64b68c77b 100644 --- a/src/Shared/DC/Scripts/Signature.py +++ b/src/Shared/DC/Scripts/Signature.py @@ -32,15 +32,18 @@ def __init__(self, varnames=(), argcount=-1): def __eq__(self, other): if not isinstance(other, FuncCode): return False + # fmt: off return ((self.co_argcount, self.co_varnames) == # NOQA: W504 (other.co_argcount, other.co_varnames)) + # fmt: on def __lt__(self, other): if not isinstance(other, FuncCode): return False + # fmt: off return ((self.co_argcount, self.co_varnames) < # NOQA: W504 (other.co_argcount, other.co_varnames)) - + # fmt: on def _setFuncSignature(self, defaults=None, varnames=(), argcount=-1): # This is meant to be imported directly into a class. diff --git a/src/ZPublisher/HTTPRequest.py b/src/ZPublisher/HTTPRequest.py index 20421a14b5..bfc9de01e6 100644 --- a/src/ZPublisher/HTTPRequest.py +++ b/src/ZPublisher/HTTPRequest.py @@ -465,16 +465,16 @@ def processInputs( hasattr=hasattr, getattr=getattr, setattr=setattr): - """Process request inputs + """Process request inputs. - See the `Zope Developer Guide Object Publishing chapter - `_ + See the + `Zope Developer Guide Object Publishing chapter `_ for a detailed explanation in the section `Marshalling Arguments from the Request`. We need to delay input parsing so that it is done under publisher control for error handling purposes. - """ + """ # noqa: E501 response = self.response environ = self.environ method = environ.get('REQUEST_METHOD', 'GET') diff --git a/tox.ini b/tox.ini index 0e004349e7..98eeac6bd1 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,6 @@ [tox] minversion = 3.18 envlist = - lint py37 py38 py39 @@ -39,47 +38,7 @@ deps = pre-commit commands_pre = commands = - pre-commit run --all-files --show-diff-on-failure - -[testenv:autopep8] -basepython = python3.8 -skip_install = true -deps = - -cconstraints.txt - autopep8 - docformatter -commands = - autopep8 --verbose --in-place --recursive --aggressive --aggressive {toxinidir}/src setup.py - docformatter --in-place --recursive {toxinidir}/src setup.py - -[testenv:lint] -basepython = python3 -commands_pre = - mkdir -p {toxinidir}/parts/flake8 -allowlist_externals = - mkdir -commands = - isort --check-only --diff {toxinidir}/src {toxinidir}/setup.py - flake8 {toxinidir}/src {toxinidir}/setup.py - check-manifest - check-python-versions -deps = - check-manifest - check-python-versions - flake8 - isort - # Useful flake8 plugins that are Python and Plone specific: - flake8-coding - flake8-debugger - mccabe - -[testenv:isort-apply] -basepython = python3 -commands_pre = -deps = - isort -commands = - isort {toxinidir}/src {toxinidir}/setup.py [] + pre-commit run {posargs} --all-files [testenv:docs] basepython = python3