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
7 changes: 6 additions & 1 deletion .github/base.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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: {}

Expand All @@ -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"
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions testing/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 42 additions & 0 deletions testing/try_repo.py
Original file line number Diff line number Diff line change
@@ -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,
)
46 changes: 9 additions & 37 deletions tests/try_repo_test.py
Original file line number Diff line number Diff line change
@@ -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