diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ff61df7..15266b1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,13 +2,14 @@ default_language_version: python: python3 repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v5.0.0 hooks: - id: check-toml - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/PyCQA/flake8 - rev: "3.9.2" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.0 hooks: - - id: flake8 + - id: ruff + args: [--fix] diff --git a/git_aggregator/__init__.py b/git_aggregator/__init__.py index 77ab94a..b868204 100644 --- a/git_aggregator/__init__.py +++ b/git_aggregator/__init__.py @@ -1,3 +1,2 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) diff --git a/git_aggregator/_compat.py b/git_aggregator/_compat.py index 9a4f757..678ac5e 100644 --- a/git_aggregator/_compat.py +++ b/git_aggregator/_compat.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) import sys diff --git a/git_aggregator/config.py b/git_aggregator/config.py index 0043e84..1f95b66 100644 --- a/git_aggregator/config.py +++ b/git_aggregator/config.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) @@ -8,9 +7,8 @@ import yaml -from .exception import ConfigException from ._compat import string_types - +from .exception import ConfigException log = logging.getLogger(__name__) @@ -167,11 +165,11 @@ def load_config(config, expand_env=False, env_file=None, force=False): key, value = line.split('=') environment.update({key.strip(): value.strip()}) environment.update(os.environ) - with open(config, 'r') as file_handler: + with open(config) as file_handler: config = Template(file_handler.read()) config = config.substitute(environment) else: - config = open(config, 'r').read() + config = open(config).read() conf = yaml.load(config, Loader=yaml.SafeLoader) diff --git a/git_aggregator/exception.py b/git_aggregator/exception.py index 86d6a94..0f25940 100644 --- a/git_aggregator/exception.py +++ b/git_aggregator/exception.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) diff --git a/git_aggregator/log.py b/git_aggregator/log.py index c1cfe0e..5219ce0 100644 --- a/git_aggregator/log.py +++ b/git_aggregator/log.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) diff --git a/git_aggregator/main.py b/git_aggregator/main.py index 146ddcf..1c922a6 100644 --- a/git_aggregator/main.py +++ b/git_aggregator/main.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015-2019 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) @@ -7,22 +6,24 @@ import sys import threading import traceback + try: - from Queue import Queue, Empty as EmptyQueue + from Queue import Empty as EmptyQueue + from Queue import Queue except ImportError: - from queue import Queue, Empty as EmptyQueue + from queue import Empty as EmptyQueue + from queue import Queue import argparse +import fnmatch + import argcomplete import colorama -import fnmatch -from .utils import ThreadNameKeeper -from .log import DebugLogFormatter -from .log import LogFormatter from .config import load_config +from .log import DebugLogFormatter, LogFormatter from .repo import Repo - +from .utils import ThreadNameKeeper logger = logging.getLogger(__name__) @@ -31,8 +32,7 @@ def _log_level_string_to_int(log_level_string): if log_level_string not in _LOG_LEVEL_STRINGS: - message = 'invalid choice: {0} (choose from {1})'.format( - log_level_string, _LOG_LEVEL_STRINGS) + message = f'invalid choice: {log_level_string} (choose from {_LOG_LEVEL_STRINGS})' raise argparse.ArgumentTypeError(message) log_level_int = getattr(logging, log_level_string, logging.INFO) @@ -99,7 +99,7 @@ def get_parser(): dest='log_level', type=_log_level_string_to_int, nargs='?', - help='Set the logging output level. {0}'.format(_LOG_LEVEL_STRINGS)) + help=f'Set the logging output level. {_LOG_LEVEL_STRINGS}') main_parser.add_argument( '-e', '--expand-env', diff --git a/git_aggregator/repo.py b/git_aggregator/repo.py index 27d623d..0656b89 100644 --- a/git_aggregator/repo.py +++ b/git_aggregator/repo.py @@ -1,18 +1,16 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) # Parts of the code comes from ANYBOX # https://github.com/anybox/anybox.recipe.odoo -from __future__ import unicode_literals -import os import logging +import os import re import subprocess import requests -from .exception import DirtyException, GitAggregatorException from ._compat import console_to_str +from .exception import DirtyException, GitAggregatorException FETCH_DEFAULTS = ("depth", "shallow-since", "shallow-exclude") logger = logging.getLogger(__name__) @@ -32,7 +30,7 @@ def ishex(s): return True -class Repo(object): +class Repo: _git_version = None diff --git a/git_aggregator/utils.py b/git_aggregator/utils.py index 063e787..1ecbb89 100644 --- a/git_aggregator/utils.py +++ b/git_aggregator/utils.py @@ -1,14 +1,14 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # © ANYBOX https://github.com/anybox/anybox.recipe.odoo # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) +import logging import os import threading -import logging + logger = logging.getLogger(__name__) -class WorkingDirectoryKeeper(object): # DEPRECATED +class WorkingDirectoryKeeper: # DEPRECATED """A context manager to get back the working directory as it was before. If you want to stack working directory keepers, you need a new instance for each stage. @@ -30,7 +30,7 @@ def __exit__(self, *exc_args): working_directory_keeper = WorkingDirectoryKeeper() -class ThreadNameKeeper(object): +class ThreadNameKeeper: """A contect manager to get back the thread name as it was before. It is meant to be used when modifying the 'MainThread' tread. """ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5c98ac7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.ruff] +fix = true +line-length = 79 + +[tool.ruff.lint] +extend-select = [ + "I", + "UP", +] +ignore = [ + "UP031", # % formatting +] + +[tool.ruff.lint.isort] +known-first-party = ["git_aggregator"] diff --git a/setup.py b/setup.py index d02c992..2013ddd 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) diff --git a/tests/__init__.py b/tests/__init__.py index 77ab94a..b868204 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +1,2 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) diff --git a/tests/test_config.py b/tests/test_config.py index 0c9fa50..ab2eba2 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) import os @@ -9,8 +8,8 @@ import yaml from git_aggregator import config -from git_aggregator.exception import ConfigException from git_aggregator._compat import PY2 +from git_aggregator.exception import ConfigException class TestConfig(unittest.TestCase): diff --git a/tests/test_log.py b/tests/test_log.py index b588e2a..ef4a849 100644 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) import logging @@ -20,7 +19,7 @@ class TestLog(unittest.TestCase): def setUp(self): """ Setup """ - super(TestLog, self).setUp() + super().setUp() reset_logger() def test_info(self): diff --git a/tests/test_repo.py b/tests/test_repo.py index c974449..91c303e 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) # Parts of the code comes from ANYBOX @@ -6,12 +5,14 @@ import argparse import os import shutil -import unittest import subprocess +import unittest + try: # Py 2 - from urlparse import urljoin from urllib import pathname2url + + from urlparse import urljoin except ImportError: # PY 3 from urllib.parse import urljoin @@ -20,11 +21,12 @@ from tempfile import mkdtemp from textwrap import dedent - -from git_aggregator.utils import WorkingDirectoryKeeper,\ - working_directory_keeper -from git_aggregator.repo import Repo from git_aggregator import exception, main +from git_aggregator.repo import Repo +from git_aggregator.utils import ( + WorkingDirectoryKeeper, + working_directory_keeper, +) def git_get_last_rev(repo_dir): @@ -65,7 +67,7 @@ class TestRepo(unittest.TestCase): @classmethod def setUpClass(cls): main.setup_logger(level=logging.DEBUG) - super(TestRepo, cls).setUpClass() + super().setUpClass() def setUp(self): """ Setup @@ -79,7 +81,7 @@ def setUp(self): commit 3 branch b2 """ - super(TestRepo, self).setUp() + super().setUp() sandbox = self.sandbox = mkdtemp('test_repo') with working_directory_keeper: os.chdir(sandbox)