Skip to content

Commit 70b6472

Browse files
committed
modify build_all.py to use rattler-build
1 parent e26076d commit 70b6472

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

.ci_support/build_all.py

+47-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from itertools import chain
2+
import json
13
import conda.base.context
24
import conda.core.index
35
import conda.resolve
@@ -44,17 +46,32 @@ def build_all(recipes_dir, arch):
4446
script_dir = os.path.dirname(os.path.realpath(__file__))
4547
variant_config_file = os.path.join(script_dir, "{}.yaml".format(get_config_name(arch)))
4648

49+
has_meta_yaml = False
50+
has_recipe_yaml = False
51+
4752
found_cuda = False
4853
found_centos7 = False
4954
for folder in folders:
5055
meta_yaml = os.path.join(recipes_dir, folder, "meta.yaml")
5156
if os.path.exists(meta_yaml):
57+
has_meta_yaml = True
5258
with(open(meta_yaml, "r", encoding="utf-8")) as f:
5359
text = ''.join(f.readlines())
5460
if 'cuda' in text:
5561
found_cuda = True
5662
if 'sysroot_linux-64' in text:
5763
found_centos7 = True
64+
65+
recipe_yaml = os.path.join(recipes_dir, folder, "recipe.yaml")
66+
if os.path.exists(recipe_yaml):
67+
has_recipe_yaml = True
68+
with(open(recipe_yaml, "r", encoding="utf-8")) as f:
69+
text = ''.join(f.readlines())
70+
if 'cuda' in text:
71+
found_cuda = True
72+
if 'sysroot_linux-64' in text:
73+
found_centos7 = True
74+
5875
cbc = os.path.join(recipes_dir, folder, "conda_build_config.yaml")
5976
if os.path.exists(cbc):
6077
with open(cbc, "r") as f:
@@ -72,6 +89,11 @@ def build_all(recipes_dir, arch):
7289
print(f"Found c_stdlib_version for linux: {version=}")
7390
found_centos7 |= version == (2, 17)
7491

92+
if has_meta_yaml and has_recipe_yaml:
93+
raise ValueError('Mixing meta.yaml and recipe.yaml recipes is not supported')
94+
if not has_meta_yaml and not has_recipe_yaml:
95+
raise ValueError('Neither a meta.yaml or a recipe.yaml recipes was found')
96+
7597
if found_cuda:
7698
print('##vso[task.setvariable variable=NEED_CUDA;isOutput=true]1')
7799
if found_centos7:
@@ -147,8 +169,13 @@ def build_all(recipes_dir, arch):
147169

148170
if 'conda-forge' not in channel_urls:
149171
raise ValueError('conda-forge needs to be part of channel_sources')
150-
print("Building {} with {}".format(','.join(folders), ','.join(channel_urls)))
151-
build_folders(recipes_dir, folders, arch, channel_urls)
172+
173+
if has_meta_yaml:
174+
print("Building {} with {} using conda-build".format(','.join(folders), ','.join(channel_urls)))
175+
build_folders(recipes_dir, folders, arch, channel_urls)
176+
elif has_recipe_yaml:
177+
print("Building {} with {} using rattler-build".format(','.join(folders), ','.join(channel_urls)))
178+
build_folders_rattler_build(recipes_dir, platform, arch, channel_urls)
152179

153180

154181
def get_config(arch, channel_urls):
@@ -207,9 +234,26 @@ def build_folders(recipes_dir, folders, arch, channel_urls):
207234
conda_build.api.build([recipe], config=get_config(arch, channel_urls))
208235

209236

237+
def build_folders_rattler_build(recipes_dir: str, platform, arch, channel_urls: list[str]):
238+
# Define the arguments for rattler-build
239+
args = [
240+
"rattler-build",
241+
"build",
242+
"--recipe-dir", recipes_dir,
243+
"--target-platform", f"{platform}-{arch}",
244+
]
245+
for channel_url in channel_urls:
246+
# Local is automatically added by rattler-build so we just remove it.
247+
if channel_url != "local":
248+
args.extend(["-c", channel_url])
249+
250+
# Execute rattler-build.
251+
subprocess.run(args, check=True)
252+
253+
210254
def check_recipes_in_correct_dir(root_dir, correct_dir):
211255
from pathlib import Path
212-
for path in Path(root_dir).rglob('meta.yaml'):
256+
for path in chain(Path(root_dir).rglob('meta.yaml'), Path(root_dir).rglob('recipe.yaml')):
213257
path = path.absolute().relative_to(root_dir)
214258
if path.parts[0] == 'build_artifacts':
215259
# ignore pkg_cache in build_artifacts

0 commit comments

Comments
 (0)