pre-commit-uv 4.2.0__tar.gz → 4.2.1__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,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pre-commit-uv
3
- Version: 4.2.0
3
+ Version: 4.2.1
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
7
- Project-URL: Documentation, https://github.com/tox-dev/pre-commit-uv/
8
7
  Project-URL: Source Code, https://github.com/tox-dev/pre-commit-uv
8
+ Project-URL: Documentation, https://github.com/tox-dev/pre-commit-uv/
9
9
  Author-email: Bernat Gabor <gaborjbernat@gmail.com>
10
10
  License: Permission is hereby granted, free of charge, to any person obtaining a
11
11
  copy of this software and associated documentation files (the
@@ -44,8 +44,8 @@ optional-dependencies.testing = [
44
44
  ]
45
45
  urls."Bug Tracker" = "https://github.com/tox-dev/pre-commit-uv/issues"
46
46
  urls."Changelog" = "https://github.com/tox-dev/pre-commit-uv/releases"
47
- urls.Documentation = "https://github.com/tox-dev/pre-commit-uv/"
48
47
  urls."Source Code" = "https://github.com/tox-dev/pre-commit-uv"
48
+ urls.Documentation = "https://github.com/tox-dev/pre-commit-uv/"
49
49
 
50
50
  [tool.hatch]
51
51
  build.dev-mode-dirs = [
@@ -77,6 +77,7 @@ lint.ignore = [
77
77
  "D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
78
78
  "DOC501", # not working with Sphinx
79
79
  "ISC001", # Conflict with formatter
80
+ "RUF067", # `__init__` module should only contain docstrings and re-exports
80
81
  "S104", # Possible binding to all interfaces
81
82
  ]
82
83
  lint.per-file-ignores."tests/**/*.py" = [
@@ -110,8 +111,10 @@ ini_options.testpaths = [
110
111
  ]
111
112
 
112
113
  [tool.coverage]
113
- html.show_contexts = true
114
- html.skip_covered = false
114
+ run.parallel = true
115
+ run.plugins = [
116
+ "covdefaults",
117
+ ]
115
118
  paths.source = [
116
119
  "src",
117
120
  ".tox/*/.venv/lib/*/site-packages",
@@ -122,10 +125,8 @@ paths.source = [
122
125
  "**\\src",
123
126
  ]
124
127
  report.fail_under = 63
125
- run.parallel = true
126
- run.plugins = [
127
- "covdefaults",
128
- ]
128
+ html.show_contexts = true
129
+ html.skip_covered = false
129
130
 
130
131
  [tool.mypy]
131
132
  show_error_codes = true
@@ -9,21 +9,28 @@ import sys
9
9
  _original_main = None
10
10
 
11
11
 
12
+ def _is_calling_pre_commit() -> bool:
13
+ if "FORCE_PRE_COMMIT_UV_PATCH" in os.environ:
14
+ return True
15
+ if not sys.argv or not sys.argv[0]:
16
+ return False
17
+ # case when pre-commit is called via python -m pre_commit
18
+ if sys.argv[0] == "-m" and "-m" in sys.orig_argv and "pre_commit" in sys.orig_argv:
19
+ return True
20
+ calling = sys.argv[1] if sys.argv[0] == sys.executable and len(sys.argv) >= 1 else sys.argv[0]
21
+ # case when pre-commit is called directly
22
+ if os.path.split(calling)[1] == f"pre-commit{'.exe' if sys.platform == 'win32' else ''}":
23
+ return True
24
+ # case when pre-commit is called due to a git commit
25
+ return "-m" in sys.argv and "hook-impl" in sys.argv
26
+
27
+
12
28
  def _patch() -> None:
13
29
  global _original_main
14
30
  if _original_main is not None: # already patched, nothing more to do
15
31
  return
16
- calling_pre_commit = "FORCE_PRE_COMMIT_UV_PATCH" in os.environ
17
- if not calling_pre_commit and sys.argv and sys.argv[0]: # must have arguments
18
- calling = sys.argv[1] if sys.argv[0] == sys.executable and len(sys.argv) >= 1 else sys.argv[0]
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
- ):
24
- calling_pre_commit = True
25
-
26
- if calling_pre_commit and os.environ.get("DISABLE_PRE_COMMIT_UV_PATCH") is None:
32
+
33
+ if _is_calling_pre_commit() and os.environ.get("DISABLE_PRE_COMMIT_UV_PATCH") is None:
27
34
  from pre_commit import main # noqa: PLC0415
28
35
 
29
36
  _original_main, main.main = main.main, _new_main
@@ -74,6 +81,7 @@ def _new_main(argv: list[str] | None = None) -> int:
74
81
  "--project",
75
82
  project_root_dir,
76
83
  "venv",
84
+ "--seed",
77
85
  environment_dir(prefix, python.ENVIRONMENT_DIR, version),
78
86
  "-p",
79
87
  py,
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import sys
3
4
  from importlib.metadata import version
4
5
  from subprocess import check_call, check_output
5
6
  from textwrap import dedent
@@ -47,8 +48,8 @@ def test_run_precommit_hook() -> None:
47
48
 
48
49
  @pytest.mark.usefixtures("install_hook")
49
50
  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()
51
+ run_result = check_output([sys.executable, "-m", "pre_commit", "run", "-a", "--color", "never"], encoding="utf-8")
52
+ assert f"[INFO] Using pre-commit with uv {uv} via pre-commit-uv {self}" in run_result.splitlines()
52
53
 
53
54
 
54
55
  def test_install(git_repo: Path, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -68,6 +69,21 @@ def test_install(git_repo: Path, caplog: pytest.LogCaptureFixture, monkeypatch:
68
69
  ]
69
70
 
70
71
 
72
+ def test_install_seeds_pip(git_repo: Path, monkeypatch: pytest.MonkeyPatch) -> None:
73
+ monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
74
+
75
+ import pre_commit_uv # noqa: PLC0415
76
+
77
+ pre_commit_uv._patch() # noqa: SLF001
78
+ main.main(["install-hooks", "-c", str(git_repo / precommit_file)])
79
+
80
+ env_dirs = list((git_repo / "store").rglob("py_env-*"))
81
+ assert env_dirs, "expected at least one hook environment"
82
+ py = next((env_dirs[0] / "bin").glob("python*"))
83
+ result = check_output([str(py), "-c", "import pip"], encoding="utf-8")
84
+ assert not result
85
+
86
+
71
87
  test_install_with_uv_config_cases: list[tuple[str, str]] = [
72
88
  (
73
89
  "pyproject.toml",
File without changes
File without changes
File without changes
File without changes