Skip to content
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

Run isort, autopep8 and flake8 in pre-commit. #1224

Merged
merged 5 commits into from
Aug 20, 2024
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
33 changes: 33 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/zope-product
name: pre-commit

on:
pull_request:
push:
branches:
- master
# Allow to run this workflow manually from the Actions tab
workflow_dispatch:

env:
FORCE_COLOR: 1

jobs:
pre-commit:
name: linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- uses: pre-commit/[email protected]
with:
extra_args: --all-files --show-diff-on-failure
env:
PRE_COMMIT_COLOR: always
- uses: pre-commit-ci/[email protected]
if: always()
with:
msg: Apply pre-commit code formatting
3 changes: 0 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
config:
# [Python version, tox env]
- ["3.11", "release-check"]
- ["3.11", "lint"]
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.10", "py310"]
Expand All @@ -34,11 +33,9 @@ jobs:
- ["3.11", "coverage"]
exclude:
- { os: ["windows", "windows-latest"], config: ["3.11", "release-check"] }
- { os: ["windows", "windows-latest"], config: ["3.11", "lint"] }
- { os: ["windows", "windows-latest"], config: ["3.11", "docs"] }
- { os: ["windows", "windows-latest"], config: ["3.11", "coverage"] }
- { os: ["macos", "macos-latest"], config: ["3.11", "release-check"] }
- { os: ["macos", "macos-latest"], config: ["3.11", "lint"] }
- { os: ["macos", "macos-latest"], config: ["3.11", "docs"] }
- { os: ["macos", "macos-latest"], config: ["3.11", "coverage"] }

Expand Down
26 changes: 1 addition & 25 deletions .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/zopefoundation/meta/tree/master/config/zope-product
[meta]
template = "zope-product"
commit-id = "994c74d7"
commit-id = "da0ad14b"

[python]
with-pypy = false
Expand Down Expand Up @@ -47,9 +47,6 @@ testenv-deps = [
"universal2: MarkupSafe",
"universal2: zope.testrunner",
]
additional-envlist = [
"pre-commit",
]
testenv-commands-pre = [
"{envbindir}/buildout -c {toxinidir}/buildout.cfg buildout:directory={envdir} buildout:develop={toxinidir} buildout:root-directory={toxinidir}",
]
Expand All @@ -64,27 +61,6 @@ testenv-commands = [
coverage-command = "coverage run {envdir}/bin/alltests {posargs:-vc}"
testenv-additional = [
"allowlist_externals = *",
"",
"[testenv:pre-commit]",
"basepython = python3",
"description = This env runs all linters configured in .pre-commit-config.yaml",
"skip_install = true",
"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",
]
use-flake8 = true

Expand Down
22 changes: 20 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/zope-product
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: "7.1.1"
hooks:
- id: flake8
additional_dependencies:
- flake8-debugger == 4.1.2
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include *.rst
include *.txt
include buildout.cfg
include tox.ini
include .pre-commit-config.yaml

recursive-include docs *.py
recursive-include docs *.rst
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/App/Dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
class MessageDialogHTML(HTML):
"""A special version of HTML which is always published as text/html
"""

def __call__(self, *args, **kw):
class _HTMLString(str):
"""A special string that will be published as text/html
"""

def asHTML(self):
return self
return _HTMLString(super().__call__(*args, **kw))
Expand Down
1 change: 1 addition & 0 deletions src/App/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class DefaultConfiguration:
"""
This configuration should be used effectively only during unit tests
"""

def __init__(self):
from App import FindHomes
self.clienthome = FindHomes.CLIENT_HOME
Expand Down
1 change: 1 addition & 0 deletions src/App/tests/test_ProductContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def _verify_reg(self, name, obj):

class _Product:
"""Product mockup."""

def __init__(self):
self.id = "pid"

Expand Down
4 changes: 2 additions & 2 deletions src/OFS/DTMLDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class DTMLDocument(PropertyManager, DTMLMethod):

# Replace change_dtml_methods by change_dtml_documents
__ac_permissions__ = tuple([
(perms[0] == change_dtml_methods) and # NOQA: W504
(change_dtml_documents, perms[1]) or perms
(perms[0] == change_dtml_methods) # NOQA: W504
and (change_dtml_documents, perms[1]) or perms
for perms in DTMLMethod.__ac_permissions__])

def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
Expand Down
1 change: 1 addition & 0 deletions src/OFS/absoluteurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def _isVirtualHostRoot(self):
class RootAbsoluteURL(OFSTraversableAbsoluteURL):
"""An absolute_url adapter for the root object (OFS.Application)
"""

def breadcrumbs(self):
context = self.context

Expand Down
1 change: 1 addition & 0 deletions src/OFS/tests/testHistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def test_manage_historicalComparison(self):
class HistoryItemWithSetState(HistoryItem):
"""A class with a data migration on __setstate__
"""

def __setstate__(self, state):
super().__setstate__(state)
self.changed_something = True
Expand Down
1 change: 1 addition & 0 deletions src/OFS/tests/testObjectManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ def test_export_import(self):

class _CallResult:
"""Auxiliary class to provide defined call results."""

def __init__(self, result):
self.result = result

Expand Down
6 changes: 6 additions & 0 deletions src/OFS/tests/testTraverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class UnitTestSecurityPolicy:
Stub out the existing security policy for unit testing purposes.
"""
# Standard SecurityPolicy interface

def validate(self, accessed=None, container=None, name=None, value=None,
context=None, roles=None, *args, **kw):
return 1
Expand All @@ -33,6 +34,7 @@ class CruelSecurityPolicy:
"""Denies everything
"""
# Standard SecurityPolicy interface

def validate(self, accessed, container, name, value, *args):
from AccessControl import Unauthorized
raise Unauthorized(name)
Expand All @@ -44,6 +46,7 @@ def checkPermission(self, permission, object, context):
class ProtectedMethodSecurityPolicy:
"""Check security strictly on bound methods.
"""

def validate(self, accessed, container, name, value, *args):
from AccessControl import Unauthorized
from Acquisition import aq_base
Expand Down Expand Up @@ -135,6 +138,7 @@ class UnitTestUser(Implicit):
"""
Stubbed out manager for unit testing purposes.
"""

def getId(self):
return 'unit_tester'
getUserName = getId
Expand Down Expand Up @@ -192,10 +196,12 @@ class Restricted(SimpleItem):
"""Instance we'll check with ProtectedMethodSecurityPolicy."""

getId__roles__ = None # ACCESS_PUBLIC

def getId(self): # NOQA: E306 # pseudo decorator
return self.id

private__roles__ = () # ACCESS_PRIVATE

def private(self): # NOQA: E306 # pseudo decorator
return 'private!'

Expand Down
1 change: 1 addition & 0 deletions src/Products/Five/browser/pagetemplatefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def getEngine():
class ViewPageTemplateFile(TrustedAppPT, PageTemplateFile):
"""Page Template used as class variable of views defined as Python classes.
"""

def __init__(self, filename, _prefix=None, content_type=None):
_prefix = self.get_path_from_prefix(_prefix)
super().__init__(filename, _prefix)
Expand Down
1 change: 1 addition & 0 deletions src/Products/Five/browser/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Resource:
thus making this mixin (and probably the other classes in this
module) obsolete.
"""

def __call__(self):
name = self.__name__
container = self.__parent__
Expand Down
1 change: 1 addition & 0 deletions src/Products/Five/tests/testing/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class NoVerifyPasteFolder(Folder):
"""Folder that does not perform paste verification.
Used by test_events
"""

def _verifyObjectPaste(self, object, validate_src=1):
pass

Expand Down
1 change: 1 addition & 0 deletions src/Products/Five/viewlet/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class UnitTestSecurityPolicy:
Stub out the existing security policy for unit testing purposes.
"""
# Standard SecurityPolicy interface

def validate(self,
accessed=None,
container=None,
Expand Down
1 change: 1 addition & 0 deletions src/Products/PageTemplates/Expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class _CombinedMapping:

Earlier mappings take precedence.
"""

def __init__(self, *ms):
self.mappings = ms

Expand Down
3 changes: 3 additions & 0 deletions src/Products/PageTemplates/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __call__(self, key, iterable):

class RepeatItem(PathIterator):
"""Iterator compatible with ``chameleon`` and ``zope.tales``."""

def __iter__(self):
return self

Expand Down Expand Up @@ -241,6 +242,7 @@ def _C2ZContextWrapper(c_context, attrs):

class MappedExpr:
"""map expression: ``zope.tales`` --> ``chameleon.tales``."""

def __init__(self, type, expression, zt_engine):
self.type = type
# At this place, *expression* is a `chameleon.tokenize.Token`
Expand Down Expand Up @@ -315,6 +317,7 @@ def __call__(self, target, c_engine):

class MappedExprType:
"""map expression type: ``zope.tales`` --> ``chameleon.tales``."""

def __init__(self, engine, type):
self.engine = engine
self.type = type
Expand Down
1 change: 1 addition & 0 deletions src/Products/PageTemplates/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class ChameleonEngine(ExpressionEngine):

Only partially implemented: its ``compile`` is currently unusable
"""

def compile(self, expression):
raise NotImplementedError()

Expand Down
1 change: 1 addition & 0 deletions src/Products/PageTemplates/tests/testDTMLTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class UnitTestSecurityPolicy:
#
# Standard SecurityPolicy interface
#

def validate(self,
accessed=None,
container=None,
Expand Down
1 change: 1 addition & 0 deletions src/Products/PageTemplates/tests/testHTMLTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class UnitTestSecurityPolicy:
Stub out the existing security policy for unit testing purposes.
"""
# Standard SecurityPolicy interface

def validate(self,
accessed=None,
container=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ZopeTalesExpressionTests(testHTMLTests.HTMLTests):
The tests in this class ensure that the ``_zt_expr_registry``
is cleared at the start and end of each test.
"""

def setUp(self):
super().setUp()
_zt_expr_registry.clear()
Expand Down
8 changes: 4 additions & 4 deletions src/Shared/DC/Scripts/Signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def __init__(self, varnames=(), argcount=-1):
def __eq__(self, other):
if not isinstance(other, FuncCode):
return False
return ((self.co_argcount, self.co_varnames) == # NOQA: W504
(other.co_argcount, other.co_varnames))
return ((self.co_argcount, self.co_varnames) # NOQA: W504
== (other.co_argcount, other.co_varnames))

def __lt__(self, other):
if not isinstance(other, FuncCode):
return False
return ((self.co_argcount, self.co_varnames) < # NOQA: W504
(other.co_argcount, other.co_varnames))
return ((self.co_argcount, self.co_varnames) # NOQA: W504
< (other.co_argcount, other.co_varnames))


def _setFuncSignature(self, defaults=None, varnames=(), argcount=-1):
Expand Down
13 changes: 6 additions & 7 deletions src/ZPublisher/BaseRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``

Expand Down Expand Up @@ -850,11 +849,11 @@ def lineno(o, m=False):
f = i.unwrap(obj.__func__)
c = obj.__self__.__class__
desc = f"'{c.__module__}.{c.__qualname__}' " \
f"method '{obj.__qualname__}'{lineno(f, 1)}"
f"method '{obj.__qualname__}'{lineno(f, 1)}"
elif i.isfunction(obj):
f = i.unwrap(obj)
desc = f"function '{f.__module__}.{f.__qualname__}'" \
f"{lineno(f)}"
f"{lineno(f)}"
else:
try:
cls_doc = "__doc__" not in obj.__dict__
Expand Down
Loading
Loading