Skip to content

Commit 1c5c250

Browse files
Merge branch 'main' into nerfstudio
2 parents f8ee66e + dccaf70 commit 1c5c250

15 files changed

+680
-366
lines changed

.ci_support/build_all.py

Lines changed: 104 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
EXAMPLE_RECIPE_FOLDERS = ["example", "example-v1"]
2727
LOCAL_CHANNELS = os.environ.get("CONDA_BLD_PATH", "local").split(",")
2828

29+
2930
def get_host_platform():
3031
from sys import platform
32+
3133
if platform == "linux" or platform == "linux2":
3234
return "linux"
3335
elif platform == "darwin":
@@ -54,7 +56,9 @@ def build_all(recipes_dir, arch):
5456

5557
platform = get_host_platform()
5658
script_dir = os.path.dirname(os.path.realpath(__file__))
57-
variant_config_file = os.path.join(script_dir, "{}.yaml".format(get_config_name(arch)))
59+
variant_config_file = os.path.join(
60+
script_dir, "{}.yaml".format(get_config_name(arch))
61+
)
5862

5963
has_meta_yaml = False
6064
has_recipe_yaml = False
@@ -65,11 +69,11 @@ def build_all(recipes_dir, arch):
6569
meta_yaml = os.path.join(recipes_dir, folder, "meta.yaml")
6670
if os.path.exists(meta_yaml):
6771
has_meta_yaml = True
68-
with(open(meta_yaml, "r", encoding="utf-8")) as f:
69-
text = ''.join(f.readlines())
70-
if 'cuda' in text:
72+
with open(meta_yaml, "r", encoding="utf-8") as f:
73+
text = "".join(f.readlines())
74+
if "cuda" in text:
7175
found_cuda = True
72-
if 'sysroot_linux-64' in text:
76+
if "sysroot_linux-64" in text:
7377
found_centos7 = True
7478

7579
recipe_yaml = os.path.join(recipes_dir, folder, "recipe.yaml")
@@ -86,16 +90,18 @@ def build_all(recipes_dir, arch):
8690
if os.path.exists(cbc):
8791
with open(cbc, "r") as f:
8892
lines = f.readlines()
89-
pat = re.compile(r"^([^\#]*?)\s+\#\s\[.*(not\s(linux|unix)|(?<!not\s)(osx|win)).*\]\s*$")
93+
pat = re.compile(
94+
r"^([^\#]*?)\s+\#\s\[.*(not\s(linux|unix)|(?<!not\s)(osx|win)).*\]\s*$"
95+
)
9096
# remove lines with selectors that don't apply to linux, i.e. if they contain
9197
# "not linux", "not unix", "osx" or "win"; this also removes trailing newlines
9298
lines = [pat.sub("", x) for x in lines]
9399
text = "\n".join(lines)
94-
if platform == 'linux' and ('c_stdlib_version' in text):
100+
if platform == "linux" and ("c_stdlib_version" in text):
95101
config = load(text, Loader=BaseLoader)
96-
if 'c_stdlib_version' in config:
97-
for version in config['c_stdlib_version']:
98-
version = tuple([int(x) for x in version.split('.')])
102+
if "c_stdlib_version" in config:
103+
for version in config["c_stdlib_version"]:
104+
version = tuple([int(x) for x in version.split(".")])
99105
print(f"Found c_stdlib_version for linux: {version=}")
100106
found_centos7 |= version == (2, 17)
101107

@@ -105,7 +111,7 @@ def build_all(recipes_dir, arch):
105111
raise ValueError("Neither a meta.yaml or a recipe.yaml recipes was found")
106112

107113
if found_cuda:
108-
print('##vso[task.setvariable variable=NEED_CUDA;isOutput=true]1')
114+
print("##vso[task.setvariable variable=NEED_CUDA;isOutput=true]1")
109115
if found_centos7:
110116
os.environ["DEFAULT_LINUX_VERSION"] = "cos7"
111117
print("Overriding DEFAULT_LINUX_VERSION to be cos7")
@@ -118,70 +124,78 @@ def build_all(recipes_dir, arch):
118124
if os.path.exists(cbc):
119125
with open(cbc, "r") as f:
120126
lines = f.readlines()
121-
pat = re.compile(r"^([^\#]*?)\s+\#\s\[.*(not\s(osx|unix)|(?<!not\s)(linux|win)).*\]\s*$")
127+
pat = re.compile(
128+
r"^([^\#]*?)\s+\#\s\[.*(not\s(osx|unix)|(?<!not\s)(linux|win)).*\]\s*$"
129+
)
122130
# remove lines with selectors that don't apply to osx, i.e. if they contain
123131
# "not osx", "not unix", "linux" or "win"; this also removes trailing newlines
124132
lines = [pat.sub("", x) for x in lines]
125133
text = "\n".join(lines)
126-
if platform == 'osx' and (
127-
'MACOSX_DEPLOYMENT_TARGET' in text or
128-
'MACOSX_SDK_VERSION' in text or
129-
'c_stdlib_version' in text):
134+
if platform == "osx" and (
135+
"MACOSX_DEPLOYMENT_TARGET" in text
136+
or "MACOSX_SDK_VERSION" in text
137+
or "c_stdlib_version" in text
138+
):
130139
config = load(text, Loader=BaseLoader)
131140

132-
if 'MACOSX_DEPLOYMENT_TARGET' in config:
133-
for version in config['MACOSX_DEPLOYMENT_TARGET']:
134-
version = tuple([int(x) for x in version.split('.')])
141+
if "MACOSX_DEPLOYMENT_TARGET" in config:
142+
for version in config["MACOSX_DEPLOYMENT_TARGET"]:
143+
version = tuple([int(x) for x in version.split(".")])
135144
deployment_version = max(deployment_version, version)
136-
if 'c_stdlib_version' in config:
137-
for version in config['c_stdlib_version']:
138-
version = tuple([int(x) for x in version.split('.')])
145+
if "c_stdlib_version" in config:
146+
for version in config["c_stdlib_version"]:
147+
version = tuple([int(x) for x in version.split(".")])
139148
print(f"Found c_stdlib_version for osx: {version=}")
140149
deployment_version = max(deployment_version, version)
141-
if 'MACOSX_SDK_VERSION' in config:
142-
for version in config['MACOSX_SDK_VERSION']:
143-
version = tuple([int(x) for x in version.split('.')])
150+
if "MACOSX_SDK_VERSION" in config:
151+
for version in config["MACOSX_SDK_VERSION"]:
152+
version = tuple([int(x) for x in version.split(".")])
144153
sdk_version = max(sdk_version, deployment_version, version)
145154

146-
if 'channel_sources' not in text:
147-
new_channel_urls = [*LOCAL_CHANNELS, 'conda-forge']
155+
if "channel_sources" not in text:
156+
new_channel_urls = [*LOCAL_CHANNELS, "conda-forge"]
148157
else:
149158
config = load(text, Loader=BaseLoader)
150-
new_channel_urls = [*LOCAL_CHANNELS, *config['channel_sources'][0].split(',')]
159+
new_channel_urls = [
160+
*LOCAL_CHANNELS,
161+
*config["channel_sources"][0].split(","),
162+
]
151163
if channel_urls is None:
152164
channel_urls = new_channel_urls
153165
elif channel_urls != new_channel_urls:
154-
raise ValueError(f'Detected different channel_sources in the recipes: {channel_urls} vs. {new_channel_urls}. Consider submitting them in separate PRs')
166+
raise ValueError(
167+
f"Detected different channel_sources in the recipes: {channel_urls} vs. {new_channel_urls}. Consider submitting them in separate PRs"
168+
)
155169

156170
if channel_urls is None:
157-
channel_urls = [*LOCAL_CHANNELS, 'conda-forge']
171+
channel_urls = [*LOCAL_CHANNELS, "conda-forge"]
158172

159-
with open(variant_config_file, 'r') as f:
160-
variant_text = ''.join(f.readlines())
173+
with open(variant_config_file, "r") as f:
174+
variant_text = "".join(f.readlines())
161175

162176
if deployment_version != (0, 0):
163-
deployment_version = '.'.join([str(x) for x in deployment_version])
177+
deployment_version = ".".join([str(x) for x in deployment_version])
164178
print("Overriding MACOSX_DEPLOYMENT_TARGET to be ", deployment_version)
165-
variant_text += '\nMACOSX_DEPLOYMENT_TARGET:\n'
179+
variant_text += "\nMACOSX_DEPLOYMENT_TARGET:\n"
166180
variant_text += f'- "{deployment_version}"\n'
167181

168182
if sdk_version != (0, 0):
169-
sdk_version = '.'.join([str(x) for x in sdk_version])
183+
sdk_version = ".".join([str(x) for x in sdk_version])
170184
print("Overriding MACOSX_SDK_VERSION to be ", sdk_version)
171-
variant_text += '\nMACOSX_SDK_VERSION:\n'
185+
variant_text += "\nMACOSX_SDK_VERSION:\n"
172186
variant_text += f'- "{sdk_version}"\n'
173187

174-
with open(variant_config_file, 'w') as f:
188+
with open(variant_config_file, "w") as f:
175189
f.write(variant_text)
176190

177191
if platform == "osx" and (sdk_version != (0, 0) or deployment_version != (0, 0)):
178192
subprocess.run("run_conda_forge_build_setup", shell=True, check=True)
179193

180-
if 'conda-forge' not in channel_urls:
181-
raise ValueError('conda-forge needs to be part of channel_sources')
182-
194+
if "conda-forge" not in channel_urls:
195+
raise ValueError("conda-forge needs to be part of channel_sources")
196+
183197
if has_meta_yaml:
184-
print("Building {} with {}".format(','.join(folders), ','.join(channel_urls)))
198+
print("Building {} with {}".format(",".join(folders), ",".join(channel_urls)))
185199
build_folders(recipes_dir, folders, arch, channel_urls)
186200
elif has_recipe_yaml:
187201
print(
@@ -193,28 +207,31 @@ def build_all(recipes_dir, arch):
193207

194208

195209
def get_config(arch, channel_urls):
196-
exclusive_config_files = [os.path.join(conda.base.context.context.root_prefix,
197-
'conda_build_config.yaml')]
210+
exclusive_config_files = [
211+
os.path.join(conda.base.context.context.root_prefix, "conda_build_config.yaml")
212+
]
198213
script_dir = os.path.dirname(os.path.realpath(__file__))
199214
# since variant builds override recipe/conda_build_config.yaml, see
200215
# https://github.com/conda/conda-build/blob/3.21.8/conda_build/variants.py#L175-L181
201216
# we need to make sure not to use variant_configs here, otherwise
202217
# staged-recipes PRs cannot override anything using the recipe-cbc.
203-
exclusive_config_file = os.path.join(script_dir, '{}.yaml'.format(
204-
get_config_name(arch)))
218+
exclusive_config_file = os.path.join(
219+
script_dir, "{}.yaml".format(get_config_name(arch))
220+
)
205221
if os.path.exists(exclusive_config_file):
206222
exclusive_config_files.append(exclusive_config_file)
207223

208224
config = conda_build.api.Config(
209-
arch=arch, exclusive_config_files=exclusive_config_files,
210-
channel_urls=channel_urls, error_overlinking=True,
225+
arch=arch,
226+
exclusive_config_files=exclusive_config_files,
227+
channel_urls=channel_urls,
228+
error_overlinking=True,
211229
)
212230
return config
213231

214232

215233
def build_folders(recipes_dir, folders, arch, channel_urls):
216-
217-
index_path = os.path.join(sys.exec_prefix, 'conda-bld')
234+
index_path = os.path.join(sys.exec_prefix, "conda-bld")
218235
os.makedirs(index_path, exist_ok=True)
219236
conda_index.api.update_index(index_path)
220237
index = conda.core.index.get_index(channel_urls=channel_urls)
@@ -223,26 +240,38 @@ def build_folders(recipes_dir, folders, arch, channel_urls):
223240
config = get_config(arch, channel_urls)
224241
platform = get_host_platform()
225242

226-
worker = {'platform': platform, 'arch': arch,
227-
'label': '{}-{}'.format(platform, arch)}
243+
worker = {
244+
"platform": platform,
245+
"arch": arch,
246+
"label": "{}-{}".format(platform, arch),
247+
}
228248

229-
G = construct_graph(recipes_dir, worker=worker, run='build',
230-
conda_resolve=conda_resolve, folders=folders,
231-
config=config, finalize=False)
249+
G = construct_graph(
250+
recipes_dir,
251+
worker=worker,
252+
run="build",
253+
conda_resolve=conda_resolve,
254+
folders=folders,
255+
config=config,
256+
finalize=False,
257+
)
232258
order = list(nx.topological_sort(G))
233259
order.reverse()
234260

235-
print('Computed that there are {} distributions to build from {} recipes'
236-
.format(len(order), len(folders)))
261+
print(
262+
"Computed that there are {} distributions to build from {} recipes".format(
263+
len(order), len(folders)
264+
)
265+
)
237266
if not order:
238-
print('Nothing to do')
267+
print("Nothing to do")
239268
return
240269
print("Resolved dependencies, will be built in the following order:")
241-
print(' '+'\n '.join(order))
270+
print(" " + "\n ".join(order))
242271

243272
d = OrderedDict()
244273
for node in order:
245-
d[G.nodes[node]['meta'].meta_path] = 1
274+
d[G.nodes[node]["meta"].meta_path] = 1
246275

247276
for recipe in d.keys():
248277
conda_build.api.build([recipe], config=get_config(arch, channel_urls))
@@ -285,7 +314,7 @@ def build_folders_rattler_build(
285314
# Construct a temporary file where we write the combined variant config. We can then pass that
286315
# to rattler-build.
287316
with tempfile.NamedTemporaryFile(delete=False) as fp:
288-
fp.write(variant_config.encode("utf-8"))
317+
fp.write(variant_config.encode("utf-8"))
289318
atexit.register(os.unlink, fp.name)
290319

291320
# Execute rattler-build.
@@ -295,17 +324,21 @@ def build_folders_rattler_build(
295324
def check_recipes_in_correct_dir(root_dir, correct_dir):
296325
for path in Path(root_dir).glob("*"):
297326
path = Path(path)
298-
if path.is_dir() and path.name.lower() in ('.pixi', 'build_artifacts', 'miniforge3'):
327+
if path.is_dir() and path.name.lower() in (
328+
".pixi",
329+
"build_artifacts",
330+
"miniforge3",
331+
):
299332
# ignore pkg_cache in build_artifacts
300333
continue
301-
for recipe_path in path.rglob('*.yaml'):
334+
for recipe_path in path.rglob("*.yaml"):
302335
if recipe_path.name not in ("meta.yaml", "recipe.yaml"):
303336
continue
304337
recipe_path = recipe_path.absolute().relative_to(root_dir)
305338
if (
306-
(recipe_path.parts[0] != correct_dir and recipe_path.parts[0] != "broken-recipes")
307-
or len(recipe_path.parts) != 3
308-
):
339+
recipe_path.parts[0] != correct_dir
340+
and recipe_path.parts[0] != "broken-recipes"
341+
) or len(recipe_path.parts) != 3:
309342
raise RuntimeError(
310343
f"recipe {recipe_path} in wrong directory; "
311344
f"must be under {correct_dir}/<name>/"
@@ -336,21 +369,22 @@ def read_mambabuild(recipes_dir):
336369

337370
def use_mambabuild():
338371
from boa.cli.mambabuild import prepare
372+
339373
prepare()
340374

341375

342376
if __name__ == "__main__":
343377
parser = argparse.ArgumentParser()
344378
parser.add_argument(
345-
'--arch',
346-
default='64',
347-
help='target architecture (second component of a subdir; e.g. 64, arm64, ppc64le)'
379+
"--arch",
380+
default="64",
381+
help="target architecture (second component of a subdir; e.g. 64, arm64, ppc64le)",
348382
)
349383
args = parser.parse_args()
350384
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
351385
check_recipes_in_correct_dir(root_dir, "recipes")
352386
use_mamba = read_mambabuild(os.path.join(root_dir, "recipes"))
353387
if use_mamba:
354-
use_mambabuild()
355-
subprocess.run("conda clean --all --yes", shell=True, check=True)
388+
use_mambabuild()
389+
subprocess.run("conda clean --all --yes", shell=True, check=True)
356390
build_all(os.path.join(root_dir, "recipes"), args.arch)

0 commit comments

Comments
 (0)