pre-commit-uv 4.1.2__tar.gz → 4.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pre-commit-uv
3
- Version: 4.1.2
3
+ Version: 4.1.3
4
4
  Summary: Run pre-commit with uv
5
5
  Project-URL: Bug Tracker, https://github.com/tox-dev/pre-commit-uv/issues
6
6
  Project-URL: Changelog, https://github.com/tox-dev/pre-commit-uv/releases
@@ -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 os.path.split(calling)[1] == f"pre-commit{'.exe' if sys.platform == 'win32' else ''}":
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:
@@ -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