Repository-wide mechanical cleanup so `ruff check src tests` has a chance of passing; no behavioural changes. - Add `from __future__ import annotations` where PEP 604 unions are used. This has to come first: pyproject declares requires-python >= 3.9, where `X | None` is not evaluable at runtime unless annotations are stringified. - Replace typing.List/Dict/Tuple/Set with the builtin generics and Optional[X] with X | None, then drop the imports that became unused. The four actions/*/__init__.py files needed this by hand because ruff leaves unused imports in __init__.py alone (possible re-exports). - Strip shebangs from 72 importable modules. None of them are executable or invoked directly; the entry points are console_scripts and runpy. - Flatten nested `with` blocks, collapse needless-bool returns, and apply the remaining mechanical ruff fixes (PIE810, FLY002, PERF102, FURB192, RUF059, I001). - Pass check=False explicitly to the four subprocess.run() calls that inspect returncode themselves. That is the existing default. Two rewrites are visible to mocks, so their tests move with them: subprocess.run(stdout=PIPE, stderr=PIPE) became capture_output=True, and open(path, "r", ...) lost the redundant mode. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from pkgmgr.actions.mirror.io import write_mirrors_file
|
|
from pkgmgr.actions.mirror.setup_cmd import setup_mirrors
|
|
|
|
Repository = dict[str, Any]
|
|
|
|
|
|
class MirrorBootstrapper:
|
|
"""
|
|
MIRRORS is the single source of truth.
|
|
|
|
Defaults are written to MIRRORS and mirror setup derives
|
|
git remotes exclusively from that file (git URLs only).
|
|
"""
|
|
|
|
def write_defaults(
|
|
self,
|
|
*,
|
|
repo_dir: str,
|
|
primary: str,
|
|
name: str,
|
|
preview: bool,
|
|
) -> None:
|
|
mirrors = {
|
|
primary,
|
|
f"https://pypi.org/project/{name}/",
|
|
}
|
|
write_mirrors_file(repo_dir, mirrors, preview=preview)
|
|
|
|
def setup(
|
|
self,
|
|
*,
|
|
repo: Repository,
|
|
repositories_base_dir: str,
|
|
all_repos: list[Repository],
|
|
preview: bool,
|
|
remote: bool,
|
|
) -> None:
|
|
# IMPORTANT:
|
|
# Do NOT set repo["mirrors"] here.
|
|
# MIRRORS file is the single source of truth.
|
|
setup_mirrors(
|
|
selected_repos=[repo],
|
|
repositories_base_dir=repositories_base_dir,
|
|
all_repos=all_repos,
|
|
preview=preview,
|
|
local=True,
|
|
remote=True,
|
|
ensure_remote=remote,
|
|
)
|