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

Move all linters to pre-commit. #1164

Closed
wants to merge 12 commits into from
Closed
17 changes: 17 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: pre-commit

on:
sallner marked this conversation as resolved.
Show resolved Hide resolved
pull_request:

jobs:
pre-commit:
name: pre-commit linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x
- uses: pre-commit/[email protected]
- uses: pre-commit-ci/[email protected]
if: always()
sallner marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 30 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
ci:
autofix_prs: true

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.6.2
rev: "v3.11.1"
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-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.4"
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/isidentical/teyit
rev: 0.4.3
hooks:
- id: teyit
exclude: src/App/tests/fixtures/error.py # invalid syntax
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst

- Update to newest compatible versions of dependencies.

- Move all linters to pre-commit (hook).


5.8.5 (2023-09-21)
------------------
Expand Down
9 changes: 4 additions & 5 deletions docs/zdgbook/examples/PollImplementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@


class PollImplementation:
"""
A multiple choice poll, implements the Poll interface.
"""A multiple choice poll, implements the Poll interface.

The poll has a question and a sequence of responses. Votes
are stored in a dictionary which maps response indexes to a
number of votes.
The poll has a question and a sequence of responses. Votes are
stored in a dictionary which maps response indexes to a number of
votes.
"""

__implements__ = Poll
Expand Down
9 changes: 4 additions & 5 deletions docs/zdgbook/examples/PollProduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@


class PollProduct(Implicit, Persistent, RoleManager, Item):
"""
Poll product class, implements Poll interface.
"""Poll product class, implements Poll interface.

The poll has a question and a sequence of responses. Votes
are stored in a dictionary which maps response indexes to a
number of votes.
The poll has a question and a sequence of responses. Votes are
stored in a dictionary which maps response indexes to a number of
votes.
"""

__implements__ = Poll
Expand Down
20 changes: 7 additions & 13 deletions src/App/ApplicationManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def db(self):


class DatabaseChooser(Tabs, Traversable, Implicit):
""" Choose which database to view
"""
"""Choose which database to view."""

__allow_access_to_unprotected_subobjects__ = 1

Expand All @@ -69,8 +68,7 @@ class DatabaseChooser(Tabs, Traversable, Implicit):

def getDatabaseNames(self, quote=False):
configuration = getConfiguration()
names = configuration.dbtab.listDatabaseNames()
names.sort()
names = sorted(configuration.dbtab.listDatabaseNames())
if quote:
return [(name, parse.quote(name)) for name in names]
return names
Expand All @@ -94,8 +92,7 @@ def __bobo_traverse__(self, request, name):


class ConfigurationViewer(Tabs, Traversable, Implicit):
""" Provides information about the running configuration
"""
"""Provides information about the running configuration."""
manage = manage_main = manage_workspace = DTMLFile('dtml/cpConfiguration',
globals())
manage_main._setName('manage_main')
Expand Down Expand Up @@ -145,8 +142,7 @@ def manage_getConfiguration(self):


class DebugManager(Tabs, Traversable, Implicit):
""" Debug and profiling information
"""
"""Debug and profiling information."""
manage = manage_main = manage_workspace = DTMLFile('dtml/debug', globals())
manage_main._setName('manage_main')
id = 'DebugInfo'
Expand Down Expand Up @@ -240,8 +236,7 @@ class ApplicationManager(CacheManager,
Tabs,
Traversable,
Implicit):
"""System management
"""
"""System management."""
__allow_access_to_unprotected_subobjects__ = 1
__roles__ = ('Manager',)

Expand Down Expand Up @@ -312,8 +307,7 @@ def getCLIENT_HOME(self):


class AltDatabaseManager(Traversable, UndoSupport):
""" Database management DBTab-style
"""
"""Database management DBTab-style."""
id = 'DatabaseManagement'
name = title = 'Database Management'
meta_type = 'Database Management'
Expand Down Expand Up @@ -371,7 +365,7 @@ def manage_minimize(self, value=1, REQUEST=None):

@requestmethod('POST')
def manage_pack(self, days=0, REQUEST=None):
"""Pack the database"""
"""Pack the database."""
if not isinstance(days, (int, float)):
try:
days = float(days)
Expand Down
16 changes: 6 additions & 10 deletions src/App/CacheManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
##############################################################################
"""Cache management support.

This class is mixed into the application manager in App.ApplicationManager.
This class is mixed into the application manager in
App.ApplicationManager.
"""

from AccessControl.class_init import InitializeClass
from Acquisition import aq_parent


class CacheManager:
"""Cache management mix-in
"""
"""Cache management mix-in."""

def _getDB(self):
try:
Expand All @@ -34,10 +34,8 @@ def cache_size(self):
return db.getCacheSize()

def cache_detail(self, REQUEST=None):
"""
Returns the name of the classes of the objects in the cache
and the number of objects in the cache for each class.
"""
"""Returns the name of the classes of the objects in the cache and the
number of objects in the cache for each class."""
detail = self._getDB().cacheDetail()
if REQUEST is not None:
# format as text
Expand All @@ -48,9 +46,7 @@ def cache_detail(self, REQUEST=None):
return detail

def cache_extreme_detail(self, REQUEST=None):
"""
Returns information about each object in the cache.
"""
"""Returns information about each object in the cache."""
detail = self._getDB().cacheExtremeDetail()
if REQUEST is not None:
# sort the list.
Expand Down
42 changes: 21 additions & 21 deletions src/App/Dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Common HTML dialog boxes.

"""Common HTML dialog boxes
MessageDialog(title, message, action, [target])

MessageDialog(title, message, action, [target])
A very simple dialog used to display an HTML page titled title,
displaying message message and an OK button. Clicking the OK
button will take the browser to the URL specified in action.
The *optional* target argument can be used to force a (frames
capable) browser to load the URL specified in action into a specific
frame. (Specifying '_new' will cause the browser to load the
specified URL into a new window, for example).

A very simple dialog used to display an HTML page titled title,
displaying message message and an OK button. Clicking the OK
button will take the browser to the URL specified in action.
The *optional* target argument can be used to force a (frames
capable) browser to load the URL specified in action into a specific
frame. (Specifying '_new' will cause the browser to load the
specified URL into a new window, for example).

example usage:
<PRE>
return MessageDialog(title='Just thought you should know...',
message='You have wiped out your data.',
action='/paid_tech_support/prices.html',
target='_top')
</PRE>"""
example usage:
<PRE>
return MessageDialog(title='Just thought you should know...',
message='You have wiped out your data.',
action='/paid_tech_support/prices.html',
target='_top')
</PRE>
"""

from App.special_dtml import HTML


class MessageDialogHTML(HTML):
"""A special version of HTML which is always published as text/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
"""
"""A special string that will be published as text/html."""

def asHTML(self):
return self
return _HTMLString(super().__call__(*args, **kw))
Expand Down
2 changes: 1 addition & 1 deletion src/App/Extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _getPath(home, prefix, name, suffixes):


def getPath(prefix, name, checkProduct=1, suffixes=('',), cfg=None):
"""Find a file in one of several relative locations
"""Find a file in one of several relative locations.

Arguments:

Expand Down
14 changes: 5 additions & 9 deletions src/App/FactoryDispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@


def _product_packages():
"""Returns all product packages including the regularly defined
zope2 packages and those without the Products namespace package.
"""
"""Returns all product packages including the regularly defined zope2
packages and those without the Products namespace package."""
import Products

_packages = {}
Expand All @@ -46,8 +45,7 @@ def _product_packages():


class Product(Base):
"""Model a non-persistent product wrapper.
"""
"""Model a non-persistent product wrapper."""

security = ClassSecurityInfo()

Expand Down Expand Up @@ -96,8 +94,7 @@ def __bobo_traverse__(self, REQUEST, name):


class FactoryDispatcher(Implicit):
"""Provide a namespace for product "methods"
"""
"""Provide a namespace for product "methods"."""

security = ClassSecurityInfo()

Expand Down Expand Up @@ -158,8 +155,7 @@ def __getattr__(self, name):

# Provide a replacement for manage_main that does a redirection:
def manage_main(trueself, self, REQUEST, update_menu=0):
"""Implement a contents view by redirecting to the true view
"""
"""Implement a contents view by redirecting to the true view."""
REQUEST.RESPONSE.redirect(self.DestinationURL() + '/manage_main')


Expand Down
6 changes: 3 additions & 3 deletions src/App/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Image object that is stored in a file"""
"""Image object that is stored in a file."""

import os.path
import stat
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self, path, _prefix=None):
self.lmh = rfc1123_date(self.lmt)

def index_html(self, REQUEST, RESPONSE):
"""Default document"""
"""Default document."""
# HTTP If-Modified-Since header handling. This is duplicated
# from OFS.Image.Image - it really should be consolidated
# somewhere...
Expand Down Expand Up @@ -122,7 +122,7 @@ def index_html(self, REQUEST, RESPONSE):

@security.public
def HEAD(self, REQUEST, RESPONSE):
""" """
""""""
RESPONSE.setHeader('Content-Type', self.content_type)
RESPONSE.setHeader('Last-Modified', self.lmh)
return ''
Expand Down
10 changes: 4 additions & 6 deletions src/App/Management.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Standard management interface support
"""
"""Standard management interface support."""

import html
import itertools
Expand Down Expand Up @@ -69,8 +68,7 @@ def filtered_manage_options(self, REQUEST=None):
manage_workspace__roles__ = ('Authenticated',)

def manage_workspace(self, REQUEST):
"""Dispatch to first interface in manage_options
"""
"""Dispatch to first interface in manage_options."""
options = self.filtered_manage_options(REQUEST)
try:
m = options[0]['action']
Expand Down Expand Up @@ -138,7 +136,7 @@ def tabs_path_info(self, script, path):

@implementer(INavigation)
class Navigation(Base):
"""Basic navigation UI support"""
"""Basic navigation UI support."""

security = ClassSecurityInfo()

Expand Down Expand Up @@ -183,7 +181,7 @@ def manage_page_header(self, *args, **kw):

@security.public
def manage_zmi_logout(self, REQUEST, RESPONSE):
"""Logout current user"""
"""Logout current user."""
p = getattr(REQUEST, '_logout_path', None)
if p is not None:
return self.restrictedTraverse(*p)
Expand Down
Loading
Loading