diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 92b0c1f..d5bc17d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,12 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.11.4 hooks: - id: ruff args: [--exit-non-zero-on-fix] - repo: https://github.com/psf/black-pre-commit-mirror - rev: 24.10.0 + rev: 25.1.0 hooks: - id: black args: [--target-version=py311] @@ -25,22 +25,22 @@ repos: - id: trailing-whitespace - repo: https://github.com/tox-dev/pyproject-fmt - rev: v2.5.0 + rev: v2.5.1 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.23 + rev: v0.24.1 hooks: - id: validate-pyproject - repo: https://github.com/tox-dev/tox-ini-fmt - rev: 1.4.1 + rev: 1.5.0 hooks: - id: tox-ini-fmt - repo: https://github.com/rbubley/mirrors-prettier - rev: v3.4.2 + rev: v3.5.3 hooks: - id: prettier args: [--prose-wrap=always, --print-width=88] diff --git a/bpo_redirecter.py b/bpo_redirecter.py index 608c21f..106c66f 100755 --- a/bpo_redirecter.py +++ b/bpo_redirecter.py @@ -33,13 +33,15 @@ # :issue:`45440` BPO_ROLE_REGEX = re.compile(r":issue:`(\d+)`") +logger = logging.getLogger(__name__) + @cache def redirect(client: httpx.Client, bpo_number: int) -> str: redirect_link = f"https://bugs.python.org/issue?@action=redirect&bpo={bpo_number}" - logging.info("Redirect link:\t%s", redirect_link) + logger.info("Redirect link:\t%s", redirect_link) r = client.get(redirect_link, follow_redirects=True) - logging.info("GitHub link:\t%s", r.url) + logger.info("GitHub link:\t%s", r.url) return str(r.url) @@ -74,15 +76,15 @@ def do_lines(old_lines: list[str], filename: str) -> list[str]: ms = BPO_URL_REGEX.findall(line.strip()) new_line = line for m in ms: - logging.info("Old line:\t%s", line.rstrip()) + logger.info("Old line:\t%s", line.rstrip()) # bpo_link = f"https://bugs.python.org/issue{m}" - # logging.info("BPO link:\t%s", bpo_link) + # logger.info("BPO link:\t%s", bpo_link) bpo_number = int(m) - logging.info("BPO number:\t%d", bpo_number) + logger.info("BPO number:\t%d", bpo_number) gh_link = redirect(client, bpo_number) new_line = BPO_URL_REGEX.sub(gh_link, new_line, count=1) - logging.info("New line:\t%s", new_line.rstrip()) + logger.info("New line:\t%s", new_line.rstrip()) if line != new_line: changes += 1 @@ -92,18 +94,18 @@ def do_lines(old_lines: list[str], filename: str) -> list[str]: ms = BPO_ROLE_REGEX.findall(line.strip()) new_line = line for m in ms: - logging.info("Old line:\t%s", line.rstrip()) + logger.info("Old line:\t%s", line.rstrip()) # bpo_role = f":issue:`{m}`" - # logging.info("BPO link:\t%s", bpo_role) + # logger.info("BPO link:\t%s", bpo_role) bpo_number = int(m) - logging.info("BPO number:\t%d", bpo_number) + logger.info("BPO number:\t%d", bpo_number) gh_link = redirect(client, bpo_number) gh_number = gh_link.split("/")[-1] new_role = f":gh:`{gh_number}`" - logging.info("New role:\t%s", new_role) + logger.info("New role:\t%s", new_role) new_line = BPO_ROLE_REGEX.sub(new_role, new_line, count=1) - logging.info("New line:\t%s", new_line.rstrip()) + logger.info("New line:\t%s", new_line.rstrip()) if line != new_line: changes += 1 @@ -135,7 +137,7 @@ def do_file_or_path(file_or_path: str, dry_run: bool = False) -> None: else: for p in sorted(Path(file_or_path).rglob("*")): if p.suffix in (".py", ".rst", ".txt") and p.is_file(): - logging.info(p) + logger.info(p) do_file(str(p), dry_run) # print() @@ -168,7 +170,7 @@ def main() -> None: do_file_or_path(args.input, args.dry_run) - logging.info(redirect.cache_info()) + logger.info(redirect.cache_info()) if __name__ == "__main__": diff --git a/upgrade_actions.py b/upgrade_actions.py index 30a2dce..f5af5fb 100644 --- a/upgrade_actions.py +++ b/upgrade_actions.py @@ -25,11 +25,13 @@ USES_REGEX = re.compile(r"(- )?uses: \"?([a-z-]+/[a-z-]+)@([a-z0-9.]+)\"?") +logger = logging.getLogger(__name__) + @cache def get_repo_tags(repo: str) -> Iterable[str]: url = f"https://github.com/{repo}/tags.atom" - logging.info(url) + logger.info(url) feed = feedparser.parse(url) return [entry.link.split("/")[-1] for entry in feed.entries] @@ -39,11 +41,11 @@ def update_tag(repo: str, old_version: str) -> str: if old_version in ("main", "master"): return old_version tags = get_repo_tags(repo) - logging.info(tags) + logger.info(tags) same_length_tags = [tag for tag in tags if len(tag) == len(old_version)] - logging.info(same_length_tags) + logger.info(same_length_tags) same_length_tags.sort(reverse=True) - logging.info(same_length_tags) + logger.info(same_length_tags) try: tag = same_length_tags[0] except IndexError: @@ -80,7 +82,7 @@ def do_file(filename: str, dry_run: bool) -> None: version = m[3] if repo == "pypa/gh-action-pypi-publish" and version == "release": new_lines.append(line) - logging.info("%s's '%s' is a branch not tag, skipping", repo, version) + logger.info("%s's '%s' is a branch not tag, skipping", repo, version) continue new_version = update_tag(repo, version) if new_version and version != new_version: @@ -136,18 +138,18 @@ def main() -> None: level=args.loglevel, format="%(message)s", handlers=[RichHandler()] ) else: - logging.basicConfig(level=args.loglevel, format="%(message)s") + logger.basicConfig(level=args.loglevel, format="%(message)s") if os.path.isfile(args.input): do_file(args.input, args.dry_run) else: for path in Path(args.input).rglob("*.y*ml"): - logging.info(path) + logger.info(path) do_file(str(path), args.dry_run) print() - logging.info("update_tag:\t%s", update_tag.cache_info()) - logging.info("get_repo_tags:\t%s", get_repo_tags.cache_info()) + logger.info("update_tag:\t%s", update_tag.cache_info()) + logger.info("get_repo_tags:\t%s", get_repo_tags.cache_info()) if __name__ == "__main__":