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
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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]
Expand Down
28 changes: 15 additions & 13 deletions bpo_redirecter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -74,15 +76,15 @@
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
Expand All @@ -92,18 +94,18 @@
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
Expand Down Expand Up @@ -135,7 +137,7 @@
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)

Check warning on line 140 in bpo_redirecter.py

View check run for this annotation

Codecov / codecov/patch

bpo_redirecter.py#L140

Added line #L140 was not covered by tests
do_file(str(p), dry_run)
# print()

Expand Down Expand Up @@ -168,7 +170,7 @@

do_file_or_path(args.input, args.dry_run)

logging.info(redirect.cache_info())
logger.info(redirect.cache_info())


if __name__ == "__main__":
Expand Down
20 changes: 11 additions & 9 deletions upgrade_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@

USES_REGEX = re.compile(r"(- )?uses: \"?([a-z-]+/[a-z-]+)@([a-z0-9.]+)\"?")

logger = logging.getLogger(__name__)

Check warning on line 28 in upgrade_actions.py

View check run for this annotation

Codecov / codecov/patch

upgrade_actions.py#L28

Added line #L28 was not covered by tests


@cache
def get_repo_tags(repo: str) -> Iterable[str]:
url = f"https://github.com/{repo}/tags.atom"
logging.info(url)
logger.info(url)

Check warning on line 34 in upgrade_actions.py

View check run for this annotation

Codecov / codecov/patch

upgrade_actions.py#L34

Added line #L34 was not covered by tests
feed = feedparser.parse(url)
return [entry.link.split("/")[-1] for entry in feed.entries]

Expand All @@ -39,11 +41,11 @@
if old_version in ("main", "master"):
return old_version
tags = get_repo_tags(repo)
logging.info(tags)
logger.info(tags)

Check warning on line 44 in upgrade_actions.py

View check run for this annotation

Codecov / codecov/patch

upgrade_actions.py#L44

Added line #L44 was not covered by tests
same_length_tags = [tag for tag in tags if len(tag) == len(old_version)]
logging.info(same_length_tags)
logger.info(same_length_tags)

Check warning on line 46 in upgrade_actions.py

View check run for this annotation

Codecov / codecov/patch

upgrade_actions.py#L46

Added line #L46 was not covered by tests
same_length_tags.sort(reverse=True)
logging.info(same_length_tags)
logger.info(same_length_tags)

Check warning on line 48 in upgrade_actions.py

View check run for this annotation

Codecov / codecov/patch

upgrade_actions.py#L48

Added line #L48 was not covered by tests
try:
tag = same_length_tags[0]
except IndexError:
Expand Down Expand Up @@ -80,7 +82,7 @@
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)

Check warning on line 85 in upgrade_actions.py

View check run for this annotation

Codecov / codecov/patch

upgrade_actions.py#L85

Added line #L85 was not covered by tests
continue
new_version = update_tag(repo, version)
if new_version and version != new_version:
Expand Down Expand Up @@ -136,18 +138,18 @@
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__":
Expand Down