@@ -148,8 +148,14 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
148
148
f .write ("" .join (lines ))
149
149
150
150
151
- class CrossPythonMigrator (CrossCompilationMigratorBase ):
151
+ class CrossPythonMigrator (MiniMigrator ):
152
+ allowed_schema_versions = {0 , 1 }
153
+ post_migration = True
154
+
152
155
def filter (self , attrs : "AttrsTypedDict" , not_bad_str_start : str = "" ) -> bool :
156
+ if super ().filter (attrs , not_bad_str_start ):
157
+ return True
158
+
153
159
host_reqs = attrs .get ("requirements" , {}).get ("host" , set ())
154
160
build_reqs = attrs .get ("requirements" , {}).get ("build" , set ())
155
161
return (
@@ -161,7 +167,8 @@ def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool:
161
167
def migrate (self , recipe_dir : str , attrs : "AttrsTypedDict" , ** kwargs : Any ) -> None :
162
168
host_reqs = attrs .get ("requirements" , {}).get ("host" , set ())
163
169
with pushd (recipe_dir ):
164
- with open ("meta.yaml" ) as f :
170
+ recipe_file = next (filter (os .path .exists , ("recipe.yaml" , "meta.yaml" )))
171
+ with open (recipe_file ) as f :
165
172
lines = f .readlines ()
166
173
in_reqs = False
167
174
for i , line in enumerate (lines ):
@@ -189,24 +196,37 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
189
196
for pkg in reversed (
190
197
[
191
198
"python" ,
192
- "cross-python_{{ target_platform }}" ,
199
+ (
200
+ "cross-python_${{ host_platform }}"
201
+ if recipe_file == "recipe.yaml"
202
+ else "cross-python_{{ target_platform }}"
203
+ ),
193
204
"cython" ,
194
205
"numpy" ,
195
206
"cffi" ,
196
207
"pybind11" ,
197
208
],
198
209
):
199
210
if pkg in host_reqs or pkg .startswith ("cross-python" ):
200
- new_line = (
201
- " " * spaces
202
- + "- "
203
- + pkg .ljust (37 )
204
- + " # [build_platform != target_platform]\n "
205
- )
206
- lines .insert (i + 1 , new_line )
211
+ if recipe_file == "recipe.yaml" :
212
+ new_line = (
213
+ " " * spaces
214
+ + "- if: build_platform != host_platform\n "
215
+ )
216
+ lines .insert (i + 1 , new_line )
217
+ new_line = " " * spaces + f" then: { pkg } \n "
218
+ lines .insert (i + 2 , new_line )
219
+ else :
220
+ new_line = (
221
+ " " * spaces
222
+ + "- "
223
+ + pkg .ljust (37 )
224
+ + " # [build_platform != target_platform]\n "
225
+ )
226
+ lines .insert (i + 1 , new_line )
207
227
break
208
228
209
- with open ("meta.yaml" , "w" ) as f :
229
+ with open (recipe_file , "w" ) as f :
210
230
f .write ("" .join (lines ))
211
231
212
232
@@ -325,20 +345,24 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
325
345
"""
326
346
327
347
328
- class CrossRBaseMigrator (CrossCompilationMigratorBase ):
348
+ class CrossRBaseMigrator (MiniMigrator ):
349
+ allowed_schema_versions = {0 , 1 }
350
+ post_migration = True
351
+
329
352
def filter (self , attrs : "AttrsTypedDict" , not_bad_str_start : str = "" ) -> bool :
353
+ if super ().filter (attrs , not_bad_str_start ):
354
+ return True
355
+
330
356
host_reqs = attrs .get ("requirements" , {}).get ("host" , set ())
331
- skip_schema = skip_migrator_due_to_schema (attrs , self .allowed_schema_versions )
332
- if (
333
- "r-base" in host_reqs or attrs .get ("name" , "" ).startswith ("r-" )
334
- ) and not skip_schema :
357
+ if "r-base" in host_reqs or attrs .get ("name" , "" ).startswith ("r-" ):
335
358
return False
336
359
else :
337
360
return True
338
361
339
362
def migrate (self , recipe_dir : str , attrs : "AttrsTypedDict" , ** kwargs : Any ) -> None :
340
363
with pushd (recipe_dir ):
341
- with open ("meta.yaml" ) as fp :
364
+ recipe_file = next (filter (os .path .exists , ("recipe.yaml" , "meta.yaml" )))
365
+ with open (recipe_file ) as fp :
342
366
meta_yaml = fp .readlines ()
343
367
344
368
new_lines = []
@@ -347,10 +371,20 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
347
371
for line in meta_yaml :
348
372
if previous_was_build :
349
373
nspaces = len (line ) - len (line .lstrip ())
350
- new_lines .append (
351
- " " * nspaces
352
- + "- cross-r-base {{ r_base }} # [build_platform != target_platform]\n " ,
353
- )
374
+ if recipe_file == "recipe.yaml" :
375
+ new_lines .extend (
376
+ [
377
+ " " * nspaces
378
+ + "- if: build_platform != host_platform\n " ,
379
+ " " * nspaces + " then:\n " ,
380
+ " " * nspaces + " - cross-r-base ${{ r_base }}\n " ,
381
+ ]
382
+ )
383
+ else :
384
+ new_lines .append (
385
+ " " * nspaces
386
+ + "- cross-r-base {{ r_base }} # [build_platform != target_platform]\n " ,
387
+ )
354
388
# Add host R requirements to build
355
389
host_reqs = attrs .get ("requirements" , {}).get ("host" , set ())
356
390
r_host_reqs = [
@@ -359,15 +393,18 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
359
393
if req .startswith ("r-" ) and req != "r-base"
360
394
]
361
395
for r_req in r_host_reqs :
362
- # Ensure nice formatting
363
- post_nspaces = max (0 , 25 - len (r_req ))
364
- new_lines .append (
365
- " " * nspaces
366
- + "- "
367
- + r_req
368
- + " " * post_nspaces
369
- + " # [build_platform != target_platform]\n " ,
370
- )
396
+ if recipe_file == "recipe.yaml" :
397
+ new_lines .append (" " * nspaces + f" - { r_req } \n " )
398
+ else :
399
+ # Ensure nice formatting
400
+ post_nspaces = max (0 , 25 - len (r_req ))
401
+ new_lines .append (
402
+ " " * nspaces
403
+ + "- "
404
+ + r_req
405
+ + " " * post_nspaces
406
+ + " # [build_platform != target_platform]\n " ,
407
+ )
371
408
in_req = False
372
409
previous_was_build = False
373
410
if "requirements:" in line :
@@ -376,7 +413,7 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
376
413
previous_was_build = True
377
414
new_lines .append (line )
378
415
379
- with open ("meta.yaml" , "w" ) as f :
416
+ with open (recipe_file , "w" ) as f :
380
417
f .write ("" .join (new_lines ))
381
418
382
419
if os .path .exists ("build.sh" ):
0 commit comments