33from __future__ import annotations
44
55import logging
6+ import sys
67from collections import defaultdict
78from collections .abc import Sequence
9+ from functools import cached_property
810from itertools import chain
911from typing import TYPE_CHECKING , Any , Final
1012
13+ if sys .version_info >= (3 , 11 ): # pragma: no cover (py311+)
14+ import tomllib
15+ else : # pragma: no cover (py311+)
16+ import tomli as tomllib
1117from packaging .requirements import Requirement
1218from packaging .utils import parse_sdist_filename , parse_wheel_filename
1319from tox .config .types import Command
@@ -101,6 +107,17 @@ def install(self, arguments: Any, section: str, of_type: str) -> None: # noqa:
101107 _LOGGER .warning ("uv cannot install %r" , arguments ) # pragma: no cover
102108 raise SystemExit (1 ) # pragma: no cover
103109
110+ @cached_property
111+ def _sourced_pkg_names (self ) -> set [str ]:
112+ pyproject_file = self ._env .conf ._conf .src_path .parent / "pyproject.toml" # noqa: SLF001
113+ if not pyproject_file .exists (): # pragma: no cover
114+ return set ()
115+ with pyproject_file .open ("rb" ) as file_handler :
116+ pyproject = tomllib .load (file_handler )
117+
118+ sources = pyproject .get ("tool" , {}).get ("uv" , {}).get ("sources" , {})
119+ return {key for key , val in sources .items () if val .get ("workspace" , False )}
120+
104121 def _install_list_of_deps ( # noqa: C901, PLR0912
105122 self ,
106123 arguments : Sequence [
@@ -114,7 +131,15 @@ def _install_list_of_deps( # noqa: C901, PLR0912
114131 if isinstance (arg , Requirement ): # pragma: no branch
115132 groups ["req" ].append (str (arg )) # pragma: no cover
116133 elif isinstance (arg , (WheelPackage , SdistPackage , EditablePackage )):
117- groups ["req" ].extend (str (i ) for i in arg .deps )
134+ for i in arg .deps :
135+ if (
136+ isinstance (i , Requirement )
137+ and i .name in self ._sourced_pkg_names
138+ and "." not in groups ["uv_editable" ]
139+ ):
140+ groups ["uv_editable" ].append ("." )
141+ continue
142+ groups ["req" ].append (str (i ))
118143 parser = parse_sdist_filename if isinstance (arg , SdistPackage ) else parse_wheel_filename
119144 name , * _ = parser (arg .path .name )
120145 groups ["pkg" ].append (f"{ name } @{ arg .path } " )
0 commit comments