pre-commit-uv 4.0.0__tar.gz → 4.0.2__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.0.0
3
+ Version: 4.0.2
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
@@ -56,6 +56,48 @@ Description-Content-Type: text/markdown
56
56
 
57
57
  Use `uv` to create virtual environments and install packages for `pre-commit`.
58
58
 
59
+ ## Installation
60
+
61
+ With pipx:
62
+
63
+ ```shell
64
+ pipx install pre-commit
65
+ pipx inject pre-commit pre-commit-uv
66
+ ```
67
+
68
+ With uv:
69
+
70
+ ```shell
71
+ uv tool install pre-commit --with pre-commit-uv --force-reinstall
72
+ ```
73
+
74
+ ## Why?
75
+
76
+ Compared to upstream `pre-commit` will speed up the initial seed operation. In general, upstream recommends caching the
77
+ `pre-commit` cache, however, that is not always possible and is still helpful to have a more performant initial cache
78
+ creation., Here's an example of what you could expect demonstrated on this project's own pre-commit setup (with a hot
79
+ `uv` cache):
80
+
81
+ ```shell
82
+ ❯ hyperfine 'pre-commit install-hooks' 'pre-commit-uv install-hooks'
83
+ Benchmark 1: pre-commit install-hooks
84
+ Time (mean ± σ): 54.132 s ± 8.827 s [User: 15.424 s, System: 9.359 s]
85
+ Range (min … max): 45.972 s … 66.506 s 10 runs
86
+
87
+ Benchmark 2: pre-commit-uv install-hooks
88
+ Time (mean ± σ): 41.695 s ± 7.395 s [User: 7.614 s, System: 6.133 s]
89
+ Range (min … max): 32.198 s … 58.467 s 10 runs
90
+
91
+ Summary
92
+ pre-commit-uv install-hooks ran 1.30 ± 0.31 times faster than pre-commit install-hooks
93
+ ```
94
+
59
95
  ## Configuration
60
96
 
61
- Once installed will use `uv` out of box, however the `DISABLE_PRE_COMMIT_UV_PATCH` environment variable if set will work as an escape hatch.
97
+ Once installed will use `uv` out of box, however the `DISABLE_PRE_COMMIT_UV_PATCH` environment variable if is set it
98
+ will work as an escape hatch to disable the new behavior.
99
+
100
+ To avoid interpreter startup overhead of the patching, we only perform this when we detect you calling `pre-commit`.
101
+ Should this logic fail you can force the patching by setting the `FORCE_PRE_COMMIT_UV_PATCH` variable. Should you
102
+ experience this please raise an issue with the content of the `sys.argv`. Note that `DISABLE_PRE_COMMIT_UV_PATCH` will
103
+ overwrite this flag should both be set.
@@ -0,0 +1,56 @@
1
+ # pre-commit-uv
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/pre-commit-uv?style=flat-square)](https://pypi.org/project/pre-commit-uv)
4
+ [![PyPI - Implementation](https://img.shields.io/pypi/implementation/pre-commit-uv?style=flat-square)](https://pypi.org/project/pre-commit-uv)
5
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pre-commit-uv?style=flat-square)](https://pypi.org/project/pre-commit-uv)
6
+ [![Downloads](https://static.pepy.tech/badge/pre-commit-uv/month)](https://pepy.tech/project/pre-commit-uv)
7
+ [![PyPI - License](https://img.shields.io/pypi/l/pre-commit-uv?style=flat-square)](https://opensource.org/licenses/MIT)
8
+ [![check](https://github.com/tox-dev/pre-commit-uv/actions/workflows/check.yml/badge.svg)](https://github.com/tox-dev/pre-commit-uv/actions/workflows/check.yml)
9
+
10
+ Use `uv` to create virtual environments and install packages for `pre-commit`.
11
+
12
+ ## Installation
13
+
14
+ With pipx:
15
+
16
+ ```shell
17
+ pipx install pre-commit
18
+ pipx inject pre-commit pre-commit-uv
19
+ ```
20
+
21
+ With uv:
22
+
23
+ ```shell
24
+ uv tool install pre-commit --with pre-commit-uv --force-reinstall
25
+ ```
26
+
27
+ ## Why?
28
+
29
+ Compared to upstream `pre-commit` will speed up the initial seed operation. In general, upstream recommends caching the
30
+ `pre-commit` cache, however, that is not always possible and is still helpful to have a more performant initial cache
31
+ creation., Here's an example of what you could expect demonstrated on this project's own pre-commit setup (with a hot
32
+ `uv` cache):
33
+
34
+ ```shell
35
+ ❯ hyperfine 'pre-commit install-hooks' 'pre-commit-uv install-hooks'
36
+ Benchmark 1: pre-commit install-hooks
37
+ Time (mean ± σ): 54.132 s ± 8.827 s [User: 15.424 s, System: 9.359 s]
38
+ Range (min … max): 45.972 s … 66.506 s 10 runs
39
+
40
+ Benchmark 2: pre-commit-uv install-hooks
41
+ Time (mean ± σ): 41.695 s ± 7.395 s [User: 7.614 s, System: 6.133 s]
42
+ Range (min … max): 32.198 s … 58.467 s 10 runs
43
+
44
+ Summary
45
+ pre-commit-uv install-hooks ran 1.30 ± 0.31 times faster than pre-commit install-hooks
46
+ ```
47
+
48
+ ## Configuration
49
+
50
+ Once installed will use `uv` out of box, however the `DISABLE_PRE_COMMIT_UV_PATCH` environment variable if is set it
51
+ will work as an escape hatch to disable the new behavior.
52
+
53
+ To avoid interpreter startup overhead of the patching, we only perform this when we detect you calling `pre-commit`.
54
+ Should this logic fail you can force the patching by setting the `FORCE_PRE_COMMIT_UV_PATCH` variable. Should you
55
+ experience this please raise an issue with the content of the `sys.argv`. Note that `DISABLE_PRE_COMMIT_UV_PATCH` will
56
+ overwrite this flag should both be set.
@@ -55,7 +55,8 @@ build.targets.sdist.include = [
55
55
  "/tests",
56
56
  "tox.ini",
57
57
  ]
58
- build.targets.wheel.force-include = { "src/pre_commit_uv_patch.pth" = "pre_commit_uv_patch.pth" }
58
+ build.targets.wheel.only-include = [ "src" ]
59
+ build.targets.wheel.sources = [ "src" ]
59
60
  version.source = "vcs"
60
61
 
61
62
  [tool.ruff]
@@ -86,8 +87,8 @@ lint.per-file-ignores."tests/**/*.py" = [
86
87
  "PLR0913", # any number of arguments in tests
87
88
  "PLR0917", # any number of arguments in tests
88
89
  "PLR2004", # Magic value used in comparison, consider replacing with a constant variable
90
+ "S", # `subprocess` call: check for execution of untrusted input
89
91
  "S101", # asserts allowed in tests...
90
- "S603", # `subprocess` call: check for execution of untrusted input
91
92
  ]
92
93
  lint.isort = { known-first-party = [
93
94
  "pre_commit_uv",
@@ -117,7 +118,7 @@ paths.source = [
117
118
  "**/src",
118
119
  "**\\src",
119
120
  ]
120
- report.fail_under = 50
121
+ report.fail_under = 65
121
122
  run.parallel = true
122
123
  run.plugins = [
123
124
  "covdefaults",
@@ -0,0 +1,93 @@
1
+ """Package root."""
2
+
3
+ from __future__ import annotations
4
+
5
+ # only import built-ins at top level to avoid interpreter startup overhead
6
+ import os
7
+ import sys
8
+
9
+ _original_main = None
10
+
11
+
12
+ def _patch() -> None:
13
+ global _original_main
14
+ if _original_main is not None: # already patched, nothing more to do
15
+ 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 os.path.split(calling)[1] == f"pre-commit{'.exe' if sys.platform == 'win32' else ''}":
20
+ calling_pre_commit = True
21
+
22
+ if calling_pre_commit and os.environ.get("DISABLE_PRE_COMMIT_UV_PATCH") is None:
23
+ from pre_commit import main # noqa: PLC0415
24
+
25
+ _original_main, main.main = main.main, _new_main
26
+
27
+
28
+ def _new_main(argv: list[str] | None = None) -> int:
29
+ # imports applied locally to avoid patching import overhead cost
30
+ from functools import cache # noqa: PLC0415
31
+ from typing import TYPE_CHECKING, cast # noqa: PLC0415
32
+
33
+ from pre_commit.languages import python # noqa: PLC0415
34
+
35
+ if TYPE_CHECKING:
36
+ from collections.abc import Sequence # noqa: PLC0415
37
+
38
+ from pre_commit.prefix import Prefix # noqa: PLC0415
39
+
40
+ def _install_environment(
41
+ prefix: Prefix,
42
+ version: str,
43
+ additional_dependencies: Sequence[str],
44
+ ) -> None:
45
+ import logging # noqa: PLC0415
46
+
47
+ from pre_commit.lang_base import environment_dir, setup_cmd # noqa: PLC0415
48
+ from pre_commit.util import cmd_output_b # noqa: PLC0415
49
+
50
+ logger = logging.getLogger("pre_commit")
51
+ logger.info("Using pre-commit with uv %s via pre-commit-uv %s", uv_version(), self_version())
52
+ uv = _uv()
53
+ venv_cmd = [uv, "venv", environment_dir(prefix, python.ENVIRONMENT_DIR, version)]
54
+ py = python.norm_version(version)
55
+ if py is not None:
56
+ venv_cmd.extend(("-p", py))
57
+ cmd_output_b(*venv_cmd, cwd="/")
58
+
59
+ with python.in_env(prefix, version):
60
+ setup_cmd(prefix, (uv, "pip", "install", ".", *additional_dependencies))
61
+
62
+ @cache
63
+ def _uv() -> str:
64
+ from uv import find_uv_bin # noqa: PLC0415
65
+
66
+ return find_uv_bin()
67
+
68
+ @cache
69
+ def self_version() -> str:
70
+ from importlib.metadata import version as _metadata_version # noqa: PLC0415
71
+
72
+ return _metadata_version("pre-commit-uv")
73
+
74
+ @cache
75
+ def uv_version() -> str:
76
+ from importlib.metadata import version as _metadata_version # noqa: PLC0415
77
+
78
+ return _metadata_version("uv")
79
+
80
+ @cache
81
+ def _version_info(exe: str) -> str:
82
+ from pre_commit.util import CalledProcessError, cmd_output # noqa: PLC0415
83
+
84
+ prog = 'import sys;print(".".join(str(p) for p in sys.version_info[0:3]))'
85
+ try:
86
+ return cast(str, cmd_output(exe, "-S", "-c", prog)[1].strip())
87
+ except CalledProcessError:
88
+ return f"<<error retrieving version from {exe}>>"
89
+
90
+ python.install_environment = _install_environment
91
+ python._version_info = _version_info # noqa: SLF001
92
+ assert _original_main is not None # noqa: S101
93
+ return cast(int, _original_main(argv))
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from importlib.metadata import version
4
+ from subprocess import check_call
4
5
  from textwrap import dedent
5
6
  from typing import TYPE_CHECKING
6
7
 
@@ -23,6 +24,8 @@ def test_install(tmp_path: Path, caplog: pytest.LogCaptureFixture, monkeypatch:
23
24
  conf_file = tmp_path / ".pre-commit-config.yaml"
24
25
  conf_file.write_text(dedent(conf))
25
26
  monkeypatch.setenv("PRE_COMMIT_HOME", str(tmp_path / "store"))
27
+ monkeypatch.chdir(tmp_path)
28
+ check_call(["git", "init"])
26
29
 
27
30
  main.main(["install-hooks", "-c", str(conf_file)])
28
31
 
@@ -1,14 +1,14 @@
1
1
  [tox]
2
2
  requires =
3
- tox>=4.2
3
+ tox>=4.17.1
4
4
  env_list =
5
5
  fix
6
- py312
7
- py311
8
- py310
9
- py39
10
6
  type
11
7
  readme
8
+ 3.12
9
+ 3.11
10
+ 3.10
11
+ 3.9
12
12
  skip_missing_interpreters = true
13
13
 
14
14
  [testenv]
@@ -17,10 +17,11 @@ package = wheel
17
17
  wheel_build_env = .pkg
18
18
  extras =
19
19
  test
20
+ pass_env =
21
+ PYTEST_ADDOPTS
20
22
  set_env =
21
23
  COVERAGE_FILE = {toxworkdir}/.coverage.{envname}
22
- COVERAGE_PROCESS_START = {toxinidir}/setup.cfg
23
- _COVERAGE_SRC = {envsitepackagesdir}/sphinx_argparse_cli
24
+ FORCE_PRE_COMMIT_UV_PATCH = true
24
25
  commands =
25
26
  python -m pytest {tty:--color=yes} {posargs: \
26
27
  --junitxml {toxworkdir}{/}junit.{envname}.xml --cov {envsitepackagesdir}{/}pre_commit_uv \
@@ -52,11 +53,13 @@ commands =
52
53
  description = check that the long description is valid
53
54
  skip_install = true
54
55
  deps =
55
- build[virtualenv]>=1.2.1
56
+ build[uv]>=1.2.1
57
+ check-wheel-contents>=0.6
56
58
  twine>=5.1.1
57
59
  commands =
58
- python -m build --sdist --wheel -o {envtmpdir} .
60
+ python -m build --installer uv --sdist --wheel -o {envtmpdir} .
59
61
  twine check {envtmpdir}/*
62
+ check-wheel-contents {envtmpdir}
60
63
 
61
64
  [testenv:dev]
62
65
  description = generate a DEV environment
@@ -64,8 +67,9 @@ package = editable
64
67
  extras =
65
68
  docs
66
69
  test
70
+ set_env =
71
+ FORCE_PRE_COMMIT_UV_PATCH = true
67
72
  commands =
68
- python -c "import shutil; shutil.copy2('src{/}pre_commit_uv_patch.pth', '{env_site_packages_dir}{/}pre_commit_uv_patch.pth')"
69
- python -m pip list --format=columns
73
+ uv tree
70
74
  python -c 'import sys; print(sys.executable)'
71
- uv_seed = true
75
+ python task/dev_pth.py {env_site_packages_dir}
@@ -1,14 +0,0 @@
1
- # pre-commit-uv
2
-
3
- [![PyPI](https://img.shields.io/pypi/v/pre-commit-uv?style=flat-square)](https://pypi.org/project/pre-commit-uv)
4
- [![PyPI - Implementation](https://img.shields.io/pypi/implementation/pre-commit-uv?style=flat-square)](https://pypi.org/project/pre-commit-uv)
5
- [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pre-commit-uv?style=flat-square)](https://pypi.org/project/pre-commit-uv)
6
- [![Downloads](https://static.pepy.tech/badge/pre-commit-uv/month)](https://pepy.tech/project/pre-commit-uv)
7
- [![PyPI - License](https://img.shields.io/pypi/l/pre-commit-uv?style=flat-square)](https://opensource.org/licenses/MIT)
8
- [![check](https://github.com/tox-dev/pre-commit-uv/actions/workflows/check.yml/badge.svg)](https://github.com/tox-dev/pre-commit-uv/actions/workflows/check.yml)
9
-
10
- Use `uv` to create virtual environments and install packages for `pre-commit`.
11
-
12
- ## Configuration
13
-
14
- Once installed will use `uv` out of box, however the `DISABLE_PRE_COMMIT_UV_PATCH` environment variable if set will work as an escape hatch.
@@ -1,68 +0,0 @@
1
- """Package root."""
2
-
3
- from __future__ import annotations
4
-
5
- import logging
6
- import os
7
- from functools import cache
8
- from importlib.metadata import version as _metadata_version
9
- from typing import TYPE_CHECKING, cast
10
-
11
- from pre_commit import lang_base, main
12
- from pre_commit.languages import python
13
- from pre_commit.languages.python import in_env, norm_version
14
- from pre_commit.util import CalledProcessError, cmd_output, cmd_output_b
15
- from uv import find_uv_bin
16
-
17
- if TYPE_CHECKING:
18
- from collections.abc import Sequence
19
-
20
- from pre_commit.prefix import Prefix
21
-
22
-
23
- __version__ = _metadata_version("pre-commit-uv")
24
- _uv_version = _metadata_version("uv")
25
- _original_main = main.main
26
-
27
-
28
- def _patch() -> None:
29
- if os.environ.get("DISABLE_PRE_COMMIT_UV_PATCH") is None:
30
- main.main = _new_main
31
-
32
-
33
- def _new_main(argv: Sequence[str] | None = None) -> int:
34
- python.install_environment = _install_environment
35
- python._version_info = _version_info # noqa: SLF001
36
- return cast(int, _original_main(argv))
37
-
38
-
39
- def _install_environment(
40
- prefix: Prefix,
41
- version: str,
42
- additional_dependencies: Sequence[str],
43
- ) -> None:
44
- logging.getLogger("pre_commit").info("Using pre-commit with uv %s via pre-commit-uv %s", _uv_version, __version__)
45
- uv = find_uv_bin()
46
-
47
- venv_cmd = [uv, "venv", lang_base.environment_dir(prefix, python.ENVIRONMENT_DIR, version)]
48
- py = norm_version(version)
49
- if py is not None:
50
- venv_cmd.extend(("-p", py))
51
- cmd_output_b(*venv_cmd, cwd="/")
52
-
53
- with in_env(prefix, version):
54
- lang_base.setup_cmd(prefix, (uv, "pip", "install", ".", *additional_dependencies))
55
-
56
-
57
- @cache
58
- def _version_info(exe: str) -> str:
59
- prog = 'import sys;print(".".join(str(p) for p in sys.version_info[0:3]))'
60
- try:
61
- return cast(str, cmd_output(exe, "-S", "-c", prog)[1].strip())
62
- except CalledProcessError:
63
- return f"<<error retrieving version from {exe}>>"
64
-
65
-
66
- __all__ = [
67
- "__version__",
68
- ]
File without changes
File without changes