Skip to content

Commit 81f946a

Browse files
authored
Merge pull request #3836 from mgorny/cross-rbase-v1
Support v1 recipes in `CrossRBaseMigrator`
2 parents 91cc9b6 + 342e595 commit 81f946a

File tree

4 files changed

+193
-26
lines changed

4 files changed

+193
-26
lines changed

conda_forge_tick/migrators/cross_compile.py

+37-20
Original file line numberDiff line numberDiff line change
@@ -325,20 +325,24 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
325325
"""
326326

327327

328-
class CrossRBaseMigrator(CrossCompilationMigratorBase):
328+
class CrossRBaseMigrator(MiniMigrator):
329+
allowed_schema_versions = {0, 1}
330+
post_migration = True
331+
329332
def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool:
333+
if super().filter(attrs, not_bad_str_start):
334+
return True
335+
330336
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:
337+
if "r-base" in host_reqs or attrs.get("name", "").startswith("r-"):
335338
return False
336339
else:
337340
return True
338341

339342
def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> None:
340343
with pushd(recipe_dir):
341-
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:
342346
meta_yaml = fp.readlines()
343347

344348
new_lines = []
@@ -347,10 +351,20 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
347351
for line in meta_yaml:
348352
if previous_was_build:
349353
nspaces = len(line) - len(line.lstrip())
350-
new_lines.append(
351-
" " * nspaces
352-
+ "- cross-r-base {{ r_base }} # [build_platform != target_platform]\n",
353-
)
354+
if recipe_file == "recipe.yaml":
355+
new_lines.extend(
356+
[
357+
" " * nspaces
358+
+ "- if: build_platform != host_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+
)
354368
# Add host R requirements to build
355369
host_reqs = attrs.get("requirements", {}).get("host", set())
356370
r_host_reqs = [
@@ -359,15 +373,18 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
359373
if req.startswith("r-") and req != "r-base"
360374
]
361375
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-
)
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+
)
371388
in_req = False
372389
previous_was_build = False
373390
if "requirements:" in line:
@@ -376,7 +393,7 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
376393
previous_was_build = True
377394
new_lines.append(line)
378395

379-
with open("meta.yaml", "w") as f:
396+
with open(recipe_file, "w") as f:
380397
f.write("".join(new_lines))
381398

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

tests/test_cross_compile.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,15 @@ def test_cmake(tmp_path):
149149
assert lines == expected
150150

151151

152+
@pytest.mark.parametrize("recipe_version", [0, 1])
152153
@flaky
153-
def test_cross_rbase(tmp_path):
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

173+
@pytest.mark.parametrize("recipe_version", [0, 1])
169174
@flaky
170-
def test_cross_rbase_build_sh(tmp_path):
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",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
schema_version: 1
2+
3+
context:
4+
version: 2.0.0
5+
posix: ${{'m2-' if win else ''}}
6+
native: ${{'m2w64-' if win else ''}}
7+
8+
package:
9+
name: r-magrittr
10+
version: ${{ version|replace("-", "_") }}
11+
12+
source:
13+
url:
14+
- https://cran.r-project.org/src/contrib/magrittr_${{ version }}.tar.gz
15+
- https://cran.r-project.org/src/contrib/Archive/magrittr/magrittr_${{ version }}.tar.gz
16+
sha256: 05c45943ada9443134caa0ab24db4a962b629f00b755ccf039a2a2a7b2c92ae8
17+
18+
build:
19+
number: 1
20+
dynamic_linking:
21+
rpaths:
22+
- lib/R/lib/
23+
- lib/
24+
25+
requirements:
26+
build:
27+
- if: not win
28+
then: ${{ compiler('c') }}
29+
- if: win
30+
then: ${{ compiler('m2w64_c') }}
31+
- if: win
32+
then: ${{ posix }}filesystem
33+
- ${{ posix }}make
34+
- if: win
35+
then: ${{ posix }}sed
36+
- if: win
37+
then: ${{ posix }}coreutils
38+
- if: win
39+
then: ${{ posix }}zip
40+
host:
41+
- r-base
42+
- r-rlang
43+
run:
44+
- r-base
45+
- r-rlang
46+
- if: win
47+
then: ${{ native }}gcc-libs
48+
49+
tests:
50+
- script:
51+
- if: not win
52+
then: "$R -e \"library('magrittr')\""
53+
- if: win
54+
then: "\"%R%\" -e \"library('magrittr')\""
55+
56+
about:
57+
license: MIT
58+
summary: |
59+
Provides a mechanism for chaining commands with a new forward-pipe operator, %>%. This operator will forward a value, or the result of an expression, into the next function call/expression. There is flexible support for the type of right-hand side expressions. For more information, see package vignette. To quote
60+
Rene Magritte, "Ceci n'est pas un pipe."
61+
license_file:
62+
- lib/R/share/licenses/MIT
63+
- LICENSE
64+
homepage: https://magrittr.tidyverse.org
65+
66+
extra:
67+
recipe-maintainers:
68+
- conda-forge/r
69+
- ocefpaf
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
schema_version: 1
2+
3+
context:
4+
version: "2.0.1"
5+
posix: ${{'m2-' if win else ''}}
6+
native: ${{'m2w64-' if win else ''}}
7+
8+
package:
9+
name: r-magrittr
10+
version: ${{ version|replace("-", "_") }}
11+
12+
source:
13+
url:
14+
- https://cran.r-project.org/src/contrib/magrittr_${{ version }}.tar.gz
15+
- https://cran.r-project.org/src/contrib/Archive/magrittr/magrittr_${{ version }}.tar.gz
16+
sha256: 75c265d51cc2b34beb27040edb09823c7b954d3990a7a931e40690b75d4aad5f
17+
18+
build:
19+
number: 0
20+
dynamic_linking:
21+
rpaths:
22+
- lib/R/lib/
23+
- lib/
24+
25+
requirements:
26+
build:
27+
- if: build_platform != host_platform
28+
then:
29+
- cross-r-base ${{ r_base }}
30+
- r-rlang
31+
- if: not win
32+
then: ${{ compiler('c') }}
33+
- if: win
34+
then: ${{ compiler('m2w64_c') }}
35+
- if: win
36+
then: ${{ posix }}filesystem
37+
- ${{ posix }}make
38+
- if: win
39+
then: ${{ posix }}sed
40+
- if: win
41+
then: ${{ posix }}coreutils
42+
- if: win
43+
then: ${{ posix }}zip
44+
host:
45+
- r-base
46+
- r-rlang
47+
run:
48+
- r-base
49+
- r-rlang
50+
- if: win
51+
then: ${{ native }}gcc-libs
52+
53+
tests:
54+
- script:
55+
- if: not win
56+
then: "$R -e \"library('magrittr')\""
57+
- if: win
58+
then: "\"%R%\" -e \"library('magrittr')\""
59+
60+
about:
61+
license: MIT
62+
summary: |
63+
Provides a mechanism for chaining commands with a new forward-pipe operator, %>%. This operator will forward a value, or the result of an expression, into the next function call/expression. There is flexible support for the type of right-hand side expressions. For more information, see package vignette. To quote
64+
Rene Magritte, "Ceci n'est pas un pipe."
65+
license_file:
66+
- lib/R/share/licenses/MIT
67+
- LICENSE
68+
homepage: https://magrittr.tidyverse.org
69+
70+
extra:
71+
recipe-maintainers:
72+
- conda-forge/r
73+
- ocefpaf

0 commit comments

Comments
 (0)