Skip to content

Commit b73b920

Browse files
committed
Make uv an optional dependency again
1 parent b3f0d88 commit b73b920

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

news/162.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make `uv` and optional dependency again.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ dependencies=[
3131
"typer >=0.12.1",
3232
# installers
3333
"pip >=22.2",
34-
"uv >=0.2.37",
3534
# compat
3635
"importlib_resources>=1.3 ; python_version<'3.9'",
3736
"tomli ; python_version<'3.11'",
@@ -41,6 +40,7 @@ dynamic = ["version"]
4140
[project.optional-dependencies]
4241
"test" = ["pytest", "pytest-cov", "pytest-xdist", "virtualenv", "setuptools", "wheel"]
4342
"mypy" = ["mypy", "types-toml", "types-setuptools"]
43+
"uv" = ["uv >=0.4.10"]
4444

4545
[project.scripts]
4646
pip-df = "pip_deepfreeze.__main__:main"

src/pip_deepfreeze/pip.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import shlex
3-
import sys
43
import textwrap
54
from abc import ABC, abstractmethod
65
from enum import Enum
@@ -33,6 +32,7 @@
3332
get_pip_command,
3433
get_pip_version,
3534
get_python_version_info,
35+
get_uv_cmd,
3636
)
3737
from .utils import (
3838
check_call,
@@ -115,7 +115,7 @@ def has_metadata_cache(self) -> bool:
115115

116116
class UvpipInstaller(Installer):
117117
def install_cmd(self, python: str) -> List[str]:
118-
return [sys.executable, "-m", "uv", "pip", "install", "--python", python]
118+
return [*get_uv_cmd(), "pip", "install", "--python", python]
119119

120120
def editable_install_cmd(
121121
self,
@@ -130,10 +130,10 @@ def editable_install_cmd(
130130
return cmd
131131

132132
def uninstall_cmd(self, python: str) -> List[str]:
133-
return [sys.executable, "-m", "uv", "pip", "uninstall", "--python", python]
133+
return [*get_uv_cmd(), "pip", "uninstall", "--python", python]
134134

135135
def freeze_cmd(self, python: str) -> List[str]:
136-
return [sys.executable, "-m", "uv", "pip", "freeze", "--python", python]
136+
return [*get_uv_cmd(), "pip", "freeze", "--python", python]
137137

138138
def has_metadata_cache(self) -> bool:
139139
return True

src/pip_deepfreeze/sanity.py

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
from functools import lru_cache
66
from importlib.metadata import version
7+
from shutil import which
78
from typing import Optional, Tuple, TypedDict, cast
89

910
import typer
@@ -47,6 +48,20 @@ def get_pip_version(python: str) -> Version:
4748
return Version(version("pip"))
4849

4950

51+
@lru_cache
52+
def get_uv_cmd() -> tuple[str, ...]:
53+
try:
54+
import uv # type: ignore[import-not-found]
55+
except ImportError as e:
56+
uv = which("uv")
57+
if not uv:
58+
log_error("uv is not installed.")
59+
raise typer.Exit(1) from e
60+
return (uv,)
61+
else:
62+
return (sys.executable, "-m", "uv")
63+
64+
5065
@lru_cache
5166
def get_pip_command(python: str) -> Tuple[str, ...]:
5267
pip_options = ("--no-input",)

0 commit comments

Comments
 (0)