@@ -5,14 +5,14 @@ use uv_configuration::{LowerBound, SourceStrategy};
5
5
use uv_distribution_types:: IndexLocations ;
6
6
use uv_normalize:: PackageName ;
7
7
use uv_workspace:: pyproject:: ToolUvSources ;
8
- use uv_workspace:: { DiscoveryOptions , ProjectWorkspace } ;
8
+ use uv_workspace:: { DiscoveryOptions , ProjectWorkspace , Workspace } ;
9
9
10
- use crate :: metadata:: { GitWorkspaceMember , LoweredRequirement , MetadataError } ;
10
+ use crate :: metadata:: { LoweredRequirement , MetadataError } ;
11
11
12
12
/// Lowered requirements from a `[build-system.requires]` field in a `pyproject.toml` file.
13
13
#[ derive( Debug , Clone ) ]
14
14
pub struct BuildRequires {
15
- pub name : PackageName ,
15
+ pub name : Option < PackageName > ,
16
16
pub requires_dist : Vec < uv_pypi_types:: Requirement > ,
17
17
}
18
18
@@ -35,46 +35,31 @@ impl BuildRequires {
35
35
pub async fn from_project_maybe_workspace (
36
36
metadata : uv_pypi_types:: BuildRequires ,
37
37
install_path : & Path ,
38
- git_member : Option < & GitWorkspaceMember < ' _ > > ,
39
38
locations : & IndexLocations ,
40
39
sources : SourceStrategy ,
41
40
lower_bound : LowerBound ,
42
41
) -> Result < Self , MetadataError > {
43
42
// TODO(konsti): Cache workspace discovery.
44
- let discovery_options = if let Some ( git_member) = & git_member {
45
- DiscoveryOptions {
46
- stop_discovery_at : Some (
47
- git_member
48
- . fetch_root
49
- . parent ( )
50
- . expect ( "git checkout has a parent" ) ,
51
- ) ,
52
- ..Default :: default ( )
53
- }
54
- } else {
55
- DiscoveryOptions :: default ( )
56
- } ;
57
43
let Some ( project_workspace) =
58
- ProjectWorkspace :: from_maybe_project_root ( install_path, & discovery_options) . await ?
44
+ ProjectWorkspace :: from_maybe_project_root ( install_path, & DiscoveryOptions :: default ( ) )
45
+ . await ?
59
46
else {
60
47
return Ok ( Self :: from_metadata23 ( metadata) ) ;
61
48
} ;
62
49
63
50
Self :: from_project_workspace (
64
51
metadata,
65
52
& project_workspace,
66
- git_member,
67
53
locations,
68
54
sources,
69
55
lower_bound,
70
56
)
71
57
}
72
58
73
59
/// Lower the `build-system.requires` field from a `pyproject.toml` file.
74
- fn from_project_workspace (
60
+ pub fn from_project_workspace (
75
61
metadata : uv_pypi_types:: BuildRequires ,
76
62
project_workspace : & ProjectWorkspace ,
77
- git_member : Option < & GitWorkspaceMember < ' _ > > ,
78
63
locations : & IndexLocations ,
79
64
source_strategy : SourceStrategy ,
80
65
lower_bound : LowerBound ,
@@ -118,7 +103,7 @@ impl BuildRequires {
118
103
let group = None ;
119
104
LoweredRequirement :: from_requirement (
120
105
requirement,
121
- & metadata. name ,
106
+ metadata. name . as_ref ( ) ,
122
107
project_workspace. project_root ( ) ,
123
108
project_sources,
124
109
project_indexes,
@@ -127,7 +112,84 @@ impl BuildRequires {
127
112
locations,
128
113
project_workspace. workspace ( ) ,
129
114
lower_bound,
130
- git_member,
115
+ None ,
116
+ )
117
+ . map ( move |requirement| match requirement {
118
+ Ok ( requirement) => Ok ( requirement. into_inner ( ) ) ,
119
+ Err ( err) => Err ( MetadataError :: LoweringError (
120
+ requirement_name. clone ( ) ,
121
+ Box :: new ( err) ,
122
+ ) ) ,
123
+ } )
124
+ } )
125
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?,
126
+ SourceStrategy :: Disabled => requires_dist
127
+ . into_iter ( )
128
+ . map ( uv_pypi_types:: Requirement :: from)
129
+ . collect ( ) ,
130
+ } ;
131
+
132
+ Ok ( Self {
133
+ name : metadata. name ,
134
+ requires_dist,
135
+ } )
136
+ }
137
+
138
+ /// Lower the `build-system.requires` field from a `pyproject.toml` file.
139
+ pub fn from_workspace (
140
+ metadata : uv_pypi_types:: BuildRequires ,
141
+ workspace : & Workspace ,
142
+ locations : & IndexLocations ,
143
+ source_strategy : SourceStrategy ,
144
+ lower_bound : LowerBound ,
145
+ ) -> Result < Self , MetadataError > {
146
+ // Collect any `tool.uv.index` entries.
147
+ let empty = vec ! [ ] ;
148
+ let project_indexes = match source_strategy {
149
+ SourceStrategy :: Enabled => workspace
150
+ . pyproject_toml ( )
151
+ . tool
152
+ . as_ref ( )
153
+ . and_then ( |tool| tool. uv . as_ref ( ) )
154
+ . and_then ( |uv| uv. index . as_deref ( ) )
155
+ . unwrap_or ( & empty) ,
156
+ SourceStrategy :: Disabled => & empty,
157
+ } ;
158
+
159
+ // Collect any `tool.uv.sources` and `tool.uv.dev_dependencies` from `pyproject.toml`.
160
+ let empty = BTreeMap :: default ( ) ;
161
+ let project_sources = match source_strategy {
162
+ SourceStrategy :: Enabled => workspace
163
+ . pyproject_toml ( )
164
+ . tool
165
+ . as_ref ( )
166
+ . and_then ( |tool| tool. uv . as_ref ( ) )
167
+ . and_then ( |uv| uv. sources . as_ref ( ) )
168
+ . map ( ToolUvSources :: inner)
169
+ . unwrap_or ( & empty) ,
170
+ SourceStrategy :: Disabled => & empty,
171
+ } ;
172
+
173
+ // Lower the requirements.
174
+ let requires_dist = metadata. requires_dist . into_iter ( ) ;
175
+ let requires_dist = match source_strategy {
176
+ SourceStrategy :: Enabled => requires_dist
177
+ . flat_map ( |requirement| {
178
+ let requirement_name = requirement. name . clone ( ) ;
179
+ let extra = requirement. marker . top_level_extra_name ( ) ;
180
+ let group = None ;
181
+ LoweredRequirement :: from_requirement (
182
+ requirement,
183
+ None ,
184
+ workspace. install_path ( ) ,
185
+ project_sources,
186
+ project_indexes,
187
+ extra. as_ref ( ) ,
188
+ group,
189
+ locations,
190
+ workspace,
191
+ lower_bound,
192
+ None ,
131
193
)
132
194
. map ( move |requirement| match requirement {
133
195
Ok ( requirement) => Ok ( requirement. into_inner ( ) ) ,
0 commit comments