pre-commit-uv
Advanced tools
+2
-2
@@ -1,4 +0,4 @@ | ||
| Metadata-Version: 2.3 | ||
| Metadata-Version: 2.4 | ||
| Name: pre-commit-uv | ||
| Version: 4.1.4 | ||
| Version: 4.1.5 | ||
| Summary: Run pre-commit with uv | ||
@@ -5,0 +5,0 @@ Project-URL: Bug Tracker, https://github.com/tox-dev/pre-commit-uv/issues |
@@ -62,5 +62,8 @@ """Package root.""" | ||
| from pre_commit.git import get_root # noqa: PLC0415 | ||
| from pre_commit.lang_base import environment_dir, setup_cmd # noqa: PLC0415 | ||
| from pre_commit.util import cmd_output_b # noqa: PLC0415 | ||
| project_root_dir = get_root() | ||
| logger = logging.getLogger("pre_commit") | ||
@@ -70,7 +73,26 @@ logger.info("Using pre-commit with uv %s via pre-commit-uv %s", uv_version(), self_version()) | ||
| py = python.norm_version(version) or os.environ.get("UV_PYTHON", sys.executable) | ||
| venv_cmd = [uv, "venv", environment_dir(prefix, python.ENVIRONMENT_DIR, version), "-p", py] | ||
| venv_cmd = [ | ||
| uv, | ||
| "--project", | ||
| project_root_dir, | ||
| "venv", | ||
| environment_dir(prefix, python.ENVIRONMENT_DIR, version), | ||
| "-p", | ||
| py, | ||
| ] | ||
| cmd_output_b(*venv_cmd, cwd="/") | ||
| with python.in_env(prefix, version): | ||
| setup_cmd(prefix, (uv, "pip", "install", ".", *additional_dependencies)) | ||
| setup_cmd( | ||
| prefix, | ||
| ( | ||
| uv, | ||
| "--project", | ||
| project_root_dir, | ||
| "pip", | ||
| "install", | ||
| ".", | ||
| *additional_dependencies, | ||
| ), | ||
| ) | ||
@@ -101,3 +123,3 @@ @cache | ||
| try: | ||
| return cast(str, cmd_output(exe, "-S", "-c", prog)[1].strip()) | ||
| return cast("str", cmd_output(exe, "-S", "-c", prog)[1].strip()) | ||
| except CalledProcessError: | ||
@@ -109,2 +131,2 @@ return f"<<error retrieving version from {exe}>>" | ||
| assert _original_main is not None # noqa: S101 | ||
| return cast(int, _original_main(argv)) | ||
| return cast("int", _original_main(argv)) |
+94
-0
@@ -69,1 +69,95 @@ from __future__ import annotations | ||
| ] | ||
| test_install_with_uv_config_cases: list[tuple[str, str]] = [ | ||
| ( | ||
| "pyproject.toml", | ||
| """ | ||
| [[tool.uv.index]] | ||
| name = "internal" | ||
| url = "https://pypi.org/simple/" | ||
| default = true | ||
| """, | ||
| ), | ||
| ( | ||
| "uv.toml", | ||
| """ | ||
| [[index]] | ||
| name = "internal" | ||
| url = "https://pypi.org/simple/" | ||
| default = true | ||
| """, | ||
| ), | ||
| ] | ||
| @pytest.mark.parametrize( | ||
| ("file_name", "content"), | ||
| test_install_with_uv_config_cases, | ||
| ) | ||
| def test_install_with_uv_config( | ||
| git_repo: Path, | ||
| caplog: pytest.LogCaptureFixture, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| file_name: str, | ||
| content: str, | ||
| ) -> None: | ||
| (git_repo / file_name).write_text(dedent(content)) | ||
| monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1") | ||
| import pre_commit_uv # noqa: PLC0415 | ||
| pre_commit_uv._patch() # noqa: SLF001 | ||
| main.main(["install-hooks", "-c", str(git_repo / precommit_file)]) | ||
| assert caplog.messages == [ | ||
| "Initializing environment for https://github.com/tox-dev/pyproject-fmt.", | ||
| "Installing environment for https://github.com/tox-dev/pyproject-fmt.", | ||
| "Once installed this environment will be reused.", | ||
| "This may take a few minutes...", | ||
| f"Using pre-commit with uv {uv} via pre-commit-uv {self}", | ||
| ] | ||
| test_install_with_uv_config_raises_error_cases: list[tuple[str, str]] = [ | ||
| ( | ||
| "pyproject.toml", | ||
| """ | ||
| [[tool.uv.index]] | ||
| name = "internal" | ||
| url = "https://pypi.example/simple/" | ||
| default = true | ||
| """, | ||
| ), | ||
| ( | ||
| "uv.toml", | ||
| """ | ||
| [[index]] | ||
| name = "internal" | ||
| url = "https://pypi.example/simple/" | ||
| default = true | ||
| """, | ||
| ), | ||
| ] | ||
| @pytest.mark.parametrize(("file_name", "content"), test_install_with_uv_config_raises_error_cases) | ||
| def test_install_with_uv_config_raises_error( | ||
| git_repo: Path, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| file_name: str, | ||
| content: str, | ||
| ) -> None: | ||
| """Test to make sure that uv config is used for non default pypi repos.""" | ||
| (git_repo / file_name).write_text(dedent(content)) | ||
| monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1") | ||
| import pre_commit_uv # noqa: PLC0415 | ||
| pre_commit_uv._patch() # noqa: SLF001 | ||
| # would raise SystemExit due to bad config | ||
| with pytest.raises(SystemExit): | ||
| main.main(["install-hooks", "-c", str(git_repo / precommit_file)]) |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
22921
13.66%229
76.15%