Skip to content

Commit

Permalink
Merge pull request #162 from sbidoul/no-local-uv
Browse files Browse the repository at this point in the history
Make uv an optional dependency again
  • Loading branch information
sbidoul authored Nov 30, 2024
2 parents 9da90df + 82c20cc commit 65451a3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/162.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make `uv` and optional dependency again.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ dependencies=[
"typer >=0.12.1",
# installers
"pip >=22.2",
"uv >=0.2.37",
# compat
"importlib_resources>=1.3 ; python_version<'3.9'",
"tomli ; python_version<'3.11'",
Expand All @@ -41,6 +40,7 @@ dynamic = ["version"]
[project.optional-dependencies]
"test" = ["pytest", "pytest-cov", "pytest-xdist", "virtualenv", "setuptools", "wheel"]
"mypy" = ["mypy", "types-toml", "types-setuptools"]
"uv" = ["uv >=0.4.10"]

[project.scripts]
pip-df = "pip_deepfreeze.__main__:main"
Expand Down
8 changes: 4 additions & 4 deletions src/pip_deepfreeze/pip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import shlex
import sys
import textwrap
from abc import ABC, abstractmethod
from enum import Enum
Expand Down Expand Up @@ -33,6 +32,7 @@
get_pip_command,
get_pip_version,
get_python_version_info,
get_uv_cmd,
)
from .utils import (
check_call,
Expand Down Expand Up @@ -115,7 +115,7 @@ def has_metadata_cache(self) -> bool:

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

def editable_install_cmd(
self,
Expand All @@ -130,10 +130,10 @@ def editable_install_cmd(
return cmd

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

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

def has_metadata_cache(self) -> bool:
return True
Expand Down
15 changes: 15 additions & 0 deletions src/pip_deepfreeze/sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
from functools import lru_cache
from importlib.metadata import version
from shutil import which
from typing import Optional, Tuple, TypedDict, cast

import typer
Expand Down Expand Up @@ -47,6 +48,20 @@ def get_pip_version(python: str) -> Version:
return Version(version("pip"))


@lru_cache
def get_uv_cmd() -> Tuple[str, ...]:
try:
import uv # type: ignore[import-not-found]
except ImportError as e:
uv = which("uv")
if not uv:
log_error("uv is not installed.")
raise typer.Exit(1) from e
return (uv,)
else:
return (sys.executable, "-m", "uv")


@lru_cache
def get_pip_command(python: str) -> Tuple[str, ...]:
pip_options = ("--no-input",)
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ python =
3.12: py312,mypy,twine_check

[testenv]
extras = test
extras =
test
uv
usedevelop = true
commands =
pytest -vv -n auto --cov --cov-branch --cov-report=xml --cov-report=html --cov-report=term {posargs}
Expand Down

0 comments on commit 65451a3

Please sign in to comment.