Skip to content

Commit ac02c67

Browse files
committed
Support v1 recipes in CrossRBaseMigrator
Add support for v1 recipes in `CrossRBaseMigrator`. Here the logic made it easy to output a single combined condition: ```yaml - if: build_platform != target_platform then: - cross-r-base ${{ r_base }} - r-rlang ``` Part of bug regro#3642
1 parent d780c62 commit ac02c67

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

conda_forge_tick/migrators/cross_compile.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
326326

327327

328328
class CrossRBaseMigrator(MiniMigrator):
329+
allowed_schema_versions = {0, 1}
329330
post_migration = True
330331

331332
def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool:
@@ -340,7 +341,8 @@ def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool:
340341

341342
def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> None:
342343
with pushd(recipe_dir):
343-
with open("meta.yaml") as fp:
344+
recipe_file = next(filter(os.path.exists, ("recipe.yaml", "meta.yaml")))
345+
with open(recipe_file) as fp:
344346
meta_yaml = fp.readlines()
345347

346348
new_lines = []
@@ -349,10 +351,20 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
349351
for line in meta_yaml:
350352
if previous_was_build:
351353
nspaces = len(line) - len(line.lstrip())
352-
new_lines.append(
353-
" " * nspaces
354-
+ "- cross-r-base {{ r_base }} # [build_platform != target_platform]\n",
355-
)
354+
if recipe_file == "recipe.yaml":
355+
new_lines.extend(
356+
[
357+
" " * nspaces
358+
+ "- if: build_platform != target_platform\n",
359+
" " * nspaces + " then:\n",
360+
" " * nspaces + " - cross-r-base ${{ r_base }}\n",
361+
]
362+
)
363+
else:
364+
new_lines.append(
365+
" " * nspaces
366+
+ "- cross-r-base {{ r_base }} # [build_platform != target_platform]\n",
367+
)
356368
# Add host R requirements to build
357369
host_reqs = attrs.get("requirements", {}).get("host", set())
358370
r_host_reqs = [
@@ -361,15 +373,18 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
361373
if req.startswith("r-") and req != "r-base"
362374
]
363375
for r_req in r_host_reqs:
364-
# Ensure nice formatting
365-
post_nspaces = max(0, 25 - len(r_req))
366-
new_lines.append(
367-
" " * nspaces
368-
+ "- "
369-
+ r_req
370-
+ " " * post_nspaces
371-
+ " # [build_platform != target_platform]\n",
372-
)
376+
if recipe_file == "recipe.yaml":
377+
new_lines.append(" " * nspaces + f" - {r_req}\n")
378+
else:
379+
# Ensure nice formatting
380+
post_nspaces = max(0, 25 - len(r_req))
381+
new_lines.append(
382+
" " * nspaces
383+
+ "- "
384+
+ r_req
385+
+ " " * post_nspaces
386+
+ " # [build_platform != target_platform]\n",
387+
)
373388
in_req = False
374389
previous_was_build = False
375390
if "requirements:" in line:
@@ -378,7 +393,7 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
378393
previous_was_build = True
379394
new_lines.append(line)
380395

381-
with open("meta.yaml", "w") as f:
396+
with open(recipe_file, "w") as f:
382397
f.write("".join(new_lines))
383398

384399
if os.path.exists("build.sh"):

tests/test_cross_compile.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ def test_cmake(tmp_path):
150150

151151

152152
@flaky
153-
def test_cross_rbase(tmp_path):
153+
@pytest.mark.parametrize("recipe_version", [0, 1])
154+
def test_cross_rbase(tmp_path, recipe_version: int):
154155
run_test_migration(
155156
m=version_migrator_rbase,
156-
inp=YAML_PATH.joinpath("rbase_recipe.yaml").read_text(),
157-
output=YAML_PATH.joinpath("rbase_recipe_correct.yaml").read_text(),
157+
inp=YAML_PATHS[recipe_version].joinpath("rbase_recipe.yaml").read_text(),
158+
output=YAML_PATHS[recipe_version]
159+
.joinpath("rbase_recipe_correct.yaml")
160+
.read_text(),
158161
prb="Dependencies have been updated if changed",
159162
kwargs={"new_version": "2.0.1"},
160163
mr_out={
@@ -163,18 +166,22 @@ def test_cross_rbase(tmp_path):
163166
"version": "2.0.1",
164167
},
165168
tmp_path=tmp_path,
169+
recipe_version=recipe_version,
166170
)
167171

168172

169173
@flaky
170-
def test_cross_rbase_build_sh(tmp_path):
174+
@pytest.mark.parametrize("recipe_version", [0, 1])
175+
def test_cross_rbase_build_sh(tmp_path, recipe_version: int):
171176
tmp_path.joinpath("recipe").mkdir()
172177
with open(tmp_path / "recipe/build.sh", "w") as f:
173178
f.write("#!/bin/bash\nR CMD INSTALL --build .")
174179
run_test_migration(
175180
m=version_migrator_rbase,
176-
inp=YAML_PATH.joinpath("rbase_recipe.yaml").read_text(),
177-
output=YAML_PATH.joinpath("rbase_recipe_correct.yaml").read_text(),
181+
inp=YAML_PATHS[recipe_version].joinpath("rbase_recipe.yaml").read_text(),
182+
output=YAML_PATHS[recipe_version]
183+
.joinpath("rbase_recipe_correct.yaml")
184+
.read_text(),
178185
prb="Dependencies have been updated if changed",
179186
kwargs={"new_version": "2.0.1"},
180187
mr_out={
@@ -183,6 +190,7 @@ def test_cross_rbase_build_sh(tmp_path):
183190
"version": "2.0.1",
184191
},
185192
tmp_path=tmp_path,
193+
recipe_version=recipe_version,
186194
)
187195
expected = [
188196
"#!/bin/bash\n",

0 commit comments

Comments
 (0)