From a6235d3d0d39da2858f1e97bdb86553064a7672f Mon Sep 17 00:00:00 2001 From: Anselm Hahn Date: Sat, 27 Jun 2026 11:50:19 +0200 Subject: [PATCH] feat: replace mirror.py + versions.py with repo-release-tools v1.10.1 sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upgrades the mirror pipeline to use `rrt sync --bump --commit --tag`, which handles PyPI polling, file updates, commits, and tagging in a single call — eliminating both mirror.py and versions.py entirely. Adds [tool.rrt.upstream] config (package = "ruff", provider = "pypi") so rrt can discover newer ruff releases autonomously. Closes #171 follow-up: the TOML rev pattern regression is also covered by the rrt pin_targets config introduced in the previous commit. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/main.yml | 5 ++- mirror.py | 85 -------------------------------------- pyproject.toml | 31 ++++++++++++++ 3 files changed, 35 insertions(+), 86 deletions(-) delete mode 100644 mirror.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c8fc3b8..2459ff0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,10 @@ jobs: git config user.name "$GITHUB_ACTOR" git config user.email "$GITHUB_ACTOR@users.noreply.github.com" - - run: uv run --no-project mirror.py + - name: Mirror new ruff versions + run: uvx "repo-release-tools==$RRT_VERSION" sync --bump --commit --tag + env: + RRT_VERSION: "1.10.1" - name: check for unpushed commits id: check_unpushed diff --git a/mirror.py b/mirror.py deleted file mode 100644 index ad1cbc6..0000000 --- a/mirror.py +++ /dev/null @@ -1,85 +0,0 @@ -# /// script -# requires-python = ">=3.12" -# dependencies = [ -# "packaging==23.1", -# "urllib3==2.0.5", -# ] -# /// -"""Update ruff-pre-commit to the latest version of ruff.""" - -import re -import subprocess -import tomllib -import typing -from pathlib import Path - -import urllib3 -from packaging.requirements import Requirement -from packaging.version import Version - - -def main(): - with open(Path(__file__).parent / "pyproject.toml", "rb") as f: - pyproject = tomllib.load(f) - - all_versions = get_all_versions() - current_version = get_current_version(pyproject=pyproject) - target_versions = [v for v in all_versions if v > current_version] - - for version in target_versions: - paths = process_version(version) - if subprocess.check_output(["git", "status", "-s"]).strip(): - subprocess.run(["git", "add", *paths], check=True) - subprocess.run(["git", "commit", "-m", f"Mirror: {version}"], check=True) - subprocess.run(["git", "tag", f"v{version}"], check=True) - else: - print(f"No change v{version}") - - -def get_all_versions() -> list[Version]: - response = urllib3.request("GET", "https://pypi.org/pypi/ruff/json") - if response.status != 200: - raise RuntimeError("Failed to fetch versions from pypi") - - versions = [Version(release) for release in response.json()["releases"]] - return sorted(versions) - - -def get_current_version(pyproject: dict) -> Version: - requirements = [Requirement(d) for d in pyproject["project"]["dependencies"]] - requirement = next((r for r in requirements if r.name == "ruff"), None) - assert requirement is not None, "pyproject.toml does not have ruff requirement" - - specifiers = list(requirement.specifier) - assert ( - len(specifiers) == 1 and specifiers[0].operator == "==" - ), f"ruff's specifier should be exact matching, but `{requirement}`" - - return Version(specifiers[0].version) - - -def process_version(version: Version) -> typing.Sequence[str]: - def replace_pyproject_toml(content: str) -> str: - return re.sub(r'"ruff==.*"', f'"ruff=={version}"', content) - - def replace_readme_md(content: str) -> str: - content = re.sub(r"rev: v\d+\.\d+\.\d+", f"rev: v{version}", content) - content = re.sub(r'rev = "v\d+\.\d+\.\d+"', f'rev = "v{version}"', content) - return re.sub(r"/ruff/\d+\.\d+\.\d+\.svg", f"/ruff/{version}.svg", content) - - paths = { - "pyproject.toml": replace_pyproject_toml, - "README.md": replace_readme_md, - } - - for path, replacer in paths.items(): - with open(path) as f: - content = replacer(f.read()) - with open(path, mode="w") as f: - f.write(content) - - return tuple(paths.keys()) - - -if __name__ == "__main__": - main() diff --git a/pyproject.toml b/pyproject.toml index dec469d..98d68ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,3 +4,34 @@ version = "0.0.0" dependencies = [ "ruff==0.15.20", ] + +[dependency-groups] +dev = [ + "repo-release-tools>=1.10.1", +] + +[tool.rrt] +release_branch = "main" +lock_command = [] + +[tool.rrt.upstream] +package = "ruff" +provider = "pypi" +commit_message = "Mirror: {version}" + +[[tool.rrt.version_targets]] +path = "pyproject.toml" +kind = "pattern" +pattern = 'ruff==(\d+\.\d+\.\d+)' + +[[tool.rrt.pin_targets]] +path = "README.md" +pattern = '(rev: v)(\d+\.\d+\.\d+)()' + +[[tool.rrt.pin_targets]] +path = "README.md" +pattern = '(rev = "v)(\d+\.\d+\.\d+)(")' + +[[tool.rrt.pin_targets]] +path = "README.md" +pattern = '(/ruff/)(\d+\.\d+\.\d+)(\.svg)'