1
+ from itertools import chain
2
+ import json
1
3
import conda .base .context
2
4
import conda .core .index
3
5
import conda .resolve
@@ -44,17 +46,32 @@ def build_all(recipes_dir, arch):
44
46
script_dir = os .path .dirname (os .path .realpath (__file__ ))
45
47
variant_config_file = os .path .join (script_dir , "{}.yaml" .format (get_config_name (arch )))
46
48
49
+ has_meta_yaml = False
50
+ has_recipe_yaml = False
51
+
47
52
found_cuda = False
48
53
found_centos7 = False
49
54
for folder in folders :
50
55
meta_yaml = os .path .join (recipes_dir , folder , "meta.yaml" )
51
56
if os .path .exists (meta_yaml ):
57
+ has_meta_yaml = True
52
58
with (open (meta_yaml , "r" , encoding = "utf-8" )) as f :
53
59
text = '' .join (f .readlines ())
54
60
if 'cuda' in text :
55
61
found_cuda = True
56
62
if 'sysroot_linux-64' in text :
57
63
found_centos7 = True
64
+
65
+ recipe_yaml = os .path .join (recipes_dir , folder , "recipe.yaml" )
66
+ if os .path .exists (recipe_yaml ):
67
+ has_recipe_yaml = True
68
+ with (open (recipe_yaml , "r" , encoding = "utf-8" )) as f :
69
+ text = '' .join (f .readlines ())
70
+ if 'cuda' in text :
71
+ found_cuda = True
72
+ if 'sysroot_linux-64' in text :
73
+ found_centos7 = True
74
+
58
75
cbc = os .path .join (recipes_dir , folder , "conda_build_config.yaml" )
59
76
if os .path .exists (cbc ):
60
77
with open (cbc , "r" ) as f :
@@ -72,6 +89,11 @@ def build_all(recipes_dir, arch):
72
89
print (f"Found c_stdlib_version for linux: { version = } " )
73
90
found_centos7 |= version == (2 , 17 )
74
91
92
+ if has_meta_yaml and has_recipe_yaml :
93
+ raise ValueError ('Mixing meta.yaml and recipe.yaml recipes is not supported' )
94
+ if not has_meta_yaml and not has_recipe_yaml :
95
+ raise ValueError ('Neither a meta.yaml or a recipe.yaml recipes was found' )
96
+
75
97
if found_cuda :
76
98
print ('##vso[task.setvariable variable=NEED_CUDA;isOutput=true]1' )
77
99
if found_centos7 :
@@ -147,8 +169,13 @@ def build_all(recipes_dir, arch):
147
169
148
170
if 'conda-forge' not in channel_urls :
149
171
raise ValueError ('conda-forge needs to be part of channel_sources' )
150
- print ("Building {} with {}" .format (',' .join (folders ), ',' .join (channel_urls )))
151
- build_folders (recipes_dir , folders , arch , channel_urls )
172
+
173
+ if has_meta_yaml :
174
+ print ("Building {} with {} using conda-build" .format (',' .join (folders ), ',' .join (channel_urls )))
175
+ build_folders (recipes_dir , folders , arch , channel_urls )
176
+ elif has_recipe_yaml :
177
+ print ("Building {} with {} using rattler-build" .format (',' .join (folders ), ',' .join (channel_urls )))
178
+ build_folders_rattler_build (recipes_dir , platform , arch , channel_urls )
152
179
153
180
154
181
def get_config (arch , channel_urls ):
@@ -207,9 +234,26 @@ def build_folders(recipes_dir, folders, arch, channel_urls):
207
234
conda_build .api .build ([recipe ], config = get_config (arch , channel_urls ))
208
235
209
236
237
+ def build_folders_rattler_build (recipes_dir : str , platform , arch , channel_urls : list [str ]):
238
+ # Define the arguments for rattler-build
239
+ args = [
240
+ "rattler-build" ,
241
+ "build" ,
242
+ "--recipe-dir" , recipes_dir ,
243
+ "--target-platform" , f"{ platform } -{ arch } " ,
244
+ ]
245
+ for channel_url in channel_urls :
246
+ # Local is automatically added by rattler-build so we just remove it.
247
+ if channel_url != "local" :
248
+ args .extend (["-c" , channel_url ])
249
+
250
+ # Execute rattler-build.
251
+ subprocess .run (args , check = True )
252
+
253
+
210
254
def check_recipes_in_correct_dir (root_dir , correct_dir ):
211
255
from pathlib import Path
212
- for path in Path (root_dir ).rglob ('meta.yaml' ):
256
+ for path in chain ( Path (root_dir ).rglob ('meta.yaml' ), Path ( root_dir ). rglob ( 'recipe.yaml' ) ):
213
257
path = path .absolute ().relative_to (root_dir )
214
258
if path .parts [0 ] == 'build_artifacts' :
215
259
# ignore pkg_cache in build_artifacts
0 commit comments