diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8145fe7..9c2da9a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,6 +28,7 @@ repos: - id: ty additional_dependencies: - coverage + - pre-commit - pytest - types-setuptools - typing_extensions; python_version < '3.12' @@ -37,6 +38,7 @@ repos: - id: pyright additional_dependencies: - coverage + - pre-commit - pytest - types-setuptools - typing_extensions; python_version < '3.12' @@ -50,6 +52,7 @@ repos: - id: mypy additional_dependencies: - coverage + - pre-commit - pytest - types-setuptools - typing_extensions; python_version < '3.12' diff --git a/pyproject.toml b/pyproject.toml index 615112b..852edb3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ pyright = "pyright_pre_commit.__main__:main" dev = [ "covdefaults>=2.1.0", "coverage", + "pre-commit", "pytest", ] diff --git a/tests/try_repo_test.py b/tests/try_repo_test.py new file mode 100644 index 0000000..a51b932 --- /dev/null +++ b/tests/try_repo_test.py @@ -0,0 +1,42 @@ +from __future__ import annotations + +import os +import subprocess +import sys +import tempfile +from pathlib import Path + +REPO_ROOT = Path(__file__).parent.parent + + +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