Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always install uv as a dependency #143

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ Using `pip <https://pypi.org/project/pip/>`__:
normally expect in an activated virtualenv), but you can ask it to work within
another environment using the ``--python`` option.

.. note::

``pip-deepfreeze`` has experimental support for the `uv
<https://github.com/astral-sh/uv>`_ installer. To use it, install with ``pipx install
pip-deepfreeze[uv]`` and run ``pip-df sync --installer=uv``.

Quick start
-----------

Expand Down Expand Up @@ -109,6 +103,12 @@ collaborating on the project can install the project and its known good
dependencies using ``pip-df sync`` (or ``pip install -r requirements.txt -e .``
in a fresh virtualenv).

.. note::

``pip-deepfreeze`` has experimental support for the `uv
<https://github.com/astral-sh/uv>`_ installer. To use it, run ``pip-df sync
--installer=uv``.

When you add or remove dependencies of your project, run ``pip-df sync`` again
to update your environment and ``requirements.txt``.

Expand Down
1 change: 1 addition & 0 deletions news/143.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Always install ``uv`` as a dependency. Consequently, the ``uv`` extra is removed.
2 changes: 1 addition & 1 deletion news/95.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Declare minimum pip-deepfreeze version in ``pyproject.toml``.
pip-deepfreeze verifies its version according to `tool.pip-deepfreeze.min_version`,
pip-deepfreeze verifies its version according to ``tool.pip-deepfreeze.min_version``,
so a project can ensure all contributors have the minmum required version.
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ classifiers = [
requires-python = ">=3.8"
dependencies=[
"httpx",
"packaging>=23",
"pip>=22.2",
"tomli ; python_version<'3.11'",
"typer[all]>=0.3.2",
"packaging >=23",
"typer[all] >=0.3.2",
# installers
"pip >=22.2",
"uv",
# compat
"importlib_resources>=1.3 ; python_version<'3.9'",
"tomli ; python_version<'3.11'",
]
dynamic = ["version"]

[project.optional-dependencies]
"uv" = ["uv"]
"test" = ["pytest", "pytest-cov", "pytest-xdist", "virtualenv", "setuptools", "wheel"]
"mypy" = ["mypy", "types-toml", "types-setuptools"]

Expand Down
6 changes: 1 addition & 5 deletions src/pip_deepfreeze/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .pip import Installer
from .pyproject_toml import load_pyproject_toml
from .sanity import check_env, get_python_version_info
from .sanity import check_env
from .sync import sync as sync_operation
from .tree import tree as tree_operation
from .utils import comma_split, increase_verbosity, log_debug, log_error
Expand Down Expand Up @@ -82,10 +82,6 @@ def sync(
update of dependencies to to the latest version that matches
constraints. Optionally uninstall unneeded dependencies.
"""
if installer == Installer.uv and get_python_version_info(ctx.obj.python) < (3, 7):
log_error("The 'uv' installer requires Python 3.7 or later.")
raise typer.Exit(1)

sync_operation(
ctx.obj.python,
upgrade_all,
Expand Down
21 changes: 8 additions & 13 deletions src/pip_deepfreeze/pip.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import importlib.util
import json
import os
import shlex
import sys
import textwrap
from enum import Enum
from functools import lru_cache
from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, TypedDict, cast

Expand All @@ -30,7 +28,12 @@
parse as parse_req_file,
)
from .req_parser import get_req_name
from .sanity import _get_env_info, get_pip_command, get_pip_version
from .sanity import (
_get_env_info,
get_pip_command,
get_pip_version,
get_python_version_info,
)
from .utils import (
check_call,
check_output,
Expand All @@ -54,11 +57,6 @@ class Installer(str, Enum):
uv = "uv"


@lru_cache
def _has_uv() -> bool:
return bool(importlib.util.find_spec("uv"))


def _pip_install_cmd_and_env(python: str) -> Tuple[List[str], Dict[str, str]]:
return [*get_pip_command(python), "install"], {}

Expand All @@ -77,11 +75,8 @@ def _install_cmd_and_env(
if installer == Installer.pip:
return _pip_install_cmd_and_env(python)
elif installer == Installer.uv:
if not _has_uv():
log_error(
"The 'uv' installer was requested but it is not available. "
"Please install pip-deepfreeze with the 'uv' extra to use it."
)
if get_python_version_info(python) < (3, 7):
log_error("The 'uv' installer requires Python 3.7 or later.")
raise typer.Exit(1)
return _uv_install_cmd_and_env(python)
raise NotImplementedError(f"Installer {installer} is not implemented.")
Expand Down
Loading