Skip to content

Commit 7a8c1d7

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

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

.ci_support/build_all.py

+46-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import conda.base.context
23
import conda.core.index
34
import conda.resolve
@@ -44,17 +45,32 @@ def build_all(recipes_dir, arch):
4445
script_dir = os.path.dirname(os.path.realpath(__file__))
4546
variant_config_file = os.path.join(script_dir, "{}.yaml".format(get_config_name(arch)))
4647

48+
has_meta_yaml = False
49+
has_recipe_yaml = False
50+
4751
found_cuda = False
4852
found_centos7 = False
4953
for folder in folders:
5054
meta_yaml = os.path.join(recipes_dir, folder, "meta.yaml")
5155
if os.path.exists(meta_yaml):
56+
has_meta_yaml = True
5257
with(open(meta_yaml, "r", encoding="utf-8")) as f:
5358
text = ''.join(f.readlines())
5459
if 'cuda' in text:
5560
found_cuda = True
5661
if 'sysroot_linux-64' in text:
5762
found_centos7 = True
63+
64+
recipe_yaml = os.path.join(recipes_dir, folder, "recipe.yaml")
65+
if os.path.exists(recipe_yaml):
66+
has_recipe_yaml = True
67+
with(open(recipe_yaml, "r", encoding="utf-8")) as f:
68+
text = ''.join(f.readlines())
69+
if 'cuda' in text:
70+
found_cuda = True
71+
if 'sysroot_linux-64' in text:
72+
found_centos7 = True
73+
5874
cbc = os.path.join(recipes_dir, folder, "conda_build_config.yaml")
5975
if os.path.exists(cbc):
6076
with open(cbc, "r") as f:
@@ -72,6 +88,11 @@ def build_all(recipes_dir, arch):
7288
print(f"Found c_stdlib_version for linux: {version=}")
7389
found_centos7 |= version == (2, 17)
7490

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

148169
if 'conda-forge' not in channel_urls:
149170
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)
171+
172+
if has_meta_yaml:
173+
print("Building {} with {} using conda-build".format(','.join(folders), ','.join(channel_urls)))
174+
build_folders(recipes_dir, folders, arch, channel_urls)
175+
elif has_recipe_yaml:
176+
print("Building {} with {} using rattler-build".format(','.join(folders), ','.join(channel_urls)))
177+
build_folders_rattler_build(recipes_dir, platform, arch, channel_urls)
152178

153179

154180
def get_config(arch, channel_urls):
@@ -207,6 +233,24 @@ def build_folders(recipes_dir, folders, arch, channel_urls):
207233
conda_build.api.build([recipe], config=get_config(arch, channel_urls))
208234

209235

236+
def build_folders_rattler_build(recipes_dir: str, platform, arch, channel_urls: list[str]):
237+
# Local is automatically added by rattler-build so we just remove it.
238+
channel_urls.remove("local")
239+
240+
# Define the arguments for rattler-build
241+
args = [
242+
"rattler-build",
243+
"build",
244+
"--recipe-dir", recipes_dir,
245+
"--target-platform", f"{platform}-{arch}",
246+
]
247+
for channel_url in channel_urls:
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
212256
for path in Path(root_dir).rglob('meta.yaml'):

0 commit comments

Comments
 (0)