Skip to content

Commit 1d1750e

Browse files
committed
fix: allow installation of uv workspaces sourced packages
Fixes: #233
1 parent 892ad41 commit 1d1750e

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/tox_uv/_installer.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import logging
66
from collections import defaultdict
77
from collections.abc import Sequence
8+
from functools import cached_property
89
from itertools import chain
910
from typing import TYPE_CHECKING, Any, Final
1011

12+
import tomllib
1113
from packaging.requirements import Requirement
1214
from packaging.utils import parse_sdist_filename, parse_wheel_filename
1315
from tox.config.types import Command
@@ -101,6 +103,17 @@ def install(self, arguments: Any, section: str, of_type: str) -> None: # noqa:
101103
_LOGGER.warning("uv cannot install %r", arguments) # pragma: no cover
102104
raise SystemExit(1) # pragma: no cover
103105

106+
@cached_property
107+
def _sourced_pkg_names(self) -> set[str]:
108+
pyproject_file = self._env.conf._conf.src_path.parent / "pyproject.toml" # noqa: SLF001
109+
if not pyproject_file.exists(): # check if it's static PEP-621 metadata
110+
return set()
111+
with pyproject_file.open("rb") as file_handler:
112+
pyproject = tomllib.load(file_handler)
113+
114+
sources = pyproject.get("tool", {}).get("uv", {}).get("sources", {})
115+
return {key for key, val in sources.items() if val.get("workspace", False)}
116+
104117
def _install_list_of_deps( # noqa: C901, PLR0912
105118
self,
106119
arguments: Sequence[
@@ -114,7 +127,15 @@ def _install_list_of_deps( # noqa: C901, PLR0912
114127
if isinstance(arg, Requirement): # pragma: no branch
115128
groups["req"].append(str(arg)) # pragma: no cover
116129
elif isinstance(arg, (WheelPackage, SdistPackage, EditablePackage)):
117-
groups["req"].extend(str(i) for i in arg.deps)
130+
for i in arg.deps:
131+
if (
132+
isinstance(i, Requirement)
133+
and i.name in self._sourced_pkg_names
134+
and "." not in groups["uv_editable"]
135+
):
136+
groups["uv_editable"].append(".")
137+
continue
138+
groups["req"].append(str(i))
118139
parser = parse_sdist_filename if isinstance(arg, SdistPackage) else parse_wheel_filename
119140
name, *_ = parser(arg.path.name)
120141
groups["pkg"].append(f"{name}@{arg.path}")

0 commit comments

Comments
 (0)