1
+ import json
1
2
import conda .base .context
2
3
import conda .core .index
3
4
import conda .resolve
@@ -44,17 +45,32 @@ def build_all(recipes_dir, arch):
44
45
script_dir = os .path .dirname (os .path .realpath (__file__ ))
45
46
variant_config_file = os .path .join (script_dir , "{}.yaml" .format (get_config_name (arch )))
46
47
48
+ has_meta_yaml = False
49
+ has_recipe_yaml = False
50
+
47
51
found_cuda = False
48
52
found_centos7 = False
49
53
for folder in folders :
50
54
meta_yaml = os .path .join (recipes_dir , folder , "meta.yaml" )
51
55
if os .path .exists (meta_yaml ):
56
+ has_meta_yaml = True
52
57
with (open (meta_yaml , "r" , encoding = "utf-8" )) as f :
53
58
text = '' .join (f .readlines ())
54
59
if 'cuda' in text :
55
60
found_cuda = True
56
61
if 'sysroot_linux-64' in text :
57
62
found_centos7 = True
63
+
64
+ recipe_yaml = os .path .join (recipes_dir , folder , "recipe.yaml" )
65
+ if os .path .exists (recipe_yaml ):
66
+ has_recipe_yaml = True
67
+ with (open (recipe_yaml , "r" , encoding = "utf-8" )) as f :
68
+ text = '' .join (f .readlines ())
69
+ if 'cuda' in text :
70
+ found_cuda = True
71
+ if 'sysroot_linux-64' in text :
72
+ found_centos7 = True
73
+
58
74
cbc = os .path .join (recipes_dir , folder , "conda_build_config.yaml" )
59
75
if os .path .exists (cbc ):
60
76
with open (cbc , "r" ) as f :
@@ -72,6 +88,11 @@ def build_all(recipes_dir, arch):
72
88
print (f"Found c_stdlib_version for linux: { version = } " )
73
89
found_centos7 |= version == (2 , 17 )
74
90
91
+ if has_meta_yaml and has_recipe_yaml :
92
+ raise ValueError ('Mixing meta.yaml and recipe.yaml recipes is not supported' )
93
+ if not has_meta_yaml and not has_recipe_yaml :
94
+ raise ValueError ('Neither a meta.yaml or a recipe.yaml recipes was found' )
95
+
75
96
if found_cuda :
76
97
print ('##vso[task.setvariable variable=NEED_CUDA;isOutput=true]1' )
77
98
if found_centos7 :
@@ -147,8 +168,13 @@ def build_all(recipes_dir, arch):
147
168
148
169
if 'conda-forge' not in channel_urls :
149
170
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 )
171
+
172
+ if has_meta_yaml :
173
+ print ("Building {} with {} using conda-build" .format (',' .join (folders ), ',' .join (channel_urls )))
174
+ build_folders (recipes_dir , folders , arch , channel_urls )
175
+ elif has_recipe_yaml :
176
+ print ("Building {} with {} using rattler-build" .format (',' .join (folders ), ',' .join (channel_urls )))
177
+ build_folders_rattler_build (recipes_dir , platform , arch , channel_urls )
152
178
153
179
154
180
def get_config (arch , channel_urls ):
@@ -207,6 +233,24 @@ def build_folders(recipes_dir, folders, arch, channel_urls):
207
233
conda_build .api .build ([recipe ], config = get_config (arch , channel_urls ))
208
234
209
235
236
+ def build_folders_rattler_build (recipes_dir : str , platform , arch , channel_urls : list [str ]):
237
+ # Local is automatically added by rattler-build so we just remove it.
238
+ channel_urls .remove ("local" )
239
+
240
+ # Define the arguments for rattler-build
241
+ args = [
242
+ "rattler-build" ,
243
+ "build" ,
244
+ "--recipe-dir" , recipes_dir ,
245
+ "--target-platform" , f"{ platform } -{ arch } " ,
246
+ ]
247
+ for channel_url in channel_urls :
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
256
for path in Path (root_dir ).rglob ('meta.yaml' ):
0 commit comments