Skip to content

Commit 9f4edb3

Browse files
committed
Use keyword
1 parent ee2e4c3 commit 9f4edb3

File tree

4 files changed

+136
-75
lines changed

4 files changed

+136
-75
lines changed

Diff for: cpython-unix/build.py

+71-36
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,16 @@ def add_target_env(env, build_platform, target_triple, build_env):
214214
env["EXTRA_TARGET_LDFLAGS"] = " ".join(extra_target_ldflags)
215215

216216

217-
def toolchain_archive_path(package_name, host_platform, downloads):
217+
def toolchain_archive_path(package_name, host_platform, *, downloads: Downloads):
218218
entry = downloads[package_name]
219219

220220
basename = "%s-%s-%s.tar" % (package_name, entry["version"], host_platform)
221221

222222
return BUILD / basename
223223

224224

225-
def install_binutils(platform):
226-
return platform != "macos"
225+
def install_binutils(host_platform):
226+
return host_platform != "macos"
227227

228228

229229
def simple_build(
@@ -234,12 +234,13 @@ def simple_build(
234234
host_platform,
235235
target_triple,
236236
optimizations,
237-
downloads: Downloads,
238237
dest_archive,
239238
extra_archives=None,
240239
tools_path="deps",
240+
*,
241+
downloads: Downloads,
241242
):
242-
archive = download_entry(entry, DOWNLOADS_PATH, downloads)
243+
archive = download_entry(entry, DOWNLOADS_PATH, downloads=downloads)
243244

244245
with build_environment(client, image) as build_env:
245246
if settings.get("needs_toolchain"):
@@ -250,6 +251,7 @@ def simple_build(
250251
binutils=install_binutils(host_platform),
251252
clang=True,
252253
musl="musl" in target_triple,
254+
downloads=downloads,
253255
)
254256

255257
for a in extra_archives or []:
@@ -275,9 +277,9 @@ def simple_build(
275277
build_env.get_tools_archive(dest_archive, tools_path)
276278

277279

278-
def build_binutils(client, image, host_platform, downloads):
280+
def build_binutils(client, image, host_platform, *, downloads: Downloads):
279281
"""Build binutils in the Docker image."""
280-
archive = download_entry("binutils", DOWNLOADS_PATH, downloads)
282+
archive = download_entry("binutils", DOWNLOADS_PATH, downloads=downloads)
281283

282284
with build_environment(client, image) as build_env:
283285
install_sccache(build_env)
@@ -295,13 +297,18 @@ def build_binutils(client, image, host_platform, downloads):
295297
)
296298

297299
build_env.get_tools_archive(
298-
toolchain_archive_path("binutils", host_platform, downloads), "host"
300+
toolchain_archive_path(
301+
"binutils",
302+
host_platform,
303+
downloads=downloads,
304+
),
305+
"host",
299306
)
300307

301308

302-
def materialize_clang(host_platform: str, target_triple: str, downloads):
309+
def materialize_clang(host_platform: str, target_triple: str, *, downloads: Downloads):
303310
entry = clang_toolchain(host_platform, target_triple)
304-
tar_zst = download_entry(entry, DOWNLOADS_PATH, downloads)
311+
tar_zst = download_entry(entry, DOWNLOADS_PATH, downloads=downloads)
305312
local_filename = "%s-%s-%s.tar" % (
306313
entry,
307314
downloads[entry]["version"],
@@ -315,12 +322,24 @@ def materialize_clang(host_platform: str, target_triple: str, downloads):
315322
dctx.copy_stream(ifh, ofh)
316323

317324

318-
def build_musl(client, image, host_platform: str, target_triple: str, downloads):
319-
musl_archive = download_entry("musl", DOWNLOADS_PATH, downloads)
325+
def build_musl(
326+
client,
327+
image,
328+
host_platform: str,
329+
target_triple: str,
330+
*,
331+
downloads: Downloads,
332+
):
333+
musl_archive = download_entry("musl", DOWNLOADS_PATH, downloads=downloads)
320334

321335
with build_environment(client, image) as build_env:
322336
build_env.install_toolchain(
323-
BUILD, host_platform, target_triple, binutils=True, clang=True
337+
BUILD,
338+
host_platform,
339+
target_triple,
340+
binutils=True,
341+
clang=True,
342+
downloads=downloads,
324343
)
325344
build_env.copy_file(musl_archive)
326345
build_env.copy_file(SUPPORT / "build-musl.sh")
@@ -333,7 +352,12 @@ def build_musl(client, image, host_platform: str, target_triple: str, downloads)
333352
build_env.run("build-musl.sh", environment=env)
334353

335354
build_env.get_tools_archive(
336-
toolchain_archive_path("musl", host_platform), "host"
355+
toolchain_archive_path(
356+
"musl",
357+
host_platform,
358+
downloads=downloads,
359+
),
360+
"host",
337361
)
338362

339363

@@ -345,9 +369,10 @@ def build_libedit(
345369
target_triple,
346370
optimizations,
347371
dest_archive,
372+
*,
348373
downloads: Downloads,
349374
):
350-
libedit_archive = download_entry("libedit", DOWNLOADS_PATH, downloads)
375+
libedit_archive = download_entry("libedit", DOWNLOADS_PATH, downloads=downloads)
351376

352377
with build_environment(client, image) as build_env:
353378
if settings.get("needs_toolchain"):
@@ -358,6 +383,7 @@ def build_libedit(
358383
binutils=install_binutils(host_platform),
359384
clang=True,
360385
musl="musl" in target_triple,
386+
downloads=downloads,
361387
)
362388

363389
build_env.install_artifact_archive(
@@ -384,11 +410,12 @@ def build_tix(
384410
target_triple,
385411
optimizations,
386412
dest_archive,
413+
*,
387414
downloads: Downloads,
388415
):
389-
tcl_archive = download_entry("tcl", DOWNLOADS_PATH, downloads)
390-
tk_archive = download_entry("tk", DOWNLOADS_PATH, downloads)
391-
tix_archive = download_entry("tix", DOWNLOADS_PATH, downloads)
416+
tcl_archive = download_entry("tcl", DOWNLOADS_PATH, downloads=downloads)
417+
tk_archive = download_entry("tk", DOWNLOADS_PATH, downloads=downloads)
418+
tix_archive = download_entry("tix", DOWNLOADS_PATH, downloads=downloads)
392419

393420
with build_environment(client, image) as build_env:
394421
if settings.get("needs_toolchain"):
@@ -399,6 +426,7 @@ def build_tix(
399426
binutils=install_binutils(host_platform),
400427
clang=True,
401428
musl="musl" in target_triple,
429+
downloads=downloads,
402430
)
403431

404432
depends = {"tcl", "tk"}
@@ -432,10 +460,11 @@ def build_cpython_host(
432460
target_triple: str,
433461
optimizations: str,
434462
dest_archive,
463+
*,
435464
downloads: Downloads,
436465
):
437466
"""Build binutils in the Docker image."""
438-
archive = download_entry(entry, DOWNLOADS_PATH, downloads)
467+
archive = download_entry(entry, DOWNLOADS_PATH, downloads=downloads)
439468

440469
with build_environment(client, image) as build_env:
441470
python_version = downloads[entry]["version"]
@@ -446,6 +475,7 @@ def build_cpython_host(
446475
target_triple,
447476
binutils=install_binutils(host_platform),
448477
clang=True,
478+
downloads=downloads,
449479
)
450480

451481
build_env.copy_file(archive)
@@ -492,12 +522,13 @@ def build_cpython_host(
492522
def python_build_info(
493523
build_env,
494524
version,
495-
platform,
525+
host_platform,
496526
target_triple,
497527
musl,
498528
optimizations,
499529
extensions,
500530
extra_metadata,
531+
*,
501532
downloads: Downloads,
502533
):
503534
"""Obtain build metadata for the Python distribution."""
@@ -508,7 +539,7 @@ def python_build_info(
508539

509540
binary_suffix = ""
510541

511-
if platform == "linux64":
542+
if host_platform == "linux64":
512543
bi["core"]["static_lib"] = (
513544
"install/lib/python{version}/config-{version}{binary_suffix}-x86_64-linux-gnu/libpython{version}{binary_suffix}.a".format(
514545
version=version, binary_suffix=binary_suffix
@@ -522,7 +553,7 @@ def python_build_info(
522553
)
523554

524555
if optimizations in ("lto", "pgo+lto"):
525-
llvm_version = downloads[clang_toolchain(platform, target_triple)][
556+
llvm_version = downloads[clang_toolchain(host_platform, target_triple)][
526557
"version"
527558
]
528559
if "+" in llvm_version:
@@ -531,7 +562,7 @@ def python_build_info(
531562
object_file_format = f"llvm-bitcode:%{llvm_version}"
532563
else:
533564
object_file_format = "elf"
534-
elif platform == "macos":
565+
elif host_platform == "macos":
535566
bi["core"]["static_lib"] = (
536567
"install/lib/python{version}/config-{version}{binary_suffix}-darwin/libpython{version}{binary_suffix}.a".format(
537568
version=version, binary_suffix=binary_suffix
@@ -549,7 +580,7 @@ def python_build_info(
549580
else:
550581
object_file_format = "mach-o"
551582
else:
552-
raise Exception("unsupported platform: %s" % platform)
583+
raise Exception("unsupported platform: %s" % host_platform)
553584

554585
bi["object_file_format"] = object_file_format
555586

@@ -564,9 +595,9 @@ def python_build_info(
564595
if lib.startswith("-l"):
565596
lib = lib[2:]
566597

567-
if platform == "linux64" and lib not in LINUX_ALLOW_SYSTEM_LIBRARIES:
598+
if host_platform == "linux64" and lib not in LINUX_ALLOW_SYSTEM_LIBRARIES:
568599
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))
569-
elif platform == "macos" and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES:
600+
elif host_platform == "macos" and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES:
570601
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))
571602

572603
log("adding core system link library: %s" % lib)
@@ -681,7 +712,7 @@ def python_build_info(
681712
extension_suffix = extra_metadata["python_config_vars"]["EXT_SUFFIX"]
682713
entry["shared_lib"] = "%s/%s%s" % (shared_dir, extension, extension_suffix)
683714

684-
add_licenses_to_extension_entry(entry)
715+
add_licenses_to_extension_entry(entry, downloads=downloads)
685716

686717
bi["extensions"].setdefault(extension, []).append(entry)
687718

@@ -701,17 +732,18 @@ def build_cpython(
701732
host_platform,
702733
target_triple,
703734
optimizations,
704-
downloads: Downloads,
705735
dest_archive,
706736
version=None,
707737
python_source=None,
738+
*,
739+
downloads: Downloads,
708740
):
709741
"""Build CPython in a Docker image'"""
710742
entry_name = "cpython-%s" % version
711743
entry = downloads[entry_name]
712744
if not python_source:
713745
python_version = entry["version"]
714-
python_archive = download_entry(entry_name, DOWNLOADS_PATH, downloads)
746+
python_archive = download_entry(entry_name, DOWNLOADS_PATH, downloads=downloads)
715747
else:
716748
python_version = os.environ["PYBUILD_PYTHON_VERSION"]
717749
python_archive = DOWNLOADS_PATH / ("Python-%s.tar.xz" % python_version)
@@ -721,8 +753,10 @@ def build_cpython(
721753
fh, python_source, path_prefix="Python-%s" % python_version
722754
)
723755

724-
setuptools_archive = download_entry("setuptools", DOWNLOADS_PATH, downloads)
725-
pip_archive = download_entry("pip", DOWNLOADS_PATH, downloads)
756+
setuptools_archive = download_entry(
757+
"setuptools", DOWNLOADS_PATH, downloads=downloads
758+
)
759+
pip_archive = download_entry("pip", DOWNLOADS_PATH, downloads=downloads)
726760

727761
ems = extension_modules_config(EXTENSION_MODULES)
728762

@@ -746,6 +780,7 @@ def build_cpython(
746780
binutils=install_binutils(host_platform),
747781
clang=True,
748782
musl="musl" in target_triple,
783+
downloads=downloads,
749784
)
750785

751786
packages = target_needs(TARGETS_CONFIG, target_triple, python_version)
@@ -1008,9 +1043,9 @@ def main():
10081043
write_dockerfiles(SUPPORT, BUILD)
10091044
elif action == "makefiles":
10101045
targets = get_targets(TARGETS_CONFIG)
1011-
write_triples_makefiles(targets, BUILD, SUPPORT)
1046+
write_triples_makefiles(targets, BUILD, SUPPORT, downloads=downloads)
10121047
write_target_settings(targets, BUILD / "targets")
1013-
write_package_versions(BUILD / "versions")
1048+
write_package_versions(BUILD / "versions", downloads=downloads)
10141049

10151050
# Override the DOWNLOADS package entry for CPython for the local build
10161051
if python_source:
@@ -1056,9 +1091,9 @@ def main():
10561091
target_triple=target_triple,
10571092
optimizations=optimizations,
10581093
dest_archive=dest_archive,
1059-
downloads=downloads,
10601094
tools_path="host",
10611095
extra_archives=["m4"],
1096+
downloads=downloads,
10621097
)
10631098

10641099
elif action == "libedit":
@@ -1110,8 +1145,8 @@ def main():
11101145
target_triple=target_triple,
11111146
optimizations=optimizations,
11121147
dest_archive=dest_archive,
1113-
downloads=downloads,
11141148
tools_path=tools_path,
1149+
downloads=downloads,
11151150
)
11161151

11171152
elif action == "libX11":
@@ -1243,9 +1278,9 @@ def main():
12431278
target_triple=target_triple,
12441279
optimizations=optimizations,
12451280
dest_archive=dest_archive,
1246-
downloads=downloads,
12471281
version=action.split("-")[1],
12481282
python_source=python_source,
1283+
downloads=downloads,
12491284
)
12501285

12511286
else:

0 commit comments

Comments
 (0)