From 6c99bfffdd1d6d25b3856bc53f0b8f44935bc169 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Fri, 16 Aug 2024 08:33:52 +0200 Subject: [PATCH 1/5] 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`` From 97d112beb3ce439b06f4ec599da38f815d432462 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Fri, 16 Aug 2024 06:39:49 +0000 Subject: [PATCH 2/5] Apply pre-commit code formatting --- src/App/Dialogs.py | 2 ++ src/App/config.py | 1 + src/App/tests/test_ProductContext.py | 1 + src/OFS/DTMLDocument.py | 4 ++-- src/OFS/absoluteurl.py | 1 + src/OFS/tests/testHistory.py | 1 + src/OFS/tests/testObjectManager.py | 1 + src/OFS/tests/testTraverse.py | 6 ++++++ src/Products/Five/browser/pagetemplatefile.py | 1 + src/Products/Five/browser/resource.py | 1 + src/Products/Five/tests/testing/folder.py | 1 + src/Products/Five/viewlet/tests.py | 1 + src/Products/PageTemplates/Expressions.py | 1 + src/Products/PageTemplates/engine.py | 3 +++ src/Products/PageTemplates/expression.py | 1 + src/Products/PageTemplates/tests/testDTMLTests.py | 1 + src/Products/PageTemplates/tests/testHTMLTests.py | 1 + .../PageTemplates/tests/testZopeTalesExpressions.py | 1 + src/Shared/DC/Scripts/Signature.py | 8 ++++---- src/ZPublisher/BaseRequest.py | 4 ++-- src/ZPublisher/BeforeTraverse.py | 1 + src/ZPublisher/HTTPRequest.py | 4 +++- src/ZPublisher/cookie.py | 1 + src/ZPublisher/tests/testBaseRequest.py | 2 ++ src/ZPublisher/tests/testHTTPRequest.py | 2 ++ src/webdav/xmltools.py | 1 + src/zmi/styles/tests.py | 1 + util.py | 4 +++- 28 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/App/Dialogs.py b/src/App/Dialogs.py index b5d440562d..e6c3d535f8 100644 --- a/src/App/Dialogs.py +++ b/src/App/Dialogs.py @@ -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)) diff --git a/src/App/config.py b/src/App/config.py index f29b0e55cb..c8a0277c48 100644 --- a/src/App/config.py +++ b/src/App/config.py @@ -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 diff --git a/src/App/tests/test_ProductContext.py b/src/App/tests/test_ProductContext.py index 7f349ac84d..8b9c59f0ba 100644 --- a/src/App/tests/test_ProductContext.py +++ b/src/App/tests/test_ProductContext.py @@ -134,6 +134,7 @@ def _verify_reg(self, name, obj): class _Product: """Product mockup.""" + def __init__(self): self.id = "pid" diff --git a/src/OFS/DTMLDocument.py b/src/OFS/DTMLDocument.py index cb0eab113f..03352342cb 100644 --- a/src/OFS/DTMLDocument.py +++ b/src/OFS/DTMLDocument.py @@ -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): diff --git a/src/OFS/absoluteurl.py b/src/OFS/absoluteurl.py index d35ae361e4..ed4b5e510d 100644 --- a/src/OFS/absoluteurl.py +++ b/src/OFS/absoluteurl.py @@ -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 diff --git a/src/OFS/tests/testHistory.py b/src/OFS/tests/testHistory.py index 845702d566..db25c1467a 100644 --- a/src/OFS/tests/testHistory.py +++ b/src/OFS/tests/testHistory.py @@ -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 diff --git a/src/OFS/tests/testObjectManager.py b/src/OFS/tests/testObjectManager.py index 20c1ccd802..edb26b350d 100644 --- a/src/OFS/tests/testObjectManager.py +++ b/src/OFS/tests/testObjectManager.py @@ -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 diff --git a/src/OFS/tests/testTraverse.py b/src/OFS/tests/testTraverse.py index 1ba8819b1b..32e0798549 100644 --- a/src/OFS/tests/testTraverse.py +++ b/src/OFS/tests/testTraverse.py @@ -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 @@ -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) @@ -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 @@ -135,6 +138,7 @@ class UnitTestUser(Implicit): """ Stubbed out manager for unit testing purposes. """ + def getId(self): return 'unit_tester' getUserName = getId @@ -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!' diff --git a/src/Products/Five/browser/pagetemplatefile.py b/src/Products/Five/browser/pagetemplatefile.py index fb66857db1..1134c542a2 100644 --- a/src/Products/Five/browser/pagetemplatefile.py +++ b/src/Products/Five/browser/pagetemplatefile.py @@ -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) diff --git a/src/Products/Five/browser/resource.py b/src/Products/Five/browser/resource.py index 8bd38c859c..9c91fef711 100644 --- a/src/Products/Five/browser/resource.py +++ b/src/Products/Five/browser/resource.py @@ -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__ diff --git a/src/Products/Five/tests/testing/folder.py b/src/Products/Five/tests/testing/folder.py index c356a792fb..52d83b0f7b 100644 --- a/src/Products/Five/tests/testing/folder.py +++ b/src/Products/Five/tests/testing/folder.py @@ -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 diff --git a/src/Products/Five/viewlet/tests.py b/src/Products/Five/viewlet/tests.py index 2328ce657a..fb60becb97 100644 --- a/src/Products/Five/viewlet/tests.py +++ b/src/Products/Five/viewlet/tests.py @@ -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, diff --git a/src/Products/PageTemplates/Expressions.py b/src/Products/PageTemplates/Expressions.py index 137db2d836..5b3e375b88 100644 --- a/src/Products/PageTemplates/Expressions.py +++ b/src/Products/PageTemplates/Expressions.py @@ -163,6 +163,7 @@ class _CombinedMapping: Earlier mappings take precedence. """ + def __init__(self, *ms): self.mappings = ms diff --git a/src/Products/PageTemplates/engine.py b/src/Products/PageTemplates/engine.py index df1d1d3390..31a3b408c1 100644 --- a/src/Products/PageTemplates/engine.py +++ b/src/Products/PageTemplates/engine.py @@ -86,6 +86,7 @@ def __call__(self, key, iterable): class RepeatItem(PathIterator): """Iterator compatible with ``chameleon`` and ``zope.tales``.""" + def __iter__(self): return self @@ -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` @@ -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 diff --git a/src/Products/PageTemplates/expression.py b/src/Products/PageTemplates/expression.py index 0f8f06dbe8..a1b1d0758b 100644 --- a/src/Products/PageTemplates/expression.py +++ b/src/Products/PageTemplates/expression.py @@ -216,6 +216,7 @@ class ChameleonEngine(ExpressionEngine): Only partially implemented: its ``compile`` is currently unusable """ + def compile(self, expression): raise NotImplementedError() diff --git a/src/Products/PageTemplates/tests/testDTMLTests.py b/src/Products/PageTemplates/tests/testDTMLTests.py index f91a870ed9..3d6926c00a 100644 --- a/src/Products/PageTemplates/tests/testDTMLTests.py +++ b/src/Products/PageTemplates/tests/testDTMLTests.py @@ -40,6 +40,7 @@ class UnitTestSecurityPolicy: # # Standard SecurityPolicy interface # + def validate(self, accessed=None, container=None, diff --git a/src/Products/PageTemplates/tests/testHTMLTests.py b/src/Products/PageTemplates/tests/testHTMLTests.py index 47a359d449..9e5fdfffa0 100644 --- a/src/Products/PageTemplates/tests/testHTMLTests.py +++ b/src/Products/PageTemplates/tests/testHTMLTests.py @@ -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, diff --git a/src/Products/PageTemplates/tests/testZopeTalesExpressions.py b/src/Products/PageTemplates/tests/testZopeTalesExpressions.py index 3188439f6e..0dd36a2a58 100644 --- a/src/Products/PageTemplates/tests/testZopeTalesExpressions.py +++ b/src/Products/PageTemplates/tests/testZopeTalesExpressions.py @@ -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() diff --git a/src/Shared/DC/Scripts/Signature.py b/src/Shared/DC/Scripts/Signature.py index af0d81b829..5e6cfcc703 100644 --- a/src/Shared/DC/Scripts/Signature.py +++ b/src/Shared/DC/Scripts/Signature.py @@ -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): diff --git a/src/ZPublisher/BaseRequest.py b/src/ZPublisher/BaseRequest.py index 2bc65ddf4d..d685c1556a 100644 --- a/src/ZPublisher/BaseRequest.py +++ b/src/ZPublisher/BaseRequest.py @@ -849,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__ diff --git a/src/ZPublisher/BeforeTraverse.py b/src/ZPublisher/BeforeTraverse.py index ae2362d11a..6a93d16323 100644 --- a/src/ZPublisher/BeforeTraverse.py +++ b/src/ZPublisher/BeforeTraverse.py @@ -88,6 +88,7 @@ class MultiHook: MultiHook calls the named hook from the class of the container, then the prior hook, then all the hooks in its list. """ + def __init__(self, hookname='', prior=None, defined_in_class=False): # The default values are needed for unpickling instances of this class diff --git a/src/ZPublisher/HTTPRequest.py b/src/ZPublisher/HTTPRequest.py index 9a497839e1..56f445d581 100644 --- a/src/ZPublisher/HTTPRequest.py +++ b/src/ZPublisher/HTTPRequest.py @@ -611,7 +611,7 @@ def processInputs( elif has_codec(type_name): # recode: assert not isinstance(item, FileUpload), \ - "cannot recode files" + "cannot recode files" item = item.encode( character_encoding, "surrogateescape") character_encoding = type_name @@ -1354,6 +1354,7 @@ def sane_environment(env): class ValueDescriptor: """(non data) descriptor to compute `value` from `file`.""" + def __get__(self, inst, owner=None): if inst is None: return self @@ -1381,6 +1382,7 @@ def __get__(self, inst, owner=None): class Global: """(non data) descriptor to access a (modul) global attribute.""" + def __init__(self, name): """access global *name*.""" self.name = name diff --git a/src/ZPublisher/cookie.py b/src/ZPublisher/cookie.py index 60c9dac85c..ad1f4177c6 100644 --- a/src/ZPublisher/cookie.py +++ b/src/ZPublisher/cookie.py @@ -107,6 +107,7 @@ class CookieParameterRegistry: It maintains 2 maps: one to normalize parameter names and one to check and convert parameter values. """ + def __init__(self): self._normalize = {} self._convert = {} diff --git a/src/ZPublisher/tests/testBaseRequest.py b/src/ZPublisher/tests/testBaseRequest.py index 91986a838e..4f2be00b6f 100644 --- a/src/ZPublisher/tests/testBaseRequest.py +++ b/src/ZPublisher/tests/testBaseRequest.py @@ -141,6 +141,7 @@ def __before_publishing_traverse__(self, object, REQUEST): def _makeObjectWithBD(self): class DummyObjectWithBD(self._makeBasicObjectClass()): """Dummy class with __browser_default__.""" + def __browser_default__(self, REQUEST): if REQUEST['_test_counter'] < 100: REQUEST['_test_counter'] += 1 @@ -155,6 +156,7 @@ def _makeObjectWithBBT(self): @zpublish class _DummyResult: ''' ''' + def __init__(self, tag): self.tag = tag diff --git a/src/ZPublisher/tests/testHTTPRequest.py b/src/ZPublisher/tests/testHTTPRequest.py index 7b11317794..7fa07d191b 100644 --- a/src/ZPublisher/tests/testHTTPRequest.py +++ b/src/ZPublisher/tests/testHTTPRequest.py @@ -1565,6 +1565,7 @@ class TestSearchType(unittest.TestCase): see "https://github.com/zopefoundation/Zope/pull/512" """ + def check(self, val, expect): mo = search_type(val) if expect is None: @@ -1590,6 +1591,7 @@ def test_special(self): class _Unseekable: """Auxiliary class emulating an unseekable file like object""" + def __init__(self, file): for m in ("read", "readline", "close", "__del__"): setattr(self, m, getattr(file, m)) diff --git a/src/webdav/xmltools.py b/src/webdav/xmltools.py index 3fc2a6f215..241221a3a7 100644 --- a/src/webdav/xmltools.py +++ b/src/webdav/xmltools.py @@ -189,6 +189,7 @@ def toxml(self): class ProtectedExpatParser(ExpatParser): """ See https://bugs.launchpad.net/zope2/+bug/1114688 """ + def __init__(self, forbid_dtd=True, forbid_entities=True, *args, **kwargs): # Python 2.x old style class diff --git a/src/zmi/styles/tests.py b/src/zmi/styles/tests.py index c0c52d6aa1..d7207038d1 100644 --- a/src/zmi/styles/tests.py +++ b/src/zmi/styles/tests.py @@ -35,6 +35,7 @@ def afterSetUp(self): def call_manage_main(self): """Call /folder/manage_main and return the HTML text.""" + def _call_manage_main(self): self.setRoles(['Manager']) # temporaryPlacelessSetUp insists in creating an interaction diff --git a/util.py b/util.py index 5d2aa81026..da9d47f815 100644 --- a/util.py +++ b/util.py @@ -1,7 +1,9 @@ import os -from typing import Optional, Tuple, List from configparser import NoSectionError from configparser import RawConfigParser +from typing import List +from typing import Optional +from typing import Tuple HERE = os.path.abspath(os.path.dirname(__file__)) From 59e4f706eb934524c09492fb1c928f06e1097e24 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Mon, 19 Aug 2024 10:45:04 +0200 Subject: [PATCH 3/5] Move lint to pre-commit. Removed things from .meta.toml still need to be added to meta/config. --- .meta.toml | 24 ------------------------ .pre-commit-config.yaml | 3 +-- tox.ini | 38 +------------------------------------- 3 files changed, 2 insertions(+), 63 deletions(-) diff --git a/.meta.toml b/.meta.toml index a3f5db2b67..55664e368a 100644 --- a/.meta.toml +++ b/.meta.toml @@ -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}", ] @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 92867ce3e6..de2984176b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,9 +15,8 @@ repos: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/PyCQA/flake8 - rev: "6.1.0" + rev: "7.1.1" hooks: - id: flake8 additional_dependencies: - - flake8-coding == 1.3.2 - flake8-debugger == 4.1.2 diff --git a/tox.ini b/tox.ini index 9540c355f0..407416a77a 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,6 @@ envlist = py313 docs coverage - pre-commit [testenv] skip_install = true @@ -51,7 +50,7 @@ commands = !universal2: {envdir}/bin/alltests --layer '!Products.PluginIndexes' {posargs:-vc} allowlist_externals = * -[testenv:pre-commit] +[testenv:lint] basepython = python3 description = This env runs all linters configured in .pre-commit-config.yaml skip_install = true @@ -61,17 +60,6 @@ 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:release-check] description = ensure that the distribution is ready to release basepython = python3 @@ -89,30 +77,6 @@ commands = python -m build --sdist --no-isolation twine check dist/* -[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 -deps = - 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 [] [testenv:docs] basepython = python3 From 646ff261f5cb9637bca37fc4efbcf0f4bc4fee6d Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Mon, 19 Aug 2024 10:47:25 +0200 Subject: [PATCH 4/5] Do not run lint/pre-commit twice. --- .github/workflows/tests.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 936f164562..6fe4f28287 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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"] @@ -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"] } From 94eac079ffb72dbaf0508d328ca5855753358d5c Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Tue, 20 Aug 2024 09:18:27 +0200 Subject: [PATCH 5/5] Run meta/config. --- .github/workflows/pre-commit.yml | 14 ++++++++++++-- .meta.toml | 2 +- .pre-commit-config.yaml | 2 ++ MANIFEST.in | 1 + tox.ini | 18 +++++++++--------- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 5c015fd6e7..eb4f0c64b5 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,3 +1,5 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/zope-product name: pre-commit on: @@ -5,9 +7,15 @@ on: push: branches: - master + # Allow to run this workflow manually from the Actions tab + workflow_dispatch: + +env: + FORCE_COLOR: 1 + jobs: pre-commit: - name: pre-commit linting + name: linting runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -16,7 +24,9 @@ jobs: python-version: 3.x - uses: pre-commit/action@v3.0.1 with: - extra_args: --all-files + extra_args: --all-files --show-diff-on-failure + env: + PRE_COMMIT_COLOR: always - uses: pre-commit-ci/lite-action@v1.0.2 if: always() with: diff --git a/.meta.toml b/.meta.toml index 55664e368a..733abde717 100644 --- a/.meta.toml +++ b/.meta.toml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index de2984176b..8d996f7755 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,5 @@ +# 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 diff --git a/MANIFEST.in b/MANIFEST.in index 3a3a7e9b98..ca8ef935c3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/tox.ini b/tox.ini index 407416a77a..0edbc014fc 100644 --- a/tox.ini +++ b/tox.ini @@ -50,15 +50,6 @@ commands = !universal2: {envdir}/bin/alltests --layer '!Products.PluginIndexes' {posargs:-vc} allowlist_externals = * -[testenv:lint] -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:release-check] description = ensure that the distribution is ready to release @@ -77,6 +68,15 @@ commands = python -m build --sdist --no-isolation twine check dist/* +[testenv:lint] +description = This env runs all linters configured in .pre-commit-config.yaml +basepython = python3 +skip_install = true +deps = + pre-commit +commands_pre = +commands = + pre-commit run --all-files --show-diff-on-failure [testenv:docs] basepython = python3