Skip to content

Commit

Permalink
Merge pull request #84 from acsone/pre-commit-sbi
Browse files Browse the repository at this point in the history
A little bit of modernization
  • Loading branch information
sbidoul authored Oct 23, 2024
2 parents 8288ebf + a0dcb3f commit d56c051
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 48 deletions.
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1 change: 0 additions & 1 deletion git_aggregator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
# © 2015 ACSONE SA/NV
# License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html)
1 change: 0 additions & 1 deletion git_aggregator/_compat.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 3 additions & 5 deletions git_aggregator/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2015 ACSONE SA/NV
# License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html)

Expand All @@ -8,9 +7,8 @@

import yaml

from .exception import ConfigException
from ._compat import string_types

from .exception import ConfigException

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion git_aggregator/exception.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2015 ACSONE SA/NV
# License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html)

Expand Down
1 change: 0 additions & 1 deletion git_aggregator/log.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2015 ACSONE SA/NV
# License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html)

Expand Down
22 changes: 11 additions & 11 deletions git_aggregator/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2015-2019 ACSONE SA/NV
# License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html)

Expand All @@ -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__)

Expand All @@ -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)
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 3 additions & 5 deletions git_aggregator/repo.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand All @@ -32,7 +30,7 @@ def ishex(s):
return True


class Repo(object):
class Repo:

_git_version = None

Expand Down
8 changes: 4 additions & 4 deletions git_aggregator/utils.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
"""
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2015 ACSONE SA/NV
# License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html)

Expand Down
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
# © 2015 ACSONE SA/NV
# License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html)
3 changes: 1 addition & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_log.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html)

import logging
Expand All @@ -20,7 +19,7 @@ class TestLog(unittest.TestCase):

def setUp(self):
""" Setup """
super(TestLog, self).setUp()
super().setUp()
reset_logger()

def test_info(self):
Expand Down
20 changes: 11 additions & 9 deletions tests/test_repo.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# -*- 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
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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit d56c051

Please sign in to comment.