26
26
EXAMPLE_RECIPE_FOLDERS = ["example" , "example-v1" ]
27
27
LOCAL_CHANNELS = os .environ .get ("CONDA_BLD_PATH" , "local" ).split ("," )
28
28
29
+
29
30
def get_host_platform ():
30
31
from sys import platform
32
+
31
33
if platform == "linux" or platform == "linux2" :
32
34
return "linux"
33
35
elif platform == "darwin" :
@@ -54,7 +56,9 @@ def build_all(recipes_dir, arch):
54
56
55
57
platform = get_host_platform ()
56
58
script_dir = os .path .dirname (os .path .realpath (__file__ ))
57
- variant_config_file = os .path .join (script_dir , "{}.yaml" .format (get_config_name (arch )))
59
+ variant_config_file = os .path .join (
60
+ script_dir , "{}.yaml" .format (get_config_name (arch ))
61
+ )
58
62
59
63
has_meta_yaml = False
60
64
has_recipe_yaml = False
@@ -65,11 +69,11 @@ def build_all(recipes_dir, arch):
65
69
meta_yaml = os .path .join (recipes_dir , folder , "meta.yaml" )
66
70
if os .path .exists (meta_yaml ):
67
71
has_meta_yaml = True
68
- with ( open (meta_yaml , "r" , encoding = "utf-8" ) ) as f :
69
- text = '' .join (f .readlines ())
70
- if ' cuda' in text :
72
+ with open (meta_yaml , "r" , encoding = "utf-8" ) as f :
73
+ text = "" .join (f .readlines ())
74
+ if " cuda" in text :
71
75
found_cuda = True
72
- if ' sysroot_linux-64' in text :
76
+ if " sysroot_linux-64" in text :
73
77
found_centos7 = True
74
78
75
79
recipe_yaml = os .path .join (recipes_dir , folder , "recipe.yaml" )
@@ -86,16 +90,18 @@ def build_all(recipes_dir, arch):
86
90
if os .path .exists (cbc ):
87
91
with open (cbc , "r" ) as f :
88
92
lines = f .readlines ()
89
- pat = re .compile (r"^([^\#]*?)\s+\#\s\[.*(not\s(linux|unix)|(?<!not\s)(osx|win)).*\]\s*$" )
93
+ pat = re .compile (
94
+ r"^([^\#]*?)\s+\#\s\[.*(not\s(linux|unix)|(?<!not\s)(osx|win)).*\]\s*$"
95
+ )
90
96
# remove lines with selectors that don't apply to linux, i.e. if they contain
91
97
# "not linux", "not unix", "osx" or "win"; this also removes trailing newlines
92
98
lines = [pat .sub ("" , x ) for x in lines ]
93
99
text = "\n " .join (lines )
94
- if platform == ' linux' and (' c_stdlib_version' in text ):
100
+ if platform == " linux" and (" c_stdlib_version" in text ):
95
101
config = load (text , Loader = BaseLoader )
96
- if ' c_stdlib_version' in config :
97
- for version in config [' c_stdlib_version' ]:
98
- version = tuple ([int (x ) for x in version .split ('.' )])
102
+ if " c_stdlib_version" in config :
103
+ for version in config [" c_stdlib_version" ]:
104
+ version = tuple ([int (x ) for x in version .split ("." )])
99
105
print (f"Found c_stdlib_version for linux: { version = } " )
100
106
found_centos7 |= version == (2 , 17 )
101
107
@@ -105,7 +111,7 @@ def build_all(recipes_dir, arch):
105
111
raise ValueError ("Neither a meta.yaml or a recipe.yaml recipes was found" )
106
112
107
113
if found_cuda :
108
- print (' ##vso[task.setvariable variable=NEED_CUDA;isOutput=true]1' )
114
+ print (" ##vso[task.setvariable variable=NEED_CUDA;isOutput=true]1" )
109
115
if found_centos7 :
110
116
os .environ ["DEFAULT_LINUX_VERSION" ] = "cos7"
111
117
print ("Overriding DEFAULT_LINUX_VERSION to be cos7" )
@@ -118,70 +124,78 @@ def build_all(recipes_dir, arch):
118
124
if os .path .exists (cbc ):
119
125
with open (cbc , "r" ) as f :
120
126
lines = f .readlines ()
121
- pat = re .compile (r"^([^\#]*?)\s+\#\s\[.*(not\s(osx|unix)|(?<!not\s)(linux|win)).*\]\s*$" )
127
+ pat = re .compile (
128
+ r"^([^\#]*?)\s+\#\s\[.*(not\s(osx|unix)|(?<!not\s)(linux|win)).*\]\s*$"
129
+ )
122
130
# remove lines with selectors that don't apply to osx, i.e. if they contain
123
131
# "not osx", "not unix", "linux" or "win"; this also removes trailing newlines
124
132
lines = [pat .sub ("" , x ) for x in lines ]
125
133
text = "\n " .join (lines )
126
- if platform == 'osx' and (
127
- 'MACOSX_DEPLOYMENT_TARGET' in text or
128
- 'MACOSX_SDK_VERSION' in text or
129
- 'c_stdlib_version' in text ):
134
+ if platform == "osx" and (
135
+ "MACOSX_DEPLOYMENT_TARGET" in text
136
+ or "MACOSX_SDK_VERSION" in text
137
+ or "c_stdlib_version" in text
138
+ ):
130
139
config = load (text , Loader = BaseLoader )
131
140
132
- if ' MACOSX_DEPLOYMENT_TARGET' in config :
133
- for version in config [' MACOSX_DEPLOYMENT_TARGET' ]:
134
- version = tuple ([int (x ) for x in version .split ('.' )])
141
+ if " MACOSX_DEPLOYMENT_TARGET" in config :
142
+ for version in config [" MACOSX_DEPLOYMENT_TARGET" ]:
143
+ version = tuple ([int (x ) for x in version .split ("." )])
135
144
deployment_version = max (deployment_version , version )
136
- if ' c_stdlib_version' in config :
137
- for version in config [' c_stdlib_version' ]:
138
- version = tuple ([int (x ) for x in version .split ('.' )])
145
+ if " c_stdlib_version" in config :
146
+ for version in config [" c_stdlib_version" ]:
147
+ version = tuple ([int (x ) for x in version .split ("." )])
139
148
print (f"Found c_stdlib_version for osx: { version = } " )
140
149
deployment_version = max (deployment_version , version )
141
- if ' MACOSX_SDK_VERSION' in config :
142
- for version in config [' MACOSX_SDK_VERSION' ]:
143
- version = tuple ([int (x ) for x in version .split ('.' )])
150
+ if " MACOSX_SDK_VERSION" in config :
151
+ for version in config [" MACOSX_SDK_VERSION" ]:
152
+ version = tuple ([int (x ) for x in version .split ("." )])
144
153
sdk_version = max (sdk_version , deployment_version , version )
145
154
146
- if ' channel_sources' not in text :
147
- new_channel_urls = [* LOCAL_CHANNELS , ' conda-forge' ]
155
+ if " channel_sources" not in text :
156
+ new_channel_urls = [* LOCAL_CHANNELS , " conda-forge" ]
148
157
else :
149
158
config = load (text , Loader = BaseLoader )
150
- new_channel_urls = [* LOCAL_CHANNELS , * config ['channel_sources' ][0 ].split (',' )]
159
+ new_channel_urls = [
160
+ * LOCAL_CHANNELS ,
161
+ * config ["channel_sources" ][0 ].split ("," ),
162
+ ]
151
163
if channel_urls is None :
152
164
channel_urls = new_channel_urls
153
165
elif channel_urls != new_channel_urls :
154
- raise ValueError (f'Detected different channel_sources in the recipes: { channel_urls } vs. { new_channel_urls } . Consider submitting them in separate PRs' )
166
+ raise ValueError (
167
+ f"Detected different channel_sources in the recipes: { channel_urls } vs. { new_channel_urls } . Consider submitting them in separate PRs"
168
+ )
155
169
156
170
if channel_urls is None :
157
- channel_urls = [* LOCAL_CHANNELS , ' conda-forge' ]
171
+ channel_urls = [* LOCAL_CHANNELS , " conda-forge" ]
158
172
159
- with open (variant_config_file , 'r' ) as f :
160
- variant_text = '' .join (f .readlines ())
173
+ with open (variant_config_file , "r" ) as f :
174
+ variant_text = "" .join (f .readlines ())
161
175
162
176
if deployment_version != (0 , 0 ):
163
- deployment_version = '.' .join ([str (x ) for x in deployment_version ])
177
+ deployment_version = "." .join ([str (x ) for x in deployment_version ])
164
178
print ("Overriding MACOSX_DEPLOYMENT_TARGET to be " , deployment_version )
165
- variant_text += ' \n MACOSX_DEPLOYMENT_TARGET:\n '
179
+ variant_text += " \n MACOSX_DEPLOYMENT_TARGET:\n "
166
180
variant_text += f'- "{ deployment_version } "\n '
167
181
168
182
if sdk_version != (0 , 0 ):
169
- sdk_version = '.' .join ([str (x ) for x in sdk_version ])
183
+ sdk_version = "." .join ([str (x ) for x in sdk_version ])
170
184
print ("Overriding MACOSX_SDK_VERSION to be " , sdk_version )
171
- variant_text += ' \n MACOSX_SDK_VERSION:\n '
185
+ variant_text += " \n MACOSX_SDK_VERSION:\n "
172
186
variant_text += f'- "{ sdk_version } "\n '
173
187
174
- with open (variant_config_file , 'w' ) as f :
188
+ with open (variant_config_file , "w" ) as f :
175
189
f .write (variant_text )
176
190
177
191
if platform == "osx" and (sdk_version != (0 , 0 ) or deployment_version != (0 , 0 )):
178
192
subprocess .run ("run_conda_forge_build_setup" , shell = True , check = True )
179
193
180
- if ' conda-forge' not in channel_urls :
181
- raise ValueError (' conda-forge needs to be part of channel_sources' )
182
-
194
+ if " conda-forge" not in channel_urls :
195
+ raise ValueError (" conda-forge needs to be part of channel_sources" )
196
+
183
197
if has_meta_yaml :
184
- print ("Building {} with {}" .format (',' .join (folders ), ',' .join (channel_urls )))
198
+ print ("Building {} with {}" .format ("," .join (folders ), "," .join (channel_urls )))
185
199
build_folders (recipes_dir , folders , arch , channel_urls )
186
200
elif has_recipe_yaml :
187
201
print (
@@ -193,28 +207,31 @@ def build_all(recipes_dir, arch):
193
207
194
208
195
209
def get_config (arch , channel_urls ):
196
- exclusive_config_files = [os .path .join (conda .base .context .context .root_prefix ,
197
- 'conda_build_config.yaml' )]
210
+ exclusive_config_files = [
211
+ os .path .join (conda .base .context .context .root_prefix , "conda_build_config.yaml" )
212
+ ]
198
213
script_dir = os .path .dirname (os .path .realpath (__file__ ))
199
214
# since variant builds override recipe/conda_build_config.yaml, see
200
215
# https://github.com/conda/conda-build/blob/3.21.8/conda_build/variants.py#L175-L181
201
216
# we need to make sure not to use variant_configs here, otherwise
202
217
# staged-recipes PRs cannot override anything using the recipe-cbc.
203
- exclusive_config_file = os .path .join (script_dir , '{}.yaml' .format (
204
- get_config_name (arch )))
218
+ exclusive_config_file = os .path .join (
219
+ script_dir , "{}.yaml" .format (get_config_name (arch ))
220
+ )
205
221
if os .path .exists (exclusive_config_file ):
206
222
exclusive_config_files .append (exclusive_config_file )
207
223
208
224
config = conda_build .api .Config (
209
- arch = arch , exclusive_config_files = exclusive_config_files ,
210
- channel_urls = channel_urls , error_overlinking = True ,
225
+ arch = arch ,
226
+ exclusive_config_files = exclusive_config_files ,
227
+ channel_urls = channel_urls ,
228
+ error_overlinking = True ,
211
229
)
212
230
return config
213
231
214
232
215
233
def build_folders (recipes_dir , folders , arch , channel_urls ):
216
-
217
- index_path = os .path .join (sys .exec_prefix , 'conda-bld' )
234
+ index_path = os .path .join (sys .exec_prefix , "conda-bld" )
218
235
os .makedirs (index_path , exist_ok = True )
219
236
conda_index .api .update_index (index_path )
220
237
index = conda .core .index .get_index (channel_urls = channel_urls )
@@ -223,26 +240,38 @@ def build_folders(recipes_dir, folders, arch, channel_urls):
223
240
config = get_config (arch , channel_urls )
224
241
platform = get_host_platform ()
225
242
226
- worker = {'platform' : platform , 'arch' : arch ,
227
- 'label' : '{}-{}' .format (platform , arch )}
243
+ worker = {
244
+ "platform" : platform ,
245
+ "arch" : arch ,
246
+ "label" : "{}-{}" .format (platform , arch ),
247
+ }
228
248
229
- G = construct_graph (recipes_dir , worker = worker , run = 'build' ,
230
- conda_resolve = conda_resolve , folders = folders ,
231
- config = config , finalize = False )
249
+ G = construct_graph (
250
+ recipes_dir ,
251
+ worker = worker ,
252
+ run = "build" ,
253
+ conda_resolve = conda_resolve ,
254
+ folders = folders ,
255
+ config = config ,
256
+ finalize = False ,
257
+ )
232
258
order = list (nx .topological_sort (G ))
233
259
order .reverse ()
234
260
235
- print ('Computed that there are {} distributions to build from {} recipes'
236
- .format (len (order ), len (folders )))
261
+ print (
262
+ "Computed that there are {} distributions to build from {} recipes" .format (
263
+ len (order ), len (folders )
264
+ )
265
+ )
237
266
if not order :
238
- print (' Nothing to do' )
267
+ print (" Nothing to do" )
239
268
return
240
269
print ("Resolved dependencies, will be built in the following order:" )
241
- print (' ' + ' \n ' .join (order ))
270
+ print (" " + " \n " .join (order ))
242
271
243
272
d = OrderedDict ()
244
273
for node in order :
245
- d [G .nodes [node ][' meta' ].meta_path ] = 1
274
+ d [G .nodes [node ][" meta" ].meta_path ] = 1
246
275
247
276
for recipe in d .keys ():
248
277
conda_build .api .build ([recipe ], config = get_config (arch , channel_urls ))
@@ -285,7 +314,7 @@ def build_folders_rattler_build(
285
314
# Construct a temporary file where we write the combined variant config. We can then pass that
286
315
# to rattler-build.
287
316
with tempfile .NamedTemporaryFile (delete = False ) as fp :
288
- fp .write (variant_config .encode ("utf-8" ))
317
+ fp .write (variant_config .encode ("utf-8" ))
289
318
atexit .register (os .unlink , fp .name )
290
319
291
320
# Execute rattler-build.
@@ -295,17 +324,21 @@ def build_folders_rattler_build(
295
324
def check_recipes_in_correct_dir (root_dir , correct_dir ):
296
325
for path in Path (root_dir ).glob ("*" ):
297
326
path = Path (path )
298
- if path .is_dir () and path .name .lower () in ('.pixi' , 'build_artifacts' , 'miniforge3' ):
327
+ if path .is_dir () and path .name .lower () in (
328
+ ".pixi" ,
329
+ "build_artifacts" ,
330
+ "miniforge3" ,
331
+ ):
299
332
# ignore pkg_cache in build_artifacts
300
333
continue
301
- for recipe_path in path .rglob (' *.yaml' ):
334
+ for recipe_path in path .rglob (" *.yaml" ):
302
335
if recipe_path .name not in ("meta.yaml" , "recipe.yaml" ):
303
336
continue
304
337
recipe_path = recipe_path .absolute ().relative_to (root_dir )
305
338
if (
306
- ( recipe_path .parts [0 ] != correct_dir and recipe_path . parts [ 0 ] != "broken-recipes" )
307
- or len ( recipe_path .parts ) != 3
308
- ):
339
+ recipe_path .parts [0 ] != correct_dir
340
+ and recipe_path .parts [ 0 ] != "broken-recipes"
341
+ ) or len ( recipe_path . parts ) != 3 :
309
342
raise RuntimeError (
310
343
f"recipe { recipe_path } in wrong directory; "
311
344
f"must be under { correct_dir } /<name>/"
@@ -336,21 +369,22 @@ def read_mambabuild(recipes_dir):
336
369
337
370
def use_mambabuild ():
338
371
from boa .cli .mambabuild import prepare
372
+
339
373
prepare ()
340
374
341
375
342
376
if __name__ == "__main__" :
343
377
parser = argparse .ArgumentParser ()
344
378
parser .add_argument (
345
- ' --arch' ,
346
- default = '64' ,
347
- help = ' target architecture (second component of a subdir; e.g. 64, arm64, ppc64le)'
379
+ " --arch" ,
380
+ default = "64" ,
381
+ help = " target architecture (second component of a subdir; e.g. 64, arm64, ppc64le)" ,
348
382
)
349
383
args = parser .parse_args ()
350
384
root_dir = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
351
385
check_recipes_in_correct_dir (root_dir , "recipes" )
352
386
use_mamba = read_mambabuild (os .path .join (root_dir , "recipes" ))
353
387
if use_mamba :
354
- use_mambabuild ()
355
- subprocess .run ("conda clean --all --yes" , shell = True , check = True )
388
+ use_mambabuild ()
389
+ subprocess .run ("conda clean --all --yes" , shell = True , check = True )
356
390
build_all (os .path .join (root_dir , "recipes" ), args .arch )
0 commit comments