From b89d61d5756e28af1d0cbaa10e7c9a698a544fd5 Mon Sep 17 00:00:00 2001 From: Max R Date: Sun, 29 Nov 2026 13:23:26 -0500 Subject: [PATCH] Use base's lockstep mirror engine --- .github/base.yml | 7 ++- .../workflows/{bump-pyright.yml => bump.yml} | 12 +++-- .pre-commit-config.yaml | 1 + testing/__init__.py | 1 + testing/try_repo.py | 42 +++++++++++++++++ tests/try_repo_test.py | 46 ++++--------------- 6 files changed, 66 insertions(+), 43 deletions(-) rename .github/workflows/{bump-pyright.yml => bump.yml} (74%) create mode 100644 testing/__init__.py create mode 100644 testing/try_repo.py diff --git a/.github/base.yml b/.github/base.yml index 873e913..35f86e2 100644 --- a/.github/base.yml +++ b/.github/base.yml @@ -1,5 +1,10 @@ -stack: [python] +stack: [mirror, python] opt: + mirror: + engine: lockstep + package: pyright + registry: npm + version-file: pyright_pre_commit/__init__.py python: min-version: '3.11' custom-managers: true diff --git a/.github/workflows/bump-pyright.yml b/.github/workflows/bump.yml similarity index 74% rename from .github/workflows/bump-pyright.yml rename to .github/workflows/bump.yml index 9428613..33f8473 100644 --- a/.github/workflows/bump-pyright.yml +++ b/.github/workflows/bump.yml @@ -1,9 +1,11 @@ -name: bump-pyright +# ~~ Generated by projen in mxr/base. Modifications will be overwritten on the next sync. To modify properly, edit .github/base.yml and retrigger the propagate workflow in mxr/base. + +name: bump on: schedule: - cron: 15 8 * * * - workflow_dispatch: + workflow_dispatch: {} permissions: {} @@ -19,7 +21,7 @@ jobs: - name: Check for new pyright version id: check run: | - current="$(grep -oP '__version__ = "\K[^"]+' pyright_pre_commit/__init__.py)" + current="$(grep -oP '^__version__ = "\K[^"]+' pyright_pre_commit/__init__.py)" latest="$(curl -sSf https://registry.npmjs.org/pyright/latest | jq -r .version)" echo "current=$current" >> "$GITHUB_OUTPUT" echo "latest=$latest" >> "$GITHUB_OUTPUT" @@ -32,8 +34,8 @@ jobs: CURRENT: ${{ steps.check.outputs.current }} LATEST: ${{ steps.check.outputs.latest }} GH_TOKEN: ${{ secrets.MIRROR_PUSH_TOKEN }} - run: | - sed -i "s/__version__ = \"$CURRENT\"/__version__ = \"$LATEST\"/" pyright_pre_commit/__init__.py + run: |- + sed -i "s/^__version__ = \"$CURRENT\"/__version__ = \"$LATEST\"/" pyright_pre_commit/__init__.py git config user.name 'Github Actions' git config user.email '41898282+github-actions[bot]@users.noreply.github.com' git commit pyright_pre_commit/__init__.py -m "pyright $LATEST" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 03f51d7..2e0f227 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,6 +22,7 @@ repos: hooks: - id: pretty-format-yaml args: [--autofix] + exclude: ^(\.pre-commit-hooks\.yaml)$ - repo: https://github.com/mxr/mirrors-ty rev: 01aac24b89157f044c74bc32d90456df0de87873 # frozen: v0.0.108 hooks: diff --git a/testing/__init__.py b/testing/__init__.py new file mode 100644 index 0000000..59ffeca --- /dev/null +++ b/testing/__init__.py @@ -0,0 +1 @@ +# ~~ Generated by projen in mxr/base. Modifications will be overwritten on the next sync. To modify properly, edit .github/base.yml and retrigger the propagate workflow in mxr/base. diff --git a/testing/try_repo.py b/testing/try_repo.py new file mode 100644 index 0000000..b711b46 --- /dev/null +++ b/testing/try_repo.py @@ -0,0 +1,42 @@ +# ~~ Generated by projen in mxr/base. Modifications will be overwritten on the next sync. To modify properly, edit .github/base.yml and retrigger the propagate workflow in mxr/base. + + +from __future__ import annotations + +import os +import subprocess +import sys +import tempfile +from pathlib import Path + +REPO_ROOT = Path(__file__).parent.parent + + +def try_repo( + hook_id: str, files: dict[str, str], tmp_path: Path +) -> subprocess.CompletedProcess[str]: + """Runs `pre-commit try-repo` on this repo's `hook_id` in a new git repo that holds `files`. stdout has stderr merged in.""" + # pre-commit relpaths the repo against cwd, which fails across Windows drives + with tempfile.TemporaryDirectory(dir=REPO_ROOT) as d: + target = Path(d) + for name, content in files.items(): + (target / name).write_text(content) + subprocess.check_call(("git", "init", "-q", str(target))) + subprocess.check_call(("git", "-C", str(target), "add", *files)) + return subprocess.run( + ( + sys.executable, + "-m", + "pre_commit", + "try-repo", + str(REPO_ROOT), + hook_id, + "--all-files", + ), + check=False, + cwd=target, + env={**os.environ, "PRE_COMMIT_HOME": str(tmp_path / "pre-commit-home")}, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True, + ) diff --git a/tests/try_repo_test.py b/tests/try_repo_test.py index a51b932..cffb516 100644 --- a/tests/try_repo_test.py +++ b/tests/try_repo_test.py @@ -1,42 +1,14 @@ from __future__ import annotations -import os -import subprocess -import sys -import tempfile -from pathlib import Path - -REPO_ROOT = Path(__file__).parent.parent +from testing.try_repo import try_repo def test_try_repo(tmp_path): - # pre-commit relpaths the repo against cwd, which fails across Windows drives - with tempfile.TemporaryDirectory(dir=REPO_ROOT) as d: - target = Path(d) - (target / "good.py").write_text("x: int = 1\n") - (target / "bad.py").write_text('x: int = "a"\n') - subprocess.check_call(("git", "init", "-q", str(target))) - subprocess.check_call(("git", "-C", str(target), "add", "good.py", "bad.py")) - - proc = subprocess.run( - ( - sys.executable, - "-m", - "pre_commit", - "try-repo", - str(REPO_ROOT), - "pyright", - "--all-files", - ), - check=False, - cwd=target, - env={**os.environ, "PRE_COMMIT_HOME": str(tmp_path / "pre-commit-home")}, - capture_output=True, - text=True, - ) - output = proc.stdout + proc.stderr - - assert proc.returncode == 1, output - assert "bad.py:1:10 - error" in output - assert "good.py:" not in output - assert "1 error, 0 warnings" in output + proc = try_repo( + "pyright", {"good.py": "x: int = 1\n", "bad.py": 'x: int = "a"\n'}, tmp_path + ) + + assert proc.returncode == 1, proc.stdout + assert "bad.py:1:10 - error" in proc.stdout + assert "good.py:" not in proc.stdout + assert "1 error, 0 warnings" in proc.stdout