From 6c99bfffdd1d6d25b3856bc53f0b8f44935bc169 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Fri, 16 Aug 2024 08:33:52 +0200 Subject: [PATCH] Run isort, autopep8 and flake8 in pre-commit. --- .github/workflows/pre-commit.yml | 23 +++++++++++++++++++++++ .pre-commit-config.yaml | 21 +++++++++++++++++++-- docs/conf.py | 2 +- src/ZPublisher/BaseRequest.py | 9 ++++----- 4 files changed, 47 insertions(+), 8 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..5c015fd6e7 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,23 @@ +name: pre-commit + +on: + pull_request: + push: + branches: + - master +jobs: + pre-commit: + name: pre-commit linting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --all-files + - uses: pre-commit-ci/lite-action@v1.0.2 + if: always() + with: + msg: Apply pre-commit code formatting diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7ec6849357..92867ce3e6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,23 @@ +minimum_pre_commit_version: '3.6' repos: + - repo: https://github.com/pycqa/isort + rev: "5.13.2" + hooks: + - id: isort + - repo: https://github.com/hhatto/autopep8 + rev: "v2.3.1" + hooks: + - id: autopep8 + args: [--in-place, --aggressive, --aggressive] - repo: https://github.com/asottile/pyupgrade - rev: v2.6.2 + rev: v3.17.0 hooks: - id: pyupgrade - args: [--py36-plus] + args: [--py38-plus] + - repo: https://github.com/PyCQA/flake8 + rev: "6.1.0" + hooks: + - id: flake8 + additional_dependencies: + - flake8-coding == 1.3.2 + - flake8-debugger == 4.1.2 diff --git a/docs/conf.py b/docs/conf.py index c328eb69ba..4919c1fda0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -100,7 +100,7 @@ "light_logo": "Zope.svg", "dark_logo": "Zope.svg", "light_css_variables": { -# "color-brand-content": "#00AAD4", # Too light for white background + # "color-brand-content": "#00AAD4", # Too light for white background }, "dark_css_variables": { "color-brand-content": "#00AAD4", diff --git a/src/ZPublisher/BaseRequest.py b/src/ZPublisher/BaseRequest.py index 3158ba3267..2bc65ddf4d 100644 --- a/src/ZPublisher/BaseRequest.py +++ b/src/ZPublisher/BaseRequest.py @@ -710,11 +710,10 @@ def ensure_publishable(self, obj, for_call=False): # a tuple of allowed request methods request_method = (getattr(self, "environ", None) and self.environ.get("REQUEST_METHOD")) - if (request_method is None # noqa: E271 - or request_method.upper() not in publishable): - raise Forbidden( - f"The object at {url} does not support " - f"{request_method} requests") + if (request_method is None # noqa: E271 + or request_method.upper() not in publishable): + raise Forbidden(f"The object at {url} does not support " + f"{request_method} requests") return # ``publishable`` is ``None``