pre-commit-uv 4.1.2__tar.gz → 4.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pre_commit_uv-4.1.2 → pre_commit_uv-4.1.4}/PKG-INFO +1 -1
- {pre_commit_uv-4.1.2 → pre_commit_uv-4.1.4}/src/pre_commit_uv/__init__.py +8 -8
- pre_commit_uv-4.1.4/tests/test_main.py +68 -0
- {pre_commit_uv-4.1.2 → pre_commit_uv-4.1.4}/tox.ini +0 -1
- pre_commit_uv-4.1.2/tests/test_main.py +0 -40
- {pre_commit_uv-4.1.2 → pre_commit_uv-4.1.4}/.gitignore +0 -0
- {pre_commit_uv-4.1.2 → pre_commit_uv-4.1.4}/LICENSE.txt +0 -0
- {pre_commit_uv-4.1.2 → pre_commit_uv-4.1.4}/README.md +0 -0
- {pre_commit_uv-4.1.2 → pre_commit_uv-4.1.4}/pyproject.toml +0 -0
- {pre_commit_uv-4.1.2 → pre_commit_uv-4.1.4}/src/pre_commit_uv/py.typed +0 -0
- {pre_commit_uv-4.1.2 → pre_commit_uv-4.1.4}/src/pre_commit_uv_patch.pth +0 -0
|
@@ -16,7 +16,11 @@ def _patch() -> None:
|
|
|
16
16
|
calling_pre_commit = "FORCE_PRE_COMMIT_UV_PATCH" in os.environ
|
|
17
17
|
if not calling_pre_commit and sys.argv and sys.argv[0]: # must have arguments
|
|
18
18
|
calling = sys.argv[1] if sys.argv[0] == sys.executable and len(sys.argv) >= 1 else sys.argv[0]
|
|
19
|
-
if
|
|
19
|
+
if (
|
|
20
|
+
os.path.split(calling)[1] == f"pre-commit{'.exe' if sys.platform == 'win32' else ''}"
|
|
21
|
+
# case when pre-commit is called due to a git commit
|
|
22
|
+
or ("-m" in sys.argv and "hook-impl" in sys.argv)
|
|
23
|
+
):
|
|
20
24
|
calling_pre_commit = True
|
|
21
25
|
|
|
22
26
|
if calling_pre_commit and os.environ.get("DISABLE_PRE_COMMIT_UV_PATCH") is None:
|
|
@@ -61,13 +65,9 @@ def _new_main(argv: list[str] | None = None) -> int:
|
|
|
61
65
|
logger = logging.getLogger("pre_commit")
|
|
62
66
|
logger.info("Using pre-commit with uv %s via pre-commit-uv %s", uv_version(), self_version())
|
|
63
67
|
uv = _uv()
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
venv_cmd.extend(("-p", py))
|
|
68
|
-
env = os.environ.copy()
|
|
69
|
-
env["UV_INTERNAL__PARENT_INTERPRETER"] = sys.executable
|
|
70
|
-
cmd_output_b(*venv_cmd, cwd="/", env=env)
|
|
68
|
+
py = python.norm_version(version) or os.environ.get("UV_PYTHON", sys.executable)
|
|
69
|
+
venv_cmd = [uv, "venv", environment_dir(prefix, python.ENVIRONMENT_DIR, version), "-p", py]
|
|
70
|
+
cmd_output_b(*venv_cmd, cwd="/")
|
|
71
71
|
|
|
72
72
|
with python.in_env(prefix, version):
|
|
73
73
|
setup_cmd(prefix, (uv, "pip", "install", ".", *additional_dependencies))
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import version
|
|
4
|
+
from subprocess import check_call, check_output
|
|
5
|
+
from textwrap import dedent
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from pre_commit import main
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
precommit_file = ".pre-commit-config.yaml"
|
|
15
|
+
uv = version("uv")
|
|
16
|
+
self = version("pre-commit-uv")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.fixture
|
|
20
|
+
def git_repo(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
|
21
|
+
conf = """
|
|
22
|
+
repos:
|
|
23
|
+
- repo: https://github.com/tox-dev/pyproject-fmt
|
|
24
|
+
rev: "2.2.0"
|
|
25
|
+
hooks:
|
|
26
|
+
- id: pyproject-fmt
|
|
27
|
+
"""
|
|
28
|
+
conf_file = tmp_path / precommit_file
|
|
29
|
+
conf_file.write_text(dedent(conf))
|
|
30
|
+
monkeypatch.setenv("PRE_COMMIT_HOME", str(tmp_path / "store"))
|
|
31
|
+
monkeypatch.chdir(tmp_path)
|
|
32
|
+
check_call(["git", "init"])
|
|
33
|
+
return tmp_path
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.fixture
|
|
37
|
+
def install_hook(git_repo: Path) -> None:
|
|
38
|
+
check_call(["pre-commit", "install", "--install-hooks", "-c", str(git_repo / precommit_file)])
|
|
39
|
+
check_call(["pre-commit", "clean"]) # ensures that 'install_environment' gets called
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@pytest.mark.usefixtures("install_hook")
|
|
43
|
+
def test_run_precommit_hook() -> None:
|
|
44
|
+
hook_result = check_output([".git/hooks/pre-commit"], encoding="utf-8")
|
|
45
|
+
assert f"[INFO] Using pre-commit with uv {uv} via pre-commit-uv {self}" in hook_result.splitlines()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.mark.usefixtures("install_hook")
|
|
49
|
+
def test_call_as_module() -> None:
|
|
50
|
+
run_result = check_output(["python3", "-m", "pre_commit", "run", "-a", "--color", "never"], encoding="utf-8")
|
|
51
|
+
assert f"[INFO] Using pre-commit with uv {uv} via pre-commit-uv {self}" not in run_result.splitlines()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_install(git_repo: Path, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
55
|
+
monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
|
|
56
|
+
|
|
57
|
+
import pre_commit_uv # noqa: PLC0415
|
|
58
|
+
|
|
59
|
+
pre_commit_uv._patch() # noqa: SLF001
|
|
60
|
+
main.main(["install-hooks", "-c", str(git_repo / precommit_file)])
|
|
61
|
+
|
|
62
|
+
assert caplog.messages == [
|
|
63
|
+
"Initializing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
64
|
+
"Installing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
65
|
+
"Once installed this environment will be reused.",
|
|
66
|
+
"This may take a few minutes...",
|
|
67
|
+
f"Using pre-commit with uv {uv} via pre-commit-uv {self}",
|
|
68
|
+
]
|
|
@@ -24,7 +24,6 @@ pass_env =
|
|
|
24
24
|
PYTEST_*
|
|
25
25
|
set_env =
|
|
26
26
|
COVERAGE_FILE = {work_dir}/.coverage.{env_name}
|
|
27
|
-
FORCE_PRE_COMMIT_UV_PATCH = true
|
|
28
27
|
commands =
|
|
29
28
|
python -m pytest {tty:--color=yes} {posargs: \
|
|
30
29
|
--cov {env_site_packages_dir}{/}pre_commit_uv --cov {tox_root}{/}tests \
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from importlib.metadata import version
|
|
4
|
-
from subprocess import check_call
|
|
5
|
-
from textwrap import dedent
|
|
6
|
-
from typing import TYPE_CHECKING
|
|
7
|
-
|
|
8
|
-
from pre_commit import main
|
|
9
|
-
|
|
10
|
-
if TYPE_CHECKING:
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
|
|
13
|
-
import pytest
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def test_install(tmp_path: Path, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
17
|
-
conf = """
|
|
18
|
-
repos:
|
|
19
|
-
- repo: https://github.com/tox-dev/pyproject-fmt
|
|
20
|
-
rev: "2.2.0"
|
|
21
|
-
hooks:
|
|
22
|
-
- id: pyproject-fmt
|
|
23
|
-
"""
|
|
24
|
-
conf_file = tmp_path / ".pre-commit-config.yaml"
|
|
25
|
-
conf_file.write_text(dedent(conf))
|
|
26
|
-
monkeypatch.setenv("PRE_COMMIT_HOME", str(tmp_path / "store"))
|
|
27
|
-
monkeypatch.chdir(tmp_path)
|
|
28
|
-
check_call(["git", "init"])
|
|
29
|
-
|
|
30
|
-
main.main(["install-hooks", "-c", str(conf_file)])
|
|
31
|
-
|
|
32
|
-
uv = version("uv")
|
|
33
|
-
self = version("pre-commit-uv")
|
|
34
|
-
assert caplog.messages == [
|
|
35
|
-
"Initializing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
36
|
-
"Installing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
37
|
-
"Once installed this environment will be reused.",
|
|
38
|
-
"This may take a few minutes...",
|
|
39
|
-
f"Using pre-commit with uv {uv} via pre-commit-uv {self}",
|
|
40
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|