pre-commit-uv 4.1.3__tar.gz → 4.1.5__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
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: pre-commit-uv
3
- Version: 4.1.3
3
+ Version: 4.1.5
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
@@ -59,22 +59,40 @@ def _new_main(argv: list[str] | None = None) -> int:
59
59
  ) -> None:
60
60
  import logging # noqa: PLC0415
61
61
 
62
+ from pre_commit.git import get_root # noqa: PLC0415
62
63
  from pre_commit.lang_base import environment_dir, setup_cmd # noqa: PLC0415
63
64
  from pre_commit.util import cmd_output_b # noqa: PLC0415
64
65
 
66
+ project_root_dir = get_root()
67
+
65
68
  logger = logging.getLogger("pre_commit")
66
69
  logger.info("Using pre-commit with uv %s via pre-commit-uv %s", uv_version(), self_version())
67
70
  uv = _uv()
68
- venv_cmd = [uv, "venv", environment_dir(prefix, python.ENVIRONMENT_DIR, version)]
69
- py = python.norm_version(version)
70
- if py is not None:
71
- venv_cmd.extend(("-p", py))
72
- env = os.environ.copy()
73
- env["UV_INTERNAL__PARENT_INTERPRETER"] = sys.executable
74
- cmd_output_b(*venv_cmd, cwd="/", env=env)
71
+ py = python.norm_version(version) or os.environ.get("UV_PYTHON", sys.executable)
72
+ venv_cmd = [
73
+ uv,
74
+ "--project",
75
+ project_root_dir,
76
+ "venv",
77
+ environment_dir(prefix, python.ENVIRONMENT_DIR, version),
78
+ "-p",
79
+ py,
80
+ ]
81
+ cmd_output_b(*venv_cmd, cwd="/")
75
82
 
76
83
  with python.in_env(prefix, version):
77
- setup_cmd(prefix, (uv, "pip", "install", ".", *additional_dependencies))
84
+ setup_cmd(
85
+ prefix,
86
+ (
87
+ uv,
88
+ "--project",
89
+ project_root_dir,
90
+ "pip",
91
+ "install",
92
+ ".",
93
+ *additional_dependencies,
94
+ ),
95
+ )
78
96
 
79
97
  @cache
80
98
  def _uv() -> str:
@@ -100,11 +118,11 @@ def _new_main(argv: list[str] | None = None) -> int:
100
118
 
101
119
  prog = 'import sys;print(".".join(str(p) for p in sys.version_info[0:3]))'
102
120
  try:
103
- return cast(str, cmd_output(exe, "-S", "-c", prog)[1].strip())
121
+ return cast("str", cmd_output(exe, "-S", "-c", prog)[1].strip())
104
122
  except CalledProcessError:
105
123
  return f"<<error retrieving version from {exe}>>"
106
124
 
107
125
  python.install_environment = _install_environment
108
126
  python._version_info = _version_info # noqa: SLF001
109
127
  assert _original_main is not None # noqa: S101
110
- return cast(int, _original_main(argv))
128
+ return cast("int", _original_main(argv))
@@ -66,3 +66,97 @@ def test_install(git_repo: Path, caplog: pytest.LogCaptureFixture, monkeypatch:
66
66
  "This may take a few minutes...",
67
67
  f"Using pre-commit with uv {uv} via pre-commit-uv {self}",
68
68
  ]
69
+
70
+
71
+ test_install_with_uv_config_cases: list[tuple[str, str]] = [
72
+ (
73
+ "pyproject.toml",
74
+ """
75
+ [[tool.uv.index]]
76
+ name = "internal"
77
+ url = "https://pypi.org/simple/"
78
+ default = true
79
+ """,
80
+ ),
81
+ (
82
+ "uv.toml",
83
+ """
84
+ [[index]]
85
+ name = "internal"
86
+ url = "https://pypi.org/simple/"
87
+ default = true
88
+ """,
89
+ ),
90
+ ]
91
+
92
+
93
+ @pytest.mark.parametrize(
94
+ ("file_name", "content"),
95
+ test_install_with_uv_config_cases,
96
+ )
97
+ def test_install_with_uv_config(
98
+ git_repo: Path,
99
+ caplog: pytest.LogCaptureFixture,
100
+ monkeypatch: pytest.MonkeyPatch,
101
+ file_name: str,
102
+ content: str,
103
+ ) -> None:
104
+ (git_repo / file_name).write_text(dedent(content))
105
+
106
+ monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
107
+
108
+ import pre_commit_uv # noqa: PLC0415
109
+
110
+ pre_commit_uv._patch() # noqa: SLF001
111
+ main.main(["install-hooks", "-c", str(git_repo / precommit_file)])
112
+
113
+ assert caplog.messages == [
114
+ "Initializing environment for https://github.com/tox-dev/pyproject-fmt.",
115
+ "Installing environment for https://github.com/tox-dev/pyproject-fmt.",
116
+ "Once installed this environment will be reused.",
117
+ "This may take a few minutes...",
118
+ f"Using pre-commit with uv {uv} via pre-commit-uv {self}",
119
+ ]
120
+
121
+
122
+ test_install_with_uv_config_raises_error_cases: list[tuple[str, str]] = [
123
+ (
124
+ "pyproject.toml",
125
+ """
126
+ [[tool.uv.index]]
127
+ name = "internal"
128
+ url = "https://pypi.example/simple/"
129
+ default = true
130
+ """,
131
+ ),
132
+ (
133
+ "uv.toml",
134
+ """
135
+ [[index]]
136
+ name = "internal"
137
+ url = "https://pypi.example/simple/"
138
+ default = true
139
+ """,
140
+ ),
141
+ ]
142
+
143
+
144
+ @pytest.mark.parametrize(("file_name", "content"), test_install_with_uv_config_raises_error_cases)
145
+ def test_install_with_uv_config_raises_error(
146
+ git_repo: Path,
147
+ monkeypatch: pytest.MonkeyPatch,
148
+ file_name: str,
149
+ content: str,
150
+ ) -> None:
151
+ """Test to make sure that uv config is used for non default pypi repos."""
152
+ (git_repo / file_name).write_text(dedent(content))
153
+
154
+ monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
155
+
156
+ import pre_commit_uv # noqa: PLC0415
157
+
158
+ pre_commit_uv._patch() # noqa: SLF001
159
+
160
+ # would raise SystemExit due to bad config
161
+ with pytest.raises(SystemExit):
162
+ main.main(["install-hooks", "-c", str(git_repo / precommit_file)])
File without changes
File without changes
File without changes
File without changes