pre-commit-uv 4.4.2__tar.gz → 4.4.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.
- pre_commit_uv-4.4.3/.python-sbom-revision +1 -0
- {pre_commit_uv-4.4.2 → pre_commit_uv-4.4.3}/CHANGELOG.md +12 -0
- {pre_commit_uv-4.4.2 → pre_commit_uv-4.4.3}/CONTRIBUTING.md +4 -0
- {pre_commit_uv-4.4.2 → pre_commit_uv-4.4.3}/PKG-INFO +1 -1
- {pre_commit_uv-4.4.2 → pre_commit_uv-4.4.3}/pyproject.toml +20 -18
- pre_commit_uv-4.4.3/src/pre_commit_uv/__init__.py +3 -0
- pre_commit_uv-4.4.2/src/pre_commit_uv/__init__.py → pre_commit_uv-4.4.3/src/pre_commit_uv/_pre_commit_patch.py +54 -50
- pre_commit_uv-4.4.3/src/pre_commit_uv_patch.pth +1 -0
- pre_commit_uv-4.4.3/tests/pre_commit_uv/test_pre_commit_patch.py +272 -0
- pre_commit_uv-4.4.2/src/pre_commit_uv_patch.pth +0 -1
- pre_commit_uv-4.4.2/tests/test_health_check.py +0 -77
- pre_commit_uv-4.4.2/tests/test_main.py +0 -178
- {pre_commit_uv-4.4.2 → pre_commit_uv-4.4.3}/.gitignore +0 -0
- {pre_commit_uv-4.4.2 → pre_commit_uv-4.4.3}/LICENSE.txt +0 -0
- {pre_commit_uv-4.4.2 → pre_commit_uv-4.4.3}/README.md +0 -0
- {pre_commit_uv-4.4.2 → pre_commit_uv-4.4.3}/src/pre_commit_uv/py.typed +0 -0
- {pre_commit_uv-4.4.2 → pre_commit_uv-4.4.3}/tox.toml +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node: ad57e53c5c59c60107180e8a1500190300359b71
|
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- towncrier release notes start -->
|
|
4
4
|
|
|
5
|
+
<a name="release-4-4-3"></a>
|
|
6
|
+
|
|
7
|
+
## 4.4.3 (2026-11-18)
|
|
8
|
+
|
|
9
|
+
<a name="release-4-4-3-packaging"></a>
|
|
10
|
+
|
|
11
|
+
### Packaging
|
|
12
|
+
|
|
13
|
+
- Every wheel now carries a [PEP 770](https://peps.python.org/pep-0770/) CycloneDX SBOM in its `.dist-info/sboms`
|
|
14
|
+
directory, written at build time by [python-sbom](https://github.com/tox-dev/python-sbom)
|
|
15
|
+
([#215](https://github.com/tox-dev/pre-commit-uv/pull/215)) by [@gaborbernat](https://github.com/gaborbernat).
|
|
16
|
+
|
|
5
17
|
<a name="release-4-4-2"></a>
|
|
6
18
|
|
|
7
19
|
## 4.4.2 (2026-11-04)
|
|
@@ -38,3 +38,7 @@ version for a `feature` fragment, and a patch version for other categories. The
|
|
|
38
38
|
`prek` on the result, and uses the repository-scoped App to push the release commit and tag. The tag workflow builds the
|
|
39
39
|
distribution, publishes it to PyPI through trusted publishing, then creates the GitHub Release from the tagged
|
|
40
40
|
changelog. The workflow does not ask for a version string.
|
|
41
|
+
|
|
42
|
+
## Tests
|
|
43
|
+
|
|
44
|
+
Add a test for every new feature and bug fix. A change without a test needs a reason in the pull request description.
|
|
@@ -4,6 +4,7 @@ requires = [
|
|
|
4
4
|
"hatch-fancy-pypi-readme>=25.1",
|
|
5
5
|
"hatch-vcs>=0.5",
|
|
6
6
|
"hatchling>=1.32.4",
|
|
7
|
+
"python-sbom[hatch]>=0.1.2",
|
|
7
8
|
]
|
|
8
9
|
|
|
9
10
|
[project]
|
|
@@ -68,6 +69,7 @@ build = [
|
|
|
68
69
|
"hatch-fancy-pypi-readme>=25.1",
|
|
69
70
|
"hatch-vcs>=0.5",
|
|
70
71
|
"hatchling>=1.32.4",
|
|
72
|
+
"python-sbom[hatch]>=0.1.2",
|
|
71
73
|
"setuptools>=80",
|
|
72
74
|
]
|
|
73
75
|
lint = [
|
|
@@ -105,6 +107,7 @@ metadata.hooks.fancy-pypi-readme.substitutions = [
|
|
|
105
107
|
build.dev-mode-dirs = [
|
|
106
108
|
"src",
|
|
107
109
|
]
|
|
110
|
+
build.hooks.python-sbom = {}
|
|
108
111
|
build.targets.sdist.include = [
|
|
109
112
|
"/CHANGELOG.md",
|
|
110
113
|
"/CONTRIBUTING.md",
|
|
@@ -130,26 +133,25 @@ lint.select = [
|
|
|
130
133
|
"ALL",
|
|
131
134
|
]
|
|
132
135
|
lint.ignore = [
|
|
133
|
-
"any-type", # allow Any as type annotation
|
|
134
136
|
"CPY", # No copyright statements
|
|
135
|
-
"
|
|
136
|
-
"hardcoded-bind-all-interfaces", # Possible binding to all interfaces
|
|
137
|
-
"incorrect-blank-line-before-class", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
|
|
137
|
+
"incorrect-blank-line-before-class", # Conflicts with `blank-line-before-class`
|
|
138
138
|
"missing-trailing-comma", # Conflict with formatter
|
|
139
|
-
"multi-line-summary-first-line", #
|
|
140
|
-
"non-empty-init-module", # `__init__` module should only contain docstrings and re-exports
|
|
139
|
+
"multi-line-summary-first-line", # Conflicts with `multi-line-summary-second-line`
|
|
141
140
|
"single-line-implicit-string-concatenation", # Conflict with formatter
|
|
141
|
+
"undocumented-magic-method", # undocumented-public-api (simplint) covers the public API instead
|
|
142
|
+
"undocumented-public-class", # undocumented-public-api (simplint) covers the public API instead
|
|
143
|
+
"undocumented-public-function", # undocumented-public-api (simplint) covers the public API instead
|
|
144
|
+
"undocumented-public-init", # undocumented-public-api (simplint) covers the public API instead
|
|
145
|
+
"undocumented-public-method", # undocumented-public-api (simplint) covers the public API instead
|
|
146
|
+
"undocumented-public-nested-class", # undocumented-public-api (simplint) covers the public API instead
|
|
142
147
|
]
|
|
143
148
|
lint.per-file-ignores."tests/**/*.py" = [
|
|
144
|
-
"assert",
|
|
145
|
-
"
|
|
146
|
-
"
|
|
147
|
-
"
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
"S", # `subprocess` call: check for execution of untrusted input
|
|
151
|
-
"too-many-arguments", # any number of arguments in tests
|
|
152
|
-
"too-many-positional-arguments", # any number of arguments in tests
|
|
149
|
+
"assert", # asserts allowed in tests...
|
|
150
|
+
"implicit-namespace-package", # no implicit namespace
|
|
151
|
+
"import-private-name", # private import
|
|
152
|
+
"subprocess-without-shell-equals-true", # integration tests pass fixed commands and fixture paths to subprocesses
|
|
153
|
+
"suspicious-subprocess-import", # integration tests execute pre-commit and its installed hook
|
|
154
|
+
"undocumented-public-module", # tests do not need module docstrings
|
|
153
155
|
]
|
|
154
156
|
lint.isort = { known-first-party = [
|
|
155
157
|
"pre_commit_uv",
|
|
@@ -210,6 +212,9 @@ type = [
|
|
|
210
212
|
{ directory = "packaging", name = "Packaging", showcontent = true },
|
|
211
213
|
]
|
|
212
214
|
|
|
215
|
+
[tool.python-sbom]
|
|
216
|
+
supplier = { name = "tox-dev", url = [ "https://github.com/tox-dev" ] }
|
|
217
|
+
|
|
213
218
|
[tool.nab]
|
|
214
219
|
mode = "universal"
|
|
215
220
|
base-group = "project-runtime"
|
|
@@ -217,6 +222,3 @@ uploaded-prior-to = "P7D"
|
|
|
217
222
|
decision-order = "stable"
|
|
218
223
|
matrix.python = ">=3.15,<3.16"
|
|
219
224
|
matrix.platforms = [ "linux_x86_64" ]
|
|
220
|
-
# release-creator 4.4.0 needs a seven-day cutoff exception.
|
|
221
|
-
# expires 2026-11-09
|
|
222
|
-
packages.release-creator.uploaded-prior-to = 2026-11-02T21:45:00Z
|
|
@@ -19,7 +19,29 @@ if TYPE_CHECKING:
|
|
|
19
19
|
health_check: Callable[[Prefix, str], str | None]
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
_ORIGINAL_MAIN = None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def patch() -> None:
|
|
26
|
+
global _ORIGINAL_MAIN
|
|
27
|
+
if _ORIGINAL_MAIN is not None: # already patched, nothing more to do
|
|
28
|
+
return
|
|
29
|
+
|
|
30
|
+
if _is_calling_pre_commit() and os.environ.get("DISABLE_PRE_COMMIT_UV_PATCH") is None:
|
|
31
|
+
from pre_commit import main # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
32
|
+
|
|
33
|
+
_ORIGINAL_MAIN, main.main = main.main, _new_main # ty: ignore[invalid-assignment] pre-commit exposes main as a plain function we patch on purpose
|
|
34
|
+
if "--version" in sys.argv:
|
|
35
|
+
from importlib.metadata import version as _metadata_version # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
36
|
+
|
|
37
|
+
from pre_commit import constants # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
38
|
+
|
|
39
|
+
constants.VERSION = (
|
|
40
|
+
f"{constants.VERSION} ("
|
|
41
|
+
f"pre-commit-uv={_metadata_version('pre-commit-uv')}, "
|
|
42
|
+
f"uv={_metadata_version('uv')}"
|
|
43
|
+
f")"
|
|
44
|
+
)
|
|
23
45
|
|
|
24
46
|
|
|
25
47
|
def _is_calling_pre_commit() -> bool:
|
|
@@ -38,44 +60,22 @@ def _is_calling_pre_commit() -> bool:
|
|
|
38
60
|
return "-m" in sys.argv and "hook-impl" in sys.argv
|
|
39
61
|
|
|
40
62
|
|
|
41
|
-
def _patch() -> None:
|
|
42
|
-
global _original_main
|
|
43
|
-
if _original_main is not None: # already patched, nothing more to do
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
if _is_calling_pre_commit() and os.environ.get("DISABLE_PRE_COMMIT_UV_PATCH") is None:
|
|
47
|
-
from pre_commit import main # ruff:ignore[import-outside-top-level]
|
|
48
|
-
|
|
49
|
-
_original_main, main.main = main.main, _new_main # ty: ignore[invalid-assignment]
|
|
50
|
-
if "--version" in sys.argv:
|
|
51
|
-
from importlib.metadata import version as _metadata_version # ruff:ignore[import-outside-top-level]
|
|
52
|
-
|
|
53
|
-
from pre_commit import constants # ruff:ignore[import-outside-top-level]
|
|
54
|
-
|
|
55
|
-
constants.VERSION = (
|
|
56
|
-
f"{constants.VERSION} ("
|
|
57
|
-
f"pre-commit-uv={_metadata_version('pre-commit-uv')}, "
|
|
58
|
-
f"uv={_metadata_version('uv')}"
|
|
59
|
-
f")"
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
|
|
63
63
|
def _new_main(argv: Sequence[str] | None = None) -> int:
|
|
64
64
|
# imports applied locally to avoid patching import overhead cost
|
|
65
|
-
from functools import cache # ruff:ignore[import-outside-top-level]
|
|
65
|
+
from functools import cache # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
66
66
|
|
|
67
|
-
from pre_commit.languages import python # ruff:ignore[import-outside-top-level]
|
|
67
|
+
from pre_commit.languages import python # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
68
68
|
|
|
69
69
|
def _install_environment(
|
|
70
70
|
prefix: Prefix,
|
|
71
71
|
version: str,
|
|
72
72
|
additional_dependencies: Sequence[str],
|
|
73
73
|
) -> None:
|
|
74
|
-
import logging # ruff:ignore[import-outside-top-level]
|
|
74
|
+
import logging # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
75
75
|
|
|
76
|
-
from pre_commit.git import get_root # ruff:ignore[import-outside-top-level]
|
|
77
|
-
from pre_commit.lang_base import environment_dir, setup_cmd # ruff:ignore[import-outside-top-level]
|
|
78
|
-
from pre_commit.util import cmd_output_b # ruff:ignore[import-outside-top-level]
|
|
76
|
+
from pre_commit.git import get_root # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
77
|
+
from pre_commit.lang_base import environment_dir, setup_cmd # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
78
|
+
from pre_commit.util import cmd_output_b # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
79
79
|
|
|
80
80
|
project_root_dir = get_root()
|
|
81
81
|
|
|
@@ -111,57 +111,46 @@ def _new_main(argv: Sequence[str] | None = None) -> int:
|
|
|
111
111
|
|
|
112
112
|
@cache
|
|
113
113
|
def _uv() -> str:
|
|
114
|
-
from uv import find_uv_bin # ruff:ignore[import-outside-top-level]
|
|
114
|
+
from uv import find_uv_bin # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
115
115
|
|
|
116
116
|
return find_uv_bin()
|
|
117
117
|
|
|
118
118
|
@cache
|
|
119
119
|
def self_version() -> str:
|
|
120
|
-
from importlib.metadata import version as _metadata_version # ruff:ignore[import-outside-top-level]
|
|
120
|
+
from importlib.metadata import version as _metadata_version # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
121
121
|
|
|
122
122
|
return _metadata_version("pre-commit-uv")
|
|
123
123
|
|
|
124
124
|
@cache
|
|
125
125
|
def uv_version() -> str:
|
|
126
|
-
from importlib.metadata import version as _metadata_version # ruff:ignore[import-outside-top-level]
|
|
126
|
+
from importlib.metadata import version as _metadata_version # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
127
127
|
|
|
128
128
|
return _metadata_version("uv")
|
|
129
129
|
|
|
130
130
|
patched = cast("_PatchablePython", python)
|
|
131
131
|
patched.install_environment = _install_environment
|
|
132
132
|
patched.health_check = _health_check
|
|
133
|
-
assert
|
|
134
|
-
return
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def _version_info(exe: str) -> str:
|
|
138
|
-
from pre_commit.util import CalledProcessError, cmd_output # ruff:ignore[import-outside-top-level]
|
|
139
|
-
|
|
140
|
-
prog = 'import sys;print(".".join(str(p) for p in sys.version_info[0:3]))'
|
|
141
|
-
try:
|
|
142
|
-
return cmd_output(exe, "-S", "-c", prog)[1].strip()
|
|
143
|
-
except CalledProcessError:
|
|
144
|
-
return f"<<error retrieving version from {exe}>>"
|
|
133
|
+
assert _ORIGINAL_MAIN is not None # ruff:ignore[assert] patch sets _ORIGINAL_MAIN before installing _new_main
|
|
134
|
+
return _ORIGINAL_MAIN(argv)
|
|
145
135
|
|
|
146
136
|
|
|
147
137
|
def _health_check(prefix: Prefix, version: str) -> str | None:
|
|
148
138
|
# uv may record fewer version components in pyvenv.cfg than pre-commit expects (e.g. "3.14" vs "3.14.6"),
|
|
149
139
|
# so compare only the components uv actually wrote rather than requiring an exact string match
|
|
150
|
-
from pre_commit.lang_base import environment_dir # ruff:ignore[import-outside-top-level]
|
|
151
|
-
from pre_commit.languages import python # ruff:ignore[import-outside-top-level]
|
|
152
|
-
from pre_commit.util import win_exe # ruff:ignore[import-outside-top-level]
|
|
140
|
+
from pre_commit.lang_base import environment_dir # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
141
|
+
from pre_commit.languages import python # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
142
|
+
from pre_commit.util import win_exe # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
153
143
|
|
|
154
144
|
pyvenv_cfg = pathlib.Path(environment_dir(prefix, python.ENVIRONMENT_DIR, version)) / "pyvenv.cfg"
|
|
155
145
|
if not pyvenv_cfg.exists():
|
|
156
146
|
return "pyvenv.cfg does not exist (old virtualenv?)"
|
|
157
147
|
|
|
158
|
-
cfg = python._read_pyvenv_cfg(str(pyvenv_cfg)) # ruff:ignore[private-member-access]
|
|
148
|
+
cfg = python._read_pyvenv_cfg(str(pyvenv_cfg)) # ruff:ignore[private-member-access] no public parser in pre-commit
|
|
159
149
|
if "version_info" not in cfg:
|
|
160
150
|
return "created virtualenv's pyvenv.cfg is missing `version_info`"
|
|
161
151
|
expected = cfg["version_info"].split(".")
|
|
162
152
|
|
|
163
|
-
|
|
164
|
-
targets = [("virtualenv python", py_exe)]
|
|
153
|
+
targets = [("virtualenv python", prefix.path(python.bin_dir(str(pyvenv_cfg.parent)), win_exe("python")))]
|
|
165
154
|
if "base-executable" in cfg:
|
|
166
155
|
targets.append(("base executable", cfg["base-executable"]))
|
|
167
156
|
for label, exe in targets:
|
|
@@ -172,3 +161,18 @@ def _health_check(prefix: Prefix, version: str) -> str | None:
|
|
|
172
161
|
f"- expected version: {cfg['version_info']}\n"
|
|
173
162
|
)
|
|
174
163
|
return None
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _version_info(exe: str) -> str:
|
|
167
|
+
from pre_commit.util import CalledProcessError, cmd_output # ruff:ignore[import-outside-top-level] loaded only when pre-commit runs, keeping startup cheap
|
|
168
|
+
|
|
169
|
+
prog = 'import sys;print(".".join(str(p) for p in sys.version_info[0:3]))'
|
|
170
|
+
try:
|
|
171
|
+
return cmd_output(exe, "-S", "-c", prog)[1].strip()
|
|
172
|
+
except CalledProcessError:
|
|
173
|
+
return f"<<error retrieving version from {exe}>>"
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
__all__ = [
|
|
177
|
+
"patch",
|
|
178
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import pre_commit_uv._pre_commit_patch; pre_commit_uv._pre_commit_patch.patch()
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from importlib import reload
|
|
5
|
+
from importlib.metadata import version
|
|
6
|
+
from shutil import which
|
|
7
|
+
from subprocess import check_call, check_output
|
|
8
|
+
from textwrap import dedent
|
|
9
|
+
from typing import TYPE_CHECKING, Final
|
|
10
|
+
|
|
11
|
+
import pytest
|
|
12
|
+
from pre_commit import main
|
|
13
|
+
from pre_commit.languages import python
|
|
14
|
+
from pre_commit.prefix import Prefix
|
|
15
|
+
|
|
16
|
+
from pre_commit_uv._pre_commit_patch import patch
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
_PRECOMMIT_FILE: Final[str] = ".pre-commit-config.yaml"
|
|
22
|
+
_UV_VERSION: Final[str] = version("uv")
|
|
23
|
+
_PRE_COMMIT_UV_VERSION: Final[str] = version("pre-commit-uv")
|
|
24
|
+
_VERSION: Final[str] = "default"
|
|
25
|
+
_MAJOR_MINOR: Final[str] = f"{sys.version_info[0]}.{sys.version_info[1]}"
|
|
26
|
+
_FULL_VERSION: Final[str] = ".".join(str(p) for p in sys.version_info[0:3])
|
|
27
|
+
_WRONG_VERSION: Final[str] = f"{sys.version_info[0]}.{sys.version_info[1] + 1}"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.fixture
|
|
31
|
+
def git_repo(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
|
32
|
+
conf_file = tmp_path / _PRECOMMIT_FILE
|
|
33
|
+
conf = """
|
|
34
|
+
repos:
|
|
35
|
+
- repo: https://github.com/tox-dev/pyproject-fmt
|
|
36
|
+
rev: "2.2.0"
|
|
37
|
+
hooks:
|
|
38
|
+
- id: pyproject-fmt
|
|
39
|
+
"""
|
|
40
|
+
conf_file.write_text(dedent(conf))
|
|
41
|
+
monkeypatch.setenv("PRE_COMMIT_HOME", str(tmp_path / "store"))
|
|
42
|
+
monkeypatch.chdir(tmp_path)
|
|
43
|
+
git = which("git")
|
|
44
|
+
assert git is not None
|
|
45
|
+
check_call([git, "init"])
|
|
46
|
+
return tmp_path
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@pytest.fixture
|
|
50
|
+
def install_hook(git_repo: Path) -> None:
|
|
51
|
+
pre_commit = which("pre-commit")
|
|
52
|
+
assert pre_commit is not None
|
|
53
|
+
check_call([pre_commit, "install", "--install-hooks", "-c", str(git_repo / _PRECOMMIT_FILE)])
|
|
54
|
+
check_call([pre_commit, "clean"]) # ensures that 'install_environment' gets called
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@pytest.mark.usefixtures("install_hook")
|
|
58
|
+
def test_run_precommit_hook(git_repo: Path) -> None:
|
|
59
|
+
hook_result = check_output([str(git_repo / ".git" / "hooks" / "pre-commit")], encoding="utf-8")
|
|
60
|
+
assert (
|
|
61
|
+
f"[INFO] Using pre-commit with uv {_UV_VERSION} via pre-commit-uv {_PRE_COMMIT_UV_VERSION}"
|
|
62
|
+
in hook_result.splitlines()
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@pytest.mark.usefixtures("install_hook")
|
|
67
|
+
def test_call_as_module() -> None:
|
|
68
|
+
run_result = check_output([sys.executable, "-m", "pre_commit", "run", "-a", "--color", "never"], encoding="utf-8")
|
|
69
|
+
assert (
|
|
70
|
+
f"[INFO] Using pre-commit with uv {_UV_VERSION} via pre-commit-uv {_PRE_COMMIT_UV_VERSION}"
|
|
71
|
+
in run_result.splitlines()
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_install(git_repo: Path, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
76
|
+
monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
|
|
77
|
+
|
|
78
|
+
reload(main)
|
|
79
|
+
reload(sys.modules[patch.__module__])
|
|
80
|
+
patch()
|
|
81
|
+
main.main(["install-hooks", "-c", str(git_repo / _PRECOMMIT_FILE)])
|
|
82
|
+
|
|
83
|
+
assert caplog.messages == [
|
|
84
|
+
"Initializing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
85
|
+
"Installing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
86
|
+
"Once installed this environment will be reused.",
|
|
87
|
+
"This may take a few minutes...",
|
|
88
|
+
f"Using pre-commit with uv {_UV_VERSION} via pre-commit-uv {_PRE_COMMIT_UV_VERSION}",
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_install_seeds_pip(git_repo: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
93
|
+
monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
|
|
94
|
+
|
|
95
|
+
patch()
|
|
96
|
+
main.main(["install-hooks", "-c", str(git_repo / _PRECOMMIT_FILE)])
|
|
97
|
+
|
|
98
|
+
env_dirs = list((git_repo / "store").rglob("py_env-*"))
|
|
99
|
+
assert env_dirs, "expected at least one hook environment"
|
|
100
|
+
result = check_output([str(next((env_dirs[0] / "bin").glob("python*"))), "-c", "import pip"], encoding="utf-8")
|
|
101
|
+
assert not result
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
_TEST_INSTALL_WITH_UV_CONFIG_CASES: Final[list[tuple[str, str]]] = [
|
|
105
|
+
(
|
|
106
|
+
"pyproject.toml",
|
|
107
|
+
"""
|
|
108
|
+
[[tool.uv.index]]
|
|
109
|
+
name = "internal"
|
|
110
|
+
url = "https://pypi.org/simple/"
|
|
111
|
+
default = true
|
|
112
|
+
""",
|
|
113
|
+
),
|
|
114
|
+
(
|
|
115
|
+
"uv.toml",
|
|
116
|
+
"""
|
|
117
|
+
[[index]]
|
|
118
|
+
name = "internal"
|
|
119
|
+
url = "https://pypi.org/simple/"
|
|
120
|
+
default = true
|
|
121
|
+
""",
|
|
122
|
+
),
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@pytest.mark.parametrize(
|
|
127
|
+
("file_name", "content"),
|
|
128
|
+
_TEST_INSTALL_WITH_UV_CONFIG_CASES,
|
|
129
|
+
)
|
|
130
|
+
def test_install_with_uv_config(
|
|
131
|
+
git_repo: Path,
|
|
132
|
+
caplog: pytest.LogCaptureFixture,
|
|
133
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
134
|
+
file_name: str,
|
|
135
|
+
content: str,
|
|
136
|
+
) -> None:
|
|
137
|
+
(git_repo / file_name).write_text(dedent(content))
|
|
138
|
+
|
|
139
|
+
monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
|
|
140
|
+
|
|
141
|
+
patch()
|
|
142
|
+
main.main(["install-hooks", "-c", str(git_repo / _PRECOMMIT_FILE)])
|
|
143
|
+
|
|
144
|
+
assert caplog.messages == [
|
|
145
|
+
"Initializing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
146
|
+
"Installing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
147
|
+
"Once installed this environment will be reused.",
|
|
148
|
+
"This may take a few minutes...",
|
|
149
|
+
f"Using pre-commit with uv {_UV_VERSION} via pre-commit-uv {_PRE_COMMIT_UV_VERSION}",
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
_TEST_INSTALL_WITH_UV_CONFIG_RAISES_ERROR_CASES: Final[list[tuple[str, str]]] = [
|
|
154
|
+
(
|
|
155
|
+
"pyproject.toml",
|
|
156
|
+
"""
|
|
157
|
+
[[tool.uv.index]]
|
|
158
|
+
name = "internal"
|
|
159
|
+
url = "https://pypi.example/simple/"
|
|
160
|
+
default = true
|
|
161
|
+
""",
|
|
162
|
+
),
|
|
163
|
+
(
|
|
164
|
+
"uv.toml",
|
|
165
|
+
"""
|
|
166
|
+
[[index]]
|
|
167
|
+
name = "internal"
|
|
168
|
+
url = "https://pypi.example/simple/"
|
|
169
|
+
default = true
|
|
170
|
+
""",
|
|
171
|
+
),
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
@pytest.mark.parametrize(("file_name", "content"), _TEST_INSTALL_WITH_UV_CONFIG_RAISES_ERROR_CASES)
|
|
176
|
+
def test_install_with_uv_config_raises_error(
|
|
177
|
+
git_repo: Path,
|
|
178
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
179
|
+
file_name: str,
|
|
180
|
+
content: str,
|
|
181
|
+
) -> None:
|
|
182
|
+
# Test to make sure that uv config is used for non default pypi repos.
|
|
183
|
+
(git_repo / file_name).write_text(dedent(content))
|
|
184
|
+
|
|
185
|
+
monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
|
|
186
|
+
|
|
187
|
+
patch()
|
|
188
|
+
|
|
189
|
+
# would raise SystemExit due to bad config
|
|
190
|
+
with pytest.raises(SystemExit):
|
|
191
|
+
main.main(["install-hooks", "-c", str(git_repo / _PRECOMMIT_FILE)])
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
@pytest.fixture
|
|
195
|
+
def patched_pre_commit(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
196
|
+
monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
|
|
197
|
+
patch()
|
|
198
|
+
with pytest.raises(SystemExit) as result:
|
|
199
|
+
main.main(["--version"])
|
|
200
|
+
assert result.value.code == 0
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
@pytest.mark.usefixtures("patched_pre_commit")
|
|
204
|
+
def test_health_check_truncated_version_passes(tmp_path: Path) -> None:
|
|
205
|
+
# uv >=0.11.22 writes only the major.minor into pyvenv.cfg (see issue #152).
|
|
206
|
+
prefix = _make_env(tmp_path, f"version_info = {_MAJOR_MINOR}\nbase-executable = {sys.executable}\n")
|
|
207
|
+
|
|
208
|
+
assert python.health_check(prefix, _VERSION) is None
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _make_env(tmp_path: Path, pyvenv_cfg: str | None) -> Prefix:
|
|
212
|
+
envdir = tmp_path / f"py_env-{_VERSION}"
|
|
213
|
+
bin_dir = python.bin_dir(str(envdir))
|
|
214
|
+
(tmp_path / bin_dir).mkdir(parents=True)
|
|
215
|
+
(tmp_path / bin_dir / python.win_exe("python")).symlink_to(sys.executable)
|
|
216
|
+
if pyvenv_cfg is not None:
|
|
217
|
+
(envdir / "pyvenv.cfg").write_text(pyvenv_cfg)
|
|
218
|
+
return Prefix(str(tmp_path))
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
@pytest.mark.usefixtures("patched_pre_commit")
|
|
222
|
+
def test_health_check_full_version_passes(tmp_path: Path) -> None:
|
|
223
|
+
prefix = _make_env(tmp_path, f"version_info = {_FULL_VERSION}\nbase-executable = {sys.executable}\n")
|
|
224
|
+
|
|
225
|
+
assert python.health_check(prefix, _VERSION) is None
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
@pytest.mark.usefixtures("patched_pre_commit")
|
|
229
|
+
def test_health_check_no_base_executable_passes(tmp_path: Path) -> None:
|
|
230
|
+
prefix = _make_env(tmp_path, f"version_info = {_MAJOR_MINOR}\n")
|
|
231
|
+
|
|
232
|
+
assert python.health_check(prefix, _VERSION) is None
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@pytest.mark.usefixtures("patched_pre_commit")
|
|
236
|
+
def test_health_check_version_mismatch_fails(tmp_path: Path) -> None:
|
|
237
|
+
result = python.health_check(_make_env(tmp_path, f"version_info = {_WRONG_VERSION}\n"), _VERSION)
|
|
238
|
+
|
|
239
|
+
assert result is not None
|
|
240
|
+
assert "virtualenv python version did not match created version" in result
|
|
241
|
+
assert f"- expected version: {_WRONG_VERSION}" in result
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@pytest.mark.usefixtures("patched_pre_commit")
|
|
245
|
+
def test_health_check_base_executable_mismatch_fails(tmp_path: Path) -> None:
|
|
246
|
+
prefix = _make_env(tmp_path, f"version_info = {_MAJOR_MINOR}\nbase-executable = /does/not/exist/python\n")
|
|
247
|
+
|
|
248
|
+
result = python.health_check(prefix, _VERSION)
|
|
249
|
+
|
|
250
|
+
assert result is not None
|
|
251
|
+
assert "base executable version did not match created version" in result
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@pytest.mark.usefixtures("patched_pre_commit")
|
|
255
|
+
def test_health_check_missing_pyvenv_cfg(tmp_path: Path) -> None:
|
|
256
|
+
prefix = _make_env(tmp_path, None)
|
|
257
|
+
|
|
258
|
+
assert python.health_check(prefix, _VERSION) == "pyvenv.cfg does not exist (old virtualenv?)"
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
@pytest.mark.parametrize(
|
|
262
|
+
"contents",
|
|
263
|
+
[
|
|
264
|
+
pytest.param("# comment\nhome = /usr\n", id="no-version"),
|
|
265
|
+
pytest.param("version_info = 3=15\n", id="extra-equals"),
|
|
266
|
+
],
|
|
267
|
+
)
|
|
268
|
+
@pytest.mark.usefixtures("patched_pre_commit")
|
|
269
|
+
def test_health_check_missing_version_info(tmp_path: Path, contents: str) -> None:
|
|
270
|
+
prefix = _make_env(tmp_path, contents)
|
|
271
|
+
|
|
272
|
+
assert python.health_check(prefix, _VERSION) == "created virtualenv's pyvenv.cfg is missing `version_info`"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import pre_commit_uv; pre_commit_uv._patch()
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import sys
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
5
|
-
|
|
6
|
-
from pre_commit.languages import python
|
|
7
|
-
from pre_commit.prefix import Prefix
|
|
8
|
-
|
|
9
|
-
from pre_commit_uv import _health_check
|
|
10
|
-
|
|
11
|
-
if TYPE_CHECKING:
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
|
|
14
|
-
version = "default"
|
|
15
|
-
major_minor = f"{sys.version_info[0]}.{sys.version_info[1]}"
|
|
16
|
-
full_version = ".".join(str(p) for p in sys.version_info[0:3])
|
|
17
|
-
wrong_version = f"{sys.version_info[0]}.{sys.version_info[1] + 1}"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def _make_env(tmp_path: Path, pyvenv_cfg: str | None) -> Prefix:
|
|
21
|
-
envdir = tmp_path / f"py_env-{version}"
|
|
22
|
-
bin_dir = python.bin_dir(str(envdir))
|
|
23
|
-
(tmp_path / bin_dir).mkdir(parents=True)
|
|
24
|
-
(tmp_path / bin_dir / python.win_exe("python")).symlink_to(sys.executable)
|
|
25
|
-
if pyvenv_cfg is not None:
|
|
26
|
-
(envdir / "pyvenv.cfg").write_text(pyvenv_cfg)
|
|
27
|
-
return Prefix(str(tmp_path))
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def test_health_check_truncated_version_passes(tmp_path: Path) -> None:
|
|
31
|
-
"""uv >=0.11.22 writes only the major.minor into pyvenv.cfg (see issue #152)."""
|
|
32
|
-
prefix = _make_env(tmp_path, f"version_info = {major_minor}\nbase-executable = {sys.executable}\n")
|
|
33
|
-
|
|
34
|
-
assert _health_check(prefix, version) is None
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def test_health_check_full_version_passes(tmp_path: Path) -> None:
|
|
38
|
-
prefix = _make_env(tmp_path, f"version_info = {full_version}\nbase-executable = {sys.executable}\n")
|
|
39
|
-
|
|
40
|
-
assert _health_check(prefix, version) is None
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def test_health_check_no_base_executable_passes(tmp_path: Path) -> None:
|
|
44
|
-
prefix = _make_env(tmp_path, f"version_info = {major_minor}\n")
|
|
45
|
-
|
|
46
|
-
assert _health_check(prefix, version) is None
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def test_health_check_version_mismatch_fails(tmp_path: Path) -> None:
|
|
50
|
-
prefix = _make_env(tmp_path, f"version_info = {wrong_version}\n")
|
|
51
|
-
|
|
52
|
-
result = _health_check(prefix, version)
|
|
53
|
-
|
|
54
|
-
assert result is not None
|
|
55
|
-
assert "virtualenv python version did not match created version" in result
|
|
56
|
-
assert f"- expected version: {wrong_version}" in result
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def test_health_check_base_executable_mismatch_fails(tmp_path: Path) -> None:
|
|
60
|
-
prefix = _make_env(tmp_path, f"version_info = {major_minor}\nbase-executable = /does/not/exist/python\n")
|
|
61
|
-
|
|
62
|
-
result = _health_check(prefix, version)
|
|
63
|
-
|
|
64
|
-
assert result is not None
|
|
65
|
-
assert "base executable version did not match created version" in result
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def test_health_check_missing_pyvenv_cfg(tmp_path: Path) -> None:
|
|
69
|
-
prefix = _make_env(tmp_path, None)
|
|
70
|
-
|
|
71
|
-
assert _health_check(prefix, version) == "pyvenv.cfg does not exist (old virtualenv?)"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def test_health_check_missing_version_info(tmp_path: Path) -> None:
|
|
75
|
-
prefix = _make_env(tmp_path, "home = /usr\n")
|
|
76
|
-
|
|
77
|
-
assert _health_check(prefix, version) == "created virtualenv's pyvenv.cfg is missing `version_info`"
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import sys
|
|
4
|
-
from importlib.metadata import version
|
|
5
|
-
from subprocess import check_call, check_output
|
|
6
|
-
from textwrap import dedent
|
|
7
|
-
from typing import TYPE_CHECKING
|
|
8
|
-
|
|
9
|
-
import pytest
|
|
10
|
-
from pre_commit import main
|
|
11
|
-
|
|
12
|
-
if TYPE_CHECKING:
|
|
13
|
-
from pathlib import Path
|
|
14
|
-
|
|
15
|
-
precommit_file = ".pre-commit-config.yaml"
|
|
16
|
-
uv = version("uv")
|
|
17
|
-
self = version("pre-commit-uv")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@pytest.fixture
|
|
21
|
-
def git_repo(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
|
|
22
|
-
conf = """
|
|
23
|
-
repos:
|
|
24
|
-
- repo: https://github.com/tox-dev/pyproject-fmt
|
|
25
|
-
rev: "2.2.0"
|
|
26
|
-
hooks:
|
|
27
|
-
- id: pyproject-fmt
|
|
28
|
-
"""
|
|
29
|
-
conf_file = tmp_path / precommit_file
|
|
30
|
-
conf_file.write_text(dedent(conf))
|
|
31
|
-
monkeypatch.setenv("PRE_COMMIT_HOME", str(tmp_path / "store"))
|
|
32
|
-
monkeypatch.chdir(tmp_path)
|
|
33
|
-
check_call(["git", "init"])
|
|
34
|
-
return tmp_path
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@pytest.fixture
|
|
38
|
-
def install_hook(git_repo: Path) -> None:
|
|
39
|
-
check_call(["pre-commit", "install", "--install-hooks", "-c", str(git_repo / precommit_file)])
|
|
40
|
-
check_call(["pre-commit", "clean"]) # ensures that 'install_environment' gets called
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
@pytest.mark.usefixtures("install_hook")
|
|
44
|
-
def test_run_precommit_hook() -> None:
|
|
45
|
-
hook_result = check_output([".git/hooks/pre-commit"], encoding="utf-8")
|
|
46
|
-
assert f"[INFO] Using pre-commit with uv {uv} via pre-commit-uv {self}" in hook_result.splitlines()
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
@pytest.mark.usefixtures("install_hook")
|
|
50
|
-
def test_call_as_module() -> None:
|
|
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()
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def test_install(git_repo: Path, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
56
|
-
monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
|
|
57
|
-
|
|
58
|
-
import pre_commit_uv # ruff:ignore[import-outside-top-level]
|
|
59
|
-
|
|
60
|
-
pre_commit_uv._patch() # ruff:ignore[private-member-access]
|
|
61
|
-
main.main(["install-hooks", "-c", str(git_repo / precommit_file)])
|
|
62
|
-
|
|
63
|
-
assert caplog.messages == [
|
|
64
|
-
"Initializing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
65
|
-
"Installing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
66
|
-
"Once installed this environment will be reused.",
|
|
67
|
-
"This may take a few minutes...",
|
|
68
|
-
f"Using pre-commit with uv {uv} via pre-commit-uv {self}",
|
|
69
|
-
]
|
|
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 # ruff:ignore[import-outside-top-level]
|
|
76
|
-
|
|
77
|
-
pre_commit_uv._patch() # ruff:ignore[private-member-access]
|
|
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
|
-
|
|
87
|
-
test_install_with_uv_config_cases: list[tuple[str, str]] = [
|
|
88
|
-
(
|
|
89
|
-
"pyproject.toml",
|
|
90
|
-
"""
|
|
91
|
-
[[tool.uv.index]]
|
|
92
|
-
name = "internal"
|
|
93
|
-
url = "https://pypi.org/simple/"
|
|
94
|
-
default = true
|
|
95
|
-
""",
|
|
96
|
-
),
|
|
97
|
-
(
|
|
98
|
-
"uv.toml",
|
|
99
|
-
"""
|
|
100
|
-
[[index]]
|
|
101
|
-
name = "internal"
|
|
102
|
-
url = "https://pypi.org/simple/"
|
|
103
|
-
default = true
|
|
104
|
-
""",
|
|
105
|
-
),
|
|
106
|
-
]
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
@pytest.mark.parametrize(
|
|
110
|
-
("file_name", "content"),
|
|
111
|
-
test_install_with_uv_config_cases,
|
|
112
|
-
)
|
|
113
|
-
def test_install_with_uv_config(
|
|
114
|
-
git_repo: Path,
|
|
115
|
-
caplog: pytest.LogCaptureFixture,
|
|
116
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
117
|
-
file_name: str,
|
|
118
|
-
content: str,
|
|
119
|
-
) -> None:
|
|
120
|
-
(git_repo / file_name).write_text(dedent(content))
|
|
121
|
-
|
|
122
|
-
monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
|
|
123
|
-
|
|
124
|
-
import pre_commit_uv # ruff:ignore[import-outside-top-level]
|
|
125
|
-
|
|
126
|
-
pre_commit_uv._patch() # ruff:ignore[private-member-access]
|
|
127
|
-
main.main(["install-hooks", "-c", str(git_repo / precommit_file)])
|
|
128
|
-
|
|
129
|
-
assert caplog.messages == [
|
|
130
|
-
"Initializing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
131
|
-
"Installing environment for https://github.com/tox-dev/pyproject-fmt.",
|
|
132
|
-
"Once installed this environment will be reused.",
|
|
133
|
-
"This may take a few minutes...",
|
|
134
|
-
f"Using pre-commit with uv {uv} via pre-commit-uv {self}",
|
|
135
|
-
]
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
test_install_with_uv_config_raises_error_cases: list[tuple[str, str]] = [
|
|
139
|
-
(
|
|
140
|
-
"pyproject.toml",
|
|
141
|
-
"""
|
|
142
|
-
[[tool.uv.index]]
|
|
143
|
-
name = "internal"
|
|
144
|
-
url = "https://pypi.example/simple/"
|
|
145
|
-
default = true
|
|
146
|
-
""",
|
|
147
|
-
),
|
|
148
|
-
(
|
|
149
|
-
"uv.toml",
|
|
150
|
-
"""
|
|
151
|
-
[[index]]
|
|
152
|
-
name = "internal"
|
|
153
|
-
url = "https://pypi.example/simple/"
|
|
154
|
-
default = true
|
|
155
|
-
""",
|
|
156
|
-
),
|
|
157
|
-
]
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
@pytest.mark.parametrize(("file_name", "content"), test_install_with_uv_config_raises_error_cases)
|
|
161
|
-
def test_install_with_uv_config_raises_error(
|
|
162
|
-
git_repo: Path,
|
|
163
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
164
|
-
file_name: str,
|
|
165
|
-
content: str,
|
|
166
|
-
) -> None:
|
|
167
|
-
"""Test to make sure that uv config is used for non default pypi repos."""
|
|
168
|
-
(git_repo / file_name).write_text(dedent(content))
|
|
169
|
-
|
|
170
|
-
monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
|
|
171
|
-
|
|
172
|
-
import pre_commit_uv # ruff:ignore[import-outside-top-level]
|
|
173
|
-
|
|
174
|
-
pre_commit_uv._patch() # ruff:ignore[private-member-access]
|
|
175
|
-
|
|
176
|
-
# would raise SystemExit due to bad config
|
|
177
|
-
with pytest.raises(SystemExit):
|
|
178
|
-
main.main(["install-hooks", "-c", str(git_repo / precommit_file)])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|