← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/lp-mailman:pre-commit into lp-mailman:master

 

Colin Watson has proposed merging ~cjwatson/lp-mailman:pre-commit into lp-mailman:master.

Commit message:
Run isort from pre-commit

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/lp-mailman/+git/lp-mailman/+merge/419224

Most of these changes were generated automatically by `isort`, with a couple of manual adjustments at the end.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/lp-mailman:pre-commit into lp-mailman:master.
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..b1295f8
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,16 @@
+# See https://pre-commit.com for more information
+# See https://pre-commit.com/hooks.html for more hooks
+repos:
+-   repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v3.2.0
+    hooks:
+    -   id: check-added-large-files
+    -   id: check-ast
+    -   id: check-merge-conflict
+    -   id: check-yaml
+    -   id: debug-statements
+    -   id: no-commit-to-branch
+-   repo: https://github.com/PyCQA/isort
+    rev: 5.9.2
+    hooks:
+    -   id: isort
diff --git a/_pythonpath.py b/_pythonpath.py
index c4a43fd..055472e 100644
--- a/_pythonpath.py
+++ b/_pythonpath.py
@@ -8,6 +8,7 @@ import imp
 import os.path
 import sys
 
+
 # Get path to this file.
 if __name__ == '__main__':
     filename = __file__
diff --git a/buildmailman.py b/buildmailman.py
index 62fc844..a4bc66a 100644
--- a/buildmailman.py
+++ b/buildmailman.py
@@ -69,8 +69,8 @@ def build_mailman():
         # monkey_patch(), in case this is half-installed.  See
         # <https://bugs.launchpad.net/launchpad-registry/+bug/683486>.
         try:
-            from Mailman.Queue import XMLRPCRunner
             from Mailman.Handlers import LPModerate
+            from Mailman.Queue import XMLRPCRunner
         except ImportError:
             # Monkey patches not present, redo install and patch steps.
             need_install = True
diff --git a/lib/contrib/glock.py b/lib/contrib/glock.py
index d1ced09..7d08379 100644
--- a/lib/contrib/glock.py
+++ b/lib/contrib/glock.py
@@ -21,7 +21,11 @@ Unix.
 @see: class L{GlobalLock} for more details.
 '''
 
-from __future__ import absolute_import, print_function
+from __future__ import (
+    absolute_import,
+    print_function,
+    )
+
 
 __version__ = '0.2.' + '$Revision: #5 $'[12:-2]
 __author__ = 'Richard Gruet', 'rjgruet@xxxxxxxxx'
@@ -31,15 +35,21 @@ __doc__ += '\n@author: %s (U{%s})\n@version: %s' % (__author__[0],
                                             __author__[1], __version__)
 __all__ = ['GlobalLock', 'GlobalLockError', 'LockAlreadyAcquired', 'NotOwner']
 
-# Imports:
-import sys, string, os, errno, re
+import errno
+import os
+import re
+import string
+import sys
+
 
 # System-dependent imports for locking implementation:
 _windows = (sys.platform == 'win32')
 
 if _windows:
     try:
-        import win32event, win32api, pywintypes
+        import pywintypes
+        import win32api
+        import win32event
     except ImportError:
         sys.stderr.write('The win32 extensions need to be installed!')
     try:
@@ -279,7 +289,8 @@ def test():
     else: raise Exception('should have raised a NotOwner exception')
 
     # Check that <> threads of same process do block:
-    import threading, time
+    import threading
+    import time
     thread = threading.Thread(target=threadMain, args=(l,))
     print('main: locking...', end='')
     l.acquire()
diff --git a/lib/devscripts/sourcecode.py b/lib/devscripts/sourcecode.py
index 5dc0e6d..0ab7650 100644
--- a/lib/devscripts/sourcecode.py
+++ b/lib/devscripts/sourcecode.py
@@ -3,7 +3,11 @@
 
 """Tools for maintaining the Launchpad source code."""
 
-from __future__ import absolute_import, print_function
+from __future__ import (
+    absolute_import,
+    print_function,
+    )
+
 
 __metaclass__ = type
 __all__ = [
@@ -19,6 +23,7 @@ import os
 import shutil
 import sys
 
+
 try:
     from breezy import ui
     from breezy.branch import Branch
diff --git a/lib/devscripts/tests/test_sourcecode.py b/lib/devscripts/tests/test_sourcecode.py
index cc8f375..8f4748f 100644
--- a/lib/devscripts/tests/test_sourcecode.py
+++ b/lib/devscripts/tests/test_sourcecode.py
@@ -3,7 +3,11 @@
 
 """Module docstring goes here."""
 
-from __future__ import absolute_import, print_function
+from __future__ import (
+    absolute_import,
+    print_function,
+    )
+
 
 __metaclass__ = type
 
@@ -13,6 +17,7 @@ from StringIO import StringIO
 import tempfile
 import unittest
 
+
 try:
     from breezy.bzr.bzrdir import BzrDir
     from breezy.tests import TestCase
diff --git a/lib/lp/scripts/runlaunchpad.py b/lib/lp/scripts/runlaunchpad.py
index c49e990..7250b25 100644
--- a/lib/lp/scripts/runlaunchpad.py
+++ b/lib/lp/scripts/runlaunchpad.py
@@ -1,7 +1,12 @@
 # Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-from __future__ import absolute_import, print_function, unicode_literals
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
 
 __metaclass__ = type
 __all__ = ['start_launchpad']
@@ -10,6 +15,7 @@ try:
     from contextlib import ExitStack
 except ImportError:
     from contextlib2 import ExitStack
+
 import os
 import signal
 import sys
diff --git a/lib/lp/scripts/tests/test_runlaunchpad.py b/lib/lp/scripts/tests/test_runlaunchpad.py
index 62f7d2d..f437811 100644
--- a/lib/lp/scripts/tests/test_runlaunchpad.py
+++ b/lib/lp/scripts/tests/test_runlaunchpad.py
@@ -3,7 +3,12 @@
 
 """Tests for runlaunchpad.py"""
 
-from __future__ import absolute_import, print_function, unicode_literals
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
 
 __metaclass__ = type
 __all__ = [
diff --git a/lib/lp/scripts/utilities/importpedant.py b/lib/lp/scripts/utilities/importpedant.py
index b08da9b..2a0746f 100644
--- a/lib/lp/scripts/utilities/importpedant.py
+++ b/lib/lp/scripts/utilities/importpedant.py
@@ -1,24 +1,29 @@
 # Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-from __future__ import absolute_import, print_function, unicode_literals
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
 
 import __builtin__
 import atexit
 import itertools
 from operator import attrgetter
 import types
+import warnings
 
 
-original_import = __builtin__.__import__
-naughty_imports = set()
-
 # Silence bogus warnings from Hardy's python-pkg-resources package.
-import warnings
 warnings.filterwarnings('ignore', category=UserWarning, append=True,
                         message=r'Module .*? is being added to sys.path')
 
 
+original_import = __builtin__.__import__
+naughty_imports = set()
+
+
 def text_lines_to_set(text):
     return set(line.strip() for line in text.splitlines() if line.strip())
 
diff --git a/lib/lp/scripts/utilities/killservice.py b/lib/lp/scripts/utilities/killservice.py
index ef91f58..a759314 100755
--- a/lib/lp/scripts/utilities/killservice.py
+++ b/lib/lp/scripts/utilities/killservice.py
@@ -3,7 +3,12 @@
 # Copyright 2009-2018 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-from __future__ import absolute_import, print_function, unicode_literals
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
 
 __metaclass__ = type
 
diff --git a/lib/lp/scripts/utilities/test.py b/lib/lp/scripts/utilities/test.py
index 49d730e..bb96f08 100755
--- a/lib/lp/scripts/utilities/test.py
+++ b/lib/lp/scripts/utilities/test.py
@@ -13,7 +13,11 @@
 ##############################################################################
 """Test script."""
 
-from __future__ import absolute_import, print_function, unicode_literals
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
 
 import doctest
 import os
diff --git a/lib/lp/scripts/utilities/tests/test_shhh.py b/lib/lp/scripts/utilities/tests/test_shhh.py
index c00e2f8..8d95ddb 100644
--- a/lib/lp/scripts/utilities/tests/test_shhh.py
+++ b/lib/lp/scripts/utilities/tests/test_shhh.py
@@ -1,7 +1,12 @@
 # Copyright 2009 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-from __future__ import absolute_import, print_function, unicode_literals
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
 
 __metaclass__ = type
 
diff --git a/lib/lp/scripts/utilities/warninghandler.py b/lib/lp/scripts/utilities/warninghandler.py
index bd167c8..71fab1c 100644
--- a/lib/lp/scripts/utilities/warninghandler.py
+++ b/lib/lp/scripts/utilities/warninghandler.py
@@ -5,6 +5,7 @@
 
 from __future__ import print_function
 
+
 __metaclass__ = type
 
 import StringIO
diff --git a/lib/lp/services/config/tests/test_config.py b/lib/lp/services/config/tests/test_config.py
index 1471927..f704df3 100644
--- a/lib/lp/services/config/tests/test_config.py
+++ b/lib/lp/services/config/tests/test_config.py
@@ -24,6 +24,7 @@ import testtools
 import lp.services.config
 from lp.services.config.fixture import ConfigUseFixture
 
+
 # Configs that shouldn't be tested.
 EXCLUDED_CONFIGS = ['lpnet-template']
 
diff --git a/lib/lp/services/log/logger.py b/lib/lp/services/log/logger.py
index 4327e9a..1d19114 100644
--- a/lib/lp/services/log/logger.py
+++ b/lib/lp/services/log/logger.py
@@ -3,7 +3,11 @@
 
 """Loggers."""
 
-from __future__ import absolute_import, print_function
+from __future__ import (
+    absolute_import,
+    print_function,
+    )
+
 
 __metaclass__ = type
 __all__ = [
diff --git a/lib/lp/services/log/loglevels.py b/lib/lp/services/log/loglevels.py
index 71d4a70..fca11d1 100644
--- a/lib/lp/services/log/loglevels.py
+++ b/lib/lp/services/log/loglevels.py
@@ -28,6 +28,7 @@ __all__ = [
 
 import logging
 
+
 # Reexport standard log levels.
 DEBUG = logging.DEBUG
 INFO = logging.INFO
diff --git a/lib/lp/services/mailman/monkeypatches/defaults.py b/lib/lp/services/mailman/monkeypatches/defaults.py
index fd3b940..7a26d3b 100644
--- a/lib/lp/services/mailman/monkeypatches/defaults.py
+++ b/lib/lp/services/mailman/monkeypatches/defaults.py
@@ -4,6 +4,7 @@
 # Pick up the standard Mailman defaults
 from Mailman.Defaults import *
 
+
 # Use a name for the site list that is very unlikely to conflict with any
 # possible Launchpad team name.  The default is "mailman" and that doesn't cut
 # it. :)  The site list is never used by Launchpad, but it's required by
diff --git a/lib/lp/services/mailman/scripts/mlist_sync.py b/lib/lp/services/mailman/scripts/mlist_sync.py
index d52a436..a83949d 100644
--- a/lib/lp/services/mailman/scripts/mlist_sync.py
+++ b/lib/lp/services/mailman/scripts/mlist_sync.py
@@ -85,6 +85,7 @@ class MailingListSyncScript(LaunchpadScript):
         """
         # This can't be done at module global scope.
         from Mailman import mm_cfg
+
         # Start by rsync'ing over the entire $vardir/lists, $vardir/archives,
         # $vardir/backups, and $vardir/mhonarc directories.  We specifically
         # do not rsync the data, locks, logs, qfiles, or spam directories.
@@ -113,8 +114,10 @@ class MailingListSyncScript(LaunchpadScript):
     def fixHostnames(self):
         """Fix up the host names in Mailman and the LP database."""
         # These can't be done at module global scope.
-        from Mailman import Utils
-        from Mailman import mm_cfg
+        from Mailman import (
+            mm_cfg,
+            Utils,
+            )
         from Mailman.MailList import MailList
         from Mailman.Queue import XMLRPCRunner
 
diff --git a/lib/lp/services/mailman/tests/enums.py b/lib/lp/services/mailman/tests/enums.py
index d62bf56..9c653e6 100644
--- a/lib/lp/services/mailman/tests/enums.py
+++ b/lib/lp/services/mailman/tests/enums.py
@@ -7,7 +7,12 @@ These are only used internally, so it doesn't matter whether the values
 match those used in the rest of Launchpad.
 """
 
-from __future__ import absolute_import, print_function, unicode_literals
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
 
 __metaclass__ = type
 __all__ = [
diff --git a/lib/lp/services/mailman/tests/test_lpsize.py b/lib/lp/services/mailman/tests/test_lpsize.py
index 4cee5d6..e7e2940 100644
--- a/lib/lp/services/mailman/tests/test_lpsize.py
+++ b/lib/lp/services/mailman/tests/test_lpsize.py
@@ -4,6 +4,7 @@
 
 from __future__ import with_statement
 
+
 __metaclass__ = type
 __all__ = []
 
diff --git a/lib/lp/services/scripts/logger.py b/lib/lp/services/scripts/logger.py
index 54ba5a3..cc26244 100644
--- a/lib/lp/services/scripts/logger.py
+++ b/lib/lp/services/scripts/logger.py
@@ -41,6 +41,7 @@ from zope.exceptions.log import Formatter
 from lp.services.config import config
 from lp.services.log import loglevels
 
+
 # Reexport our custom loglevels for old callsites. These callsites
 # should be importing the symbols from lp.services.log.loglevels
 DEBUG2 = loglevels.DEBUG2
diff --git a/lib/lp/services/xmlrpc.py b/lib/lp/services/xmlrpc.py
index 9eff891..4dd0adf 100644
--- a/lib/lp/services/xmlrpc.py
+++ b/lib/lp/services/xmlrpc.py
@@ -14,6 +14,7 @@ import socket
 from defusedxml.xmlrpc import monkey_patch
 from six.moves import xmlrpc_client
 
+
 # Protect against various XML parsing vulnerabilities.
 monkey_patch()
 
diff --git a/lib/lp/testing/__init__.py b/lib/lp/testing/__init__.py
index 687e4e8..1440e68 100644
--- a/lib/lp/testing/__init__.py
+++ b/lib/lp/testing/__init__.py
@@ -1,7 +1,10 @@
 # Copyright 2009-2019 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-from __future__ import absolute_import, print_function
+from __future__ import (
+    absolute_import,
+    print_function,
+    )
 
 
 __metaclass__ = type
@@ -56,8 +59,8 @@ def reset_logging():
     logging._handlers.clear()
 
     # Reset the setup
-    from zope.testrunner.runner import Runner
     from zope.testrunner.logsupport import Logging
+    from zope.testrunner.runner import Runner
     Logging(Runner()).global_setup()
     lp_sitecustomize.customize_logger()
 
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..8069514
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,13 @@
+[isort]
+combine_as_imports = true
+force_grid_wrap = 2
+force_sort_within_sections = true
+include_trailing_comma = true
+known_first_party = lp,devscripts
+known_pythonpath = _pythonpath
+line_length = 78
+lines_after_imports = 2
+multi_line_output = 8
+order_by_type = false
+py_version = 27
+sections = FUTURE,PYTHONPATH,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
diff --git a/utilities/format-imports b/utilities/format-imports
index 18d9403..d3d037f 100755
--- a/utilities/format-imports
+++ b/utilities/format-imports
@@ -125,7 +125,11 @@ is over the length limit.
 }}}
 """
 
-from __future__ import absolute_import, print_function
+from __future__ import (
+    absolute_import,
+    print_function,
+    )
+
 
 __metaclass__ = type
 
@@ -135,9 +139,11 @@ import re
 import sys
 from textwrap import dedent
 
+
 sys.path[0:0] = [os.path.dirname(__file__)]
 from python_standard_libs import python_standard_libs
 
+
 # python_standard_libs is only used for membership tests.
 python_standard_libs = frozenset(python_standard_libs)
 
diff --git a/utilities/python_standard_libs.py b/utilities/python_standard_libs.py
index eb76673..dec0085 100644
--- a/utilities/python_standard_libs.py
+++ b/utilities/python_standard_libs.py
@@ -13,8 +13,12 @@ updated from time to time.
 
 # Run this to generate a new module list.
 if __name__ == '__main__':
+    from sys import (
+        stdout,
+        version_info,
+        )
+
     from lxml import html
-    from sys import version_info, stdout
     modindex_url = (
         "http://docs.python.org/release/";
         "{0}.{1}.{2}/modindex.html").format(*version_info)
diff --git a/utilities/run-as b/utilities/run-as
index 27c14b5..9df9447 100755
--- a/utilities/run-as
+++ b/utilities/run-as
@@ -10,7 +10,11 @@ inside "lxc exec".  (sudo in xenial breaks without a tty, so cannot be used
 here.)
 """
 
-from __future__ import absolute_import, print_function, unicode_literals
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
 
 import os
 import pwd
diff --git a/utilities/update-copyright b/utilities/update-copyright
index dcca9db..0a1d310 100755
--- a/utilities/update-copyright
+++ b/utilities/update-copyright
@@ -10,7 +10,10 @@ notice to reflect the current year. Looks for the notice in the first three
 lines of the file and leaves the file unchanged if it finds none.
 """
 
-from __future__ import absolute_import, print_function
+from __future__ import (
+    absolute_import,
+    print_function,
+    )
 
 from datetime import date
 import os
@@ -21,6 +24,7 @@ from subprocess import (
     )
 import sys
 
+
 # This script lives in the 'utilites' directory.
 UTILITIES_DIR = os.path.dirname(__file__)
 CURRENT_YEAR = date.today().year