Skip to content

Commit f7a2d6f

Browse files
authored
Merge pull request #3832 from mgorny/cross-python
Support v1 recipes in `CrossPythonMigrator`
2 parents 141732a + f80d060 commit f7a2d6f

File tree

6 files changed

+308
-17
lines changed

6 files changed

+308
-17
lines changed

Diff for: conda_forge_tick/migrators/cross_compile.py

+31-11
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,14 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
148148
f.write("".join(lines))
149149

150150

151-
class CrossPythonMigrator(CrossCompilationMigratorBase):
151+
class CrossPythonMigrator(MiniMigrator):
152+
allowed_schema_versions = {0, 1}
153+
post_migration = True
154+
152155
def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool:
156+
if super().filter(attrs, not_bad_str_start):
157+
return True
158+
153159
host_reqs = attrs.get("requirements", {}).get("host", set())
154160
build_reqs = attrs.get("requirements", {}).get("build", set())
155161
return (
@@ -161,7 +167,8 @@ def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool:
161167
def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> None:
162168
host_reqs = attrs.get("requirements", {}).get("host", set())
163169
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:
165172
lines = f.readlines()
166173
in_reqs = False
167174
for i, line in enumerate(lines):
@@ -189,24 +196,37 @@ def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict", **kwargs: Any) -> No
189196
for pkg in reversed(
190197
[
191198
"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+
),
193204
"cython",
194205
"numpy",
195206
"cffi",
196207
"pybind11",
197208
],
198209
):
199210
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)
207227
break
208228

209-
with open("meta.yaml", "w") as f:
229+
with open(recipe_file, "w") as f:
210230
f.write("".join(lines))
211231

212232

Diff for: tests/test_cross_compile.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,15 @@ def test_cross_rbase_build_sh(tmp_path, recipe_version: int):
205205
assert lines == expected
206206

207207

208+
@pytest.mark.parametrize("recipe_version", [0, 1])
208209
@flaky
209-
def test_cross_python(tmp_path):
210+
def test_cross_python(tmp_path, recipe_version: int):
210211
run_test_migration(
211212
m=version_migrator_python,
212-
inp=YAML_PATH.joinpath("python_recipe.yaml").read_text(),
213-
output=YAML_PATH.joinpath("python_recipe_correct.yaml").read_text(),
213+
inp=YAML_PATHS[recipe_version].joinpath("python_recipe.yaml").read_text(),
214+
output=YAML_PATHS[recipe_version]
215+
.joinpath("python_recipe_correct.yaml")
216+
.read_text(),
214217
prb="Dependencies have been updated if changed",
215218
kwargs={"new_version": "1.19.1"},
216219
mr_out={
@@ -219,15 +222,21 @@ def test_cross_python(tmp_path):
219222
"version": "1.19.1",
220223
},
221224
tmp_path=tmp_path,
225+
recipe_version=recipe_version,
222226
)
223227

224228

229+
@pytest.mark.parametrize("recipe_version", [0, 1])
225230
@flaky
226-
def test_cross_python_no_build(tmp_path):
231+
def test_cross_python_no_build(tmp_path, recipe_version: int):
227232
run_test_migration(
228233
m=version_migrator_python,
229-
inp=YAML_PATH.joinpath("python_no_build_recipe.yaml").read_text(),
230-
output=YAML_PATH.joinpath("python_no_build_recipe_correct.yaml").read_text(),
234+
inp=YAML_PATHS[recipe_version]
235+
.joinpath("python_no_build_recipe.yaml")
236+
.read_text(),
237+
output=YAML_PATHS[recipe_version]
238+
.joinpath("python_no_build_recipe_correct.yaml")
239+
.read_text(),
231240
prb="Dependencies have been updated if changed",
232241
kwargs={"new_version": "2020.6.20"},
233242
mr_out={
@@ -236,6 +245,7 @@ def test_cross_python_no_build(tmp_path):
236245
"version": "2020.6.20",
237246
},
238247
tmp_path=tmp_path,
248+
recipe_version=recipe_version,
239249
)
240250

241251

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
schema_version: 1
2+
3+
context:
4+
version: 2020.4.5.2
5+
pip_version: 19.1.1
6+
setuptools_version: 41.0.1
7+
8+
package:
9+
name: certifi
10+
version: ${{ version }}
11+
12+
source:
13+
- url: https://pypi.io/packages/source/c/certifi/certifi-${{ version }}.tar.gz
14+
sha256: 5ad7e9a056d25ffa5082862e36f119f7f7cec6457fa07ee2f8c339814b80c9b1
15+
target_directory: certifi
16+
# bootstrap pip and setuptools to avoid circular dependency
17+
# but without losing metadata
18+
- url: https://pypi.io/packages/py2.py3/p/pip/pip-${{ pip_version }}-py2.py3-none-any.whl
19+
sha256: 993134f0475471b91452ca029d4390dc8f298ac63a712814f101cd1b6db46676
20+
target_directory: pip_wheel
21+
- url: https://pypi.io/packages/py2.py3/s/setuptools/setuptools-${{ setuptools_version }}-py2.py3-none-any.whl
22+
sha256: c7769ce668c7a333d84e17fe8b524b1c45e7ee9f7908ad0a73e1eda7e6a5aebf
23+
target_directory: setuptools_wheel
24+
25+
build:
26+
number: 0
27+
28+
requirements:
29+
host:
30+
- python
31+
run:
32+
- python
33+
34+
tests:
35+
- python:
36+
imports:
37+
- certifi
38+
39+
about:
40+
license: ISC
41+
license_file: certifi/LICENSE
42+
summary: "Python package for providing Mozilla's CA Bundle."
43+
description: |
44+
Certifi is a curated collection of Root Certificates for validating the
45+
trustworthiness of SSL certificates while verifying the identity of TLS
46+
hosts.
47+
homepage: http://certifi.io/
48+
repository: https://github.com/certifi/python-certifi
49+
documentation: https://pypi.python.org/pypi/certifi
50+
51+
extra:
52+
recipe-maintainers:
53+
- jakirkham
54+
- pelson
55+
- sigmavirus24
56+
- ocefpaf
57+
- mingwandroid
58+
- jjhelmus
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
schema_version: 1
2+
3+
context:
4+
version: "2020.6.20"
5+
pip_version: 19.1.1
6+
setuptools_version: 41.0.1
7+
8+
package:
9+
name: certifi
10+
version: ${{ version }}
11+
12+
source:
13+
- url: https://pypi.io/packages/source/c/certifi/certifi-${{ version }}.tar.gz
14+
sha256: 5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3
15+
target_directory: certifi
16+
# bootstrap pip and setuptools to avoid circular dependency
17+
# but without losing metadata
18+
- url: https://pypi.io/packages/py2.py3/p/pip/pip-${{ pip_version }}-py2.py3-none-any.whl
19+
sha256: 993134f0475471b91452ca029d4390dc8f298ac63a712814f101cd1b6db46676
20+
target_directory: pip_wheel
21+
- url: https://pypi.io/packages/py2.py3/s/setuptools/setuptools-${{ setuptools_version }}-py2.py3-none-any.whl
22+
sha256: c7769ce668c7a333d84e17fe8b524b1c45e7ee9f7908ad0a73e1eda7e6a5aebf
23+
target_directory: setuptools_wheel
24+
25+
build:
26+
number: 0
27+
28+
requirements:
29+
build:
30+
- if: build_platform != host_platform
31+
then: python
32+
- if: build_platform != host_platform
33+
then: cross-python_${{ host_platform }}
34+
host:
35+
- python
36+
run:
37+
- python
38+
39+
tests:
40+
- python:
41+
imports:
42+
- certifi
43+
44+
about:
45+
license: ISC
46+
license_file: certifi/LICENSE
47+
summary: "Python package for providing Mozilla's CA Bundle."
48+
description: |
49+
Certifi is a curated collection of Root Certificates for validating the
50+
trustworthiness of SSL certificates while verifying the identity of TLS
51+
hosts.
52+
homepage: http://certifi.io/
53+
repository: https://github.com/certifi/python-certifi
54+
documentation: https://pypi.python.org/pypi/certifi
55+
56+
extra:
57+
recipe-maintainers:
58+
- jakirkham
59+
- pelson
60+
- sigmavirus24
61+
- ocefpaf
62+
- mingwandroid
63+
- jjhelmus

Diff for: tests/test_v1_yaml/cross_compile/python_recipe.yaml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
schema_version: 1
2+
3+
context:
4+
version: 1.19.0
5+
6+
package:
7+
name: numpy
8+
version: ${{ version }}
9+
10+
source:
11+
url: https://github.com/numpy/numpy/releases/download/v${{ version }}/numpy-${{ version }}.tar.gz
12+
sha256: 153cf8b0176e57a611931981acfe093d2f7fef623b48f91176efa199798a6b90
13+
14+
build:
15+
number: 0
16+
python:
17+
entry_points:
18+
- if: win
19+
then: f2py = numpy.f2py.f2py2e:main
20+
21+
requirements:
22+
build:
23+
- ${{ compiler('c') }}
24+
# gcc 7.3 segfaults on aarch64
25+
- if: aarch64
26+
then: clangdev
27+
host:
28+
- python
29+
- pip
30+
- cython
31+
- libblas
32+
- libcblas
33+
- liblapack
34+
run:
35+
- python
36+
37+
tests:
38+
- python:
39+
imports:
40+
- numpy
41+
- numpy.linalg.lapack_lite
42+
- requirements:
43+
run:
44+
- pytest
45+
- hypothesis
46+
script:
47+
- f2py -h
48+
- if: unix
49+
then: export OPENBLAS_NUM_THREADS=1
50+
- if: win
51+
then: set OPENBLAS_NUM_THREADS=1
52+
53+
about:
54+
license: BSD-3-Clause
55+
license_file: LICENSE.txt
56+
summary: Array processing for numbers, strings, records, and objects.
57+
homepage: http://numpy.scipy.org/
58+
repository: https://github.com/numpy/numpy
59+
documentation: https://docs.scipy.org/doc/numpy/reference/
60+
61+
extra:
62+
recipe-maintainers:
63+
- jakirkham
64+
- msarahan
65+
- pelson
66+
- rgommers
67+
- ocefpaf
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
schema_version: 1
2+
3+
context:
4+
version: "1.19.1"
5+
6+
package:
7+
name: numpy
8+
version: ${{ version }}
9+
10+
source:
11+
url: https://github.com/numpy/numpy/releases/download/v${{ version }}/numpy-${{ version }}.tar.gz
12+
sha256: 1396e6c3d20cbfc119195303b0272e749610b7042cc498be4134f013e9a3215c
13+
14+
build:
15+
number: 0
16+
python:
17+
entry_points:
18+
- if: win
19+
then: f2py = numpy.f2py.f2py2e:main
20+
21+
requirements:
22+
build:
23+
- if: build_platform != host_platform
24+
then: python
25+
- if: build_platform != host_platform
26+
then: cross-python_${{ host_platform }}
27+
- if: build_platform != host_platform
28+
then: cython
29+
- ${{ compiler('c') }}
30+
# gcc 7.3 segfaults on aarch64
31+
- if: aarch64
32+
then: clangdev
33+
host:
34+
- python
35+
- pip
36+
- cython
37+
- libblas
38+
- libcblas
39+
- liblapack
40+
run:
41+
- python
42+
43+
tests:
44+
- python:
45+
imports:
46+
- numpy
47+
- numpy.linalg.lapack_lite
48+
- requirements:
49+
run:
50+
- pytest
51+
- hypothesis
52+
script:
53+
- f2py -h
54+
- if: unix
55+
then: export OPENBLAS_NUM_THREADS=1
56+
- if: win
57+
then: set OPENBLAS_NUM_THREADS=1
58+
59+
about:
60+
license: BSD-3-Clause
61+
license_file: LICENSE.txt
62+
summary: Array processing for numbers, strings, records, and objects.
63+
homepage: http://numpy.scipy.org/
64+
repository: https://github.com/numpy/numpy
65+
documentation: https://docs.scipy.org/doc/numpy/reference/
66+
67+
extra:
68+
recipe-maintainers:
69+
- jakirkham
70+
- msarahan
71+
- pelson
72+
- rgommers
73+
- ocefpaf

0 commit comments

Comments
 (0)