@@ -27,7 +27,7 @@ class Factory(object):
27
27
"""
28
28
29
29
def create_poetry (
30
- self , cwd : Optional [Path ] = None , with_dev : bool = True
30
+ self , cwd : Optional [Path ] = None , with_groups : bool = True
31
31
) -> "Poetry" :
32
32
from .poetry import Poetry
33
33
from .pyproject .toml import PyProjectTOML
@@ -49,7 +49,7 @@ def create_poetry(
49
49
version = local_config ["version" ]
50
50
package = self .get_package (name , version )
51
51
package = self .configure_package (
52
- package , local_config , poetry_file .parent , with_dev = with_dev
52
+ package , local_config , poetry_file .parent , with_groups = with_groups
53
53
)
54
54
55
55
return Poetry (poetry_file , local_config , package )
@@ -66,9 +66,10 @@ def configure_package(
66
66
package : "ProjectPackage" ,
67
67
config : Dict [str , Any ],
68
68
root : Path ,
69
- with_dev : bool = True ,
69
+ with_groups : bool = True ,
70
70
) -> "ProjectPackage" :
71
71
from .packages .dependency import Dependency
72
+ from .packages .dependency_group import DependencyGroup
72
73
from .spdx .helpers import license_by_id
73
74
74
75
package .root_dir = root
@@ -99,46 +100,82 @@ def configure_package(
99
100
package .platform = config ["platform" ]
100
101
101
102
if "dependencies" in config :
103
+ group = DependencyGroup ("default" )
102
104
for name , constraint in config ["dependencies" ].items ():
103
105
if name .lower () == "python" :
104
106
package .python_versions = constraint
105
107
continue
106
108
107
109
if isinstance (constraint , list ):
108
110
for _constraint in constraint :
109
- package .add_dependency (
111
+ group .add_dependency (
110
112
cls .create_dependency (
111
113
name , _constraint , root_dir = package .root_dir
112
114
)
113
115
)
114
116
115
117
continue
116
118
117
- package .add_dependency (
119
+ group .add_dependency (
118
120
cls .create_dependency (name , constraint , root_dir = package .root_dir )
119
121
)
120
122
121
- if with_dev and "dev-dependencies" in config :
123
+ package .add_dependency_group (group )
124
+
125
+ if with_groups and "group" in config :
126
+ for group_name , group_config in config ["group" ].items ():
127
+ group = DependencyGroup (
128
+ group_name , optional = group_config .get ("optional" , False )
129
+ )
130
+ for name , constraint in group_config ["dependencies" ].items ():
131
+ if isinstance (constraint , list ):
132
+ for _constraint in constraint :
133
+ group .add_dependency (
134
+ cls .create_dependency (
135
+ name ,
136
+ _constraint ,
137
+ groups = [group_name ],
138
+ root_dir = package .root_dir ,
139
+ )
140
+ )
141
+
142
+ continue
143
+
144
+ group .add_dependency (
145
+ cls .create_dependency (
146
+ name ,
147
+ constraint ,
148
+ groups = [group_name ],
149
+ root_dir = package .root_dir ,
150
+ )
151
+ )
152
+
153
+ package .add_dependency_group (group )
154
+
155
+ if with_groups and "dev-dependencies" in config :
156
+ group = DependencyGroup ("dev" )
122
157
for name , constraint in config ["dev-dependencies" ].items ():
123
158
if isinstance (constraint , list ):
124
159
for _constraint in constraint :
125
- package .add_dependency (
160
+ group .add_dependency (
126
161
cls .create_dependency (
127
162
name ,
128
163
_constraint ,
129
- category = "dev" ,
164
+ groups = [ "dev" ] ,
130
165
root_dir = package .root_dir ,
131
166
)
132
167
)
133
168
134
169
continue
135
170
136
- package .add_dependency (
171
+ group .add_dependency (
137
172
cls .create_dependency (
138
- name , constraint , category = "dev" , root_dir = package .root_dir
173
+ name , constraint , groups = [ "dev" ] , root_dir = package .root_dir
139
174
)
140
175
)
141
176
177
+ package .add_dependency_group (group )
178
+
142
179
extras = config .get ("extras" , {})
143
180
for extra_name , requirements in extras .items ():
144
181
package .extras [extra_name ] = []
@@ -191,7 +228,7 @@ def create_dependency(
191
228
cls ,
192
229
name : str ,
193
230
constraint : Union [str , Dict [str , Any ]],
194
- category : str = "main" ,
231
+ groups : Optional [ List [ str ]] = None ,
195
232
root_dir : Optional [Path ] = None ,
196
233
) -> "DependencyTypes" :
197
234
from .packages .constraints import parse_constraint as parse_generic_constraint
@@ -204,6 +241,9 @@ def create_dependency(
204
241
from .version .markers import AnyMarker
205
242
from .version .markers import parse_marker
206
243
244
+ if groups is None :
245
+ groups = ["default" ]
246
+
207
247
if constraint is None :
208
248
constraint = "*"
209
249
@@ -234,7 +274,7 @@ def create_dependency(
234
274
branch = constraint .get ("branch" , None ),
235
275
tag = constraint .get ("tag" , None ),
236
276
rev = constraint .get ("rev" , None ),
237
- category = category ,
277
+ groups = groups ,
238
278
optional = optional ,
239
279
develop = constraint .get ("develop" , False ),
240
280
extras = constraint .get ("extras" , []),
@@ -245,7 +285,7 @@ def create_dependency(
245
285
dependency = FileDependency (
246
286
name ,
247
287
file_path ,
248
- category = category ,
288
+ groups = groups ,
249
289
base = root_dir ,
250
290
extras = constraint .get ("extras" , []),
251
291
)
@@ -261,7 +301,7 @@ def create_dependency(
261
301
dependency = FileDependency (
262
302
name ,
263
303
path ,
264
- category = category ,
304
+ groups = groups ,
265
305
optional = optional ,
266
306
base = root_dir ,
267
307
extras = constraint .get ("extras" , []),
@@ -270,7 +310,7 @@ def create_dependency(
270
310
dependency = DirectoryDependency (
271
311
name ,
272
312
path ,
273
- category = category ,
313
+ groups = groups ,
274
314
optional = optional ,
275
315
base = root_dir ,
276
316
develop = constraint .get ("develop" , False ),
@@ -280,7 +320,7 @@ def create_dependency(
280
320
dependency = URLDependency (
281
321
name ,
282
322
constraint ["url" ],
283
- category = category ,
323
+ groups = groups ,
284
324
optional = optional ,
285
325
extras = constraint .get ("extras" , []),
286
326
)
@@ -291,7 +331,7 @@ def create_dependency(
291
331
name ,
292
332
version ,
293
333
optional = optional ,
294
- category = category ,
334
+ groups = groups ,
295
335
allows_prereleases = allows_prereleases ,
296
336
extras = constraint .get ("extras" , []),
297
337
)
@@ -324,7 +364,7 @@ def create_dependency(
324
364
325
365
dependency .source_name = constraint .get ("source" )
326
366
else :
327
- dependency = Dependency (name , constraint , category = category )
367
+ dependency = Dependency (name , constraint , groups = groups )
328
368
329
369
return dependency
330
370
0 commit comments