Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .flake8

This file was deleted.

74 changes: 30 additions & 44 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,33 @@
default_language_version:
python: python3
repos:
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- id: fix-encoding-pragma
args: ["--remove"]
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-symlinks
- id: check-xml
- id: check-yaml
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
name: flake8 except __init__.py
args: [--exclude=__init__.py]
additional_dependencies: ["flake8-bugbear==20.1.4"]
- id: flake8
name: flake8 only __init__.py
args: [--extend-ignore=F401] # ignore imported unused in __init__.py
files: __init__.py
- repo: https://github.com/asottile/pyupgrade
rev: v3.18.0
hooks:
- id: pyupgrade
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: local
hooks:
# These files are most likely copier diff rejection junks; if found,
# review them manually, fix the problem (if needed) and remove them
- id: forbidden-files
name: forbidden files
entry: found forbidden files; remove them
language: fail
files: "\\.rej$"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-symlinks
- id: check-xml
- id: check-yaml
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
19 changes: 19 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

target-version = "py310"
fix = true

[lint]
extend-select = [
"B",
"C90",
"E501", # line too long (default 88)
"I", # isort
"UP", # pyupgrade
]

[lint.per-file-ignores]
"__init__.py" = ["F401", "I001"] # ignore unused and unsorted imports in __init__.py


[lint.mccabe]
max-complexity = 16
6 changes: 4 additions & 2 deletions src/oca_github_bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Copyright (c) ACSONE SA/NV 2018
# Distributed under the MIT License (http://opensource.org/licenses/MIT).

""" OCA GitHub Bot
"""OCA GitHub Bot

This is the main program, which provides the dispatching
mechanisms for webhook calls from github.
"""

import logging

import aiohttp
from aiohttp import web
from gidgethub import aiohttp as gh_aiohttp, sansio as gh_sansio
from gidgethub import aiohttp as gh_aiohttp
from gidgethub import sansio as gh_sansio

from . import config
from .router import router
Expand Down
4 changes: 2 additions & 2 deletions src/oca_github_bot/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def gh_call(func, *args, **kwargs):
message="Retry task after rate limit reset",
exc=e,
when=e.response.headers.get("X-RateLimit-Reset"),
)
) from e
raise


Expand Down Expand Up @@ -136,7 +136,7 @@ def git_push_if_needed(remote, branch, cwd=None):
raise Retry(
exc=e,
message="Retrying because a non-fast-forward git push was attempted.",
)
) from e
else:
_logger.error(
f"command {e.cmd} failed with return code {e.returncode} "
Expand Down
5 changes: 2 additions & 3 deletions src/oca_github_bot/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import os
import re
from typing import Tuple

import requests

Expand Down Expand Up @@ -218,7 +217,7 @@ def get_odoo_series_from_version(version):
return tuple(int(s) for s in series.split("."))


def get_odoo_series_from_branch(branch) -> Tuple[int, int]:
def get_odoo_series_from_branch(branch) -> tuple[int, int]:
mo = BRANCH_RE.match(branch)
if not mo:
raise OdooSeriesNotDetected()
Expand Down Expand Up @@ -278,7 +277,7 @@ def is_maintainer_other_branches(org, repo, username, modified_addons, other_bra
url = (
f"https://github.com/{org}/{repo}/raw/{branch}/{addon}/{manifest_file}"
)
_logger.debug("Looking for maintainers in %s" % url)
_logger.debug("Looking for maintainers in %s", url)
r = requests.get(
url, allow_redirects=True, headers={"Cache-Control": "no-cache"}
)
Expand Down
4 changes: 2 additions & 2 deletions src/oca_github_bot/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def check_call(cmd, cwd, log_error=True, extra_cmd_args=False, env=None):
cmd += extra_cmd_args
cp = subprocess.run(
cmd,
universal_newlines=True,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=cwd,
Expand All @@ -34,7 +34,7 @@ def check_call(cmd, cwd, log_error=True, extra_cmd_args=False, env=None):
def check_output(cmd, cwd, log_error=True):
cp = subprocess.run(
cmd,
universal_newlines=True,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=cwd,
Expand Down
5 changes: 3 additions & 2 deletions src/oca_github_bot/pypi.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Copyright (c) ACSONE SA/NV 2021
# Distributed under the MIT License (http://opensource.org/licenses/MIT).
"""Utilities to work with PEP 503 package indexes."""

import logging
import os
from collections.abc import Iterator
from io import StringIO
from pathlib import PosixPath
from subprocess import CalledProcessError
from typing import Iterator, Optional, Tuple
from urllib.parse import urljoin, urlparse

import requests
Expand All @@ -19,7 +20,7 @@

def files_on_index(
index_url: str, project_name: str
) -> Iterator[Tuple[str, Optional[Tuple[str, str]]]]:
) -> Iterator[tuple[str, tuple[str, str] | None]]:
"""Iterate files available on an index for a given project name."""
project_name = project_name.replace("_", "-")
base_url = urljoin(index_url, project_name + "/")
Expand Down
2 changes: 1 addition & 1 deletion src/oca_github_bot/tasks/migration_issue_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _find_issue(gh_repo, milestone, target_branch):

def _check_line_issue(gh_pr_number, issue_body):
lines = []
regex = r"\#%s\b" % gh_pr_number
regex = rf"\#{gh_pr_number}\b"
for line in issue_body.split("\n"):
if re.findall(regex, line):
checked_line = line.replace("[ ]", "[x]", 1)
Expand Down
2 changes: 1 addition & 1 deletion src/oca_github_bot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import shlex
import time
from typing import Sequence
from collections.abc import Sequence

from . import config

Expand Down
6 changes: 2 additions & 4 deletions tests/test_build_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ def _make_addon(
(addon_dir / "__init__.py").write_text("")
if pyproject:
(addon_dir / "pyproject.toml").write_text(
textwrap.dedent(
"""\
textwrap.dedent("""\
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
"""
)
""")
)
subprocess.check_call(["git", "add", addon_name], cwd=addons_dir)
subprocess.check_call(
Expand Down
10 changes: 3 additions & 7 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def test_parse_command_not_a_command():

def test_parse_command_multi():
cmds = list(
parse_commands(
"""
parse_commands("""
...
/ocabot merge major
/ocabot merge patch
Expand All @@ -33,8 +32,7 @@ def test_parse_command_multi():
/ocabot merge minor # ignored
/ocabot rebase, please
...
"""
)
""")
)
assert [(cmd.name, cmd.options) for cmd in cmds] == [
("merge", ["major"]),
Expand Down Expand Up @@ -100,9 +98,7 @@ def test_parse_command_comment():
> Some comment {merge_command}
>> Double comment! {merge_command}
This is the one {merge_command} patch
""".format(
merge_command="/ocabot merge"
)
""".format(merge_command="/ocabot merge")
command = list(parse_commands(body))
assert len(command) == 1
command = command[0]
Expand Down
Loading