Skip to content

Commit 86a6afd

Browse files
committed
Use keyword
1 parent ee2e4c3 commit 86a6afd

File tree

4 files changed

+147
-84
lines changed

4 files changed

+147
-84
lines changed

cpython-unix/build.py

+78-42
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,14 +234,16 @@ 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:
246+
245247
if settings.get("needs_toolchain"):
246248
build_env.install_toolchain(
247249
BUILD,
@@ -250,10 +252,11 @@ def simple_build(
250252
binutils=install_binutils(host_platform),
251253
clang=True,
252254
musl="musl" in target_triple,
255+
downloads=downloads,
253256
)
254257

255258
for a in extra_archives or []:
256-
build_env.install_artifact_archive(BUILD, a, target_triple, optimizations)
259+
build_env.install_artifact_archive(BUILD, a, target_triple, optimizations, downloads=downloads)
257260

258261
build_env.copy_file(archive)
259262
build_env.copy_file(SUPPORT / ("build-%s.sh" % entry))
@@ -275,9 +278,9 @@ def simple_build(
275278
build_env.get_tools_archive(dest_archive, tools_path)
276279

277280

278-
def build_binutils(client, image, host_platform, downloads):
281+
def build_binutils(client, image, host_platform, *, downloads: Downloads):
279282
"""Build binutils in the Docker image."""
280-
archive = download_entry("binutils", DOWNLOADS_PATH, downloads)
283+
archive = download_entry("binutils", DOWNLOADS_PATH, downloads=downloads)
281284

282285
with build_environment(client, image) as build_env:
283286
install_sccache(build_env)
@@ -295,13 +298,18 @@ def build_binutils(client, image, host_platform, downloads):
295298
)
296299

297300
build_env.get_tools_archive(
298-
toolchain_archive_path("binutils", host_platform, downloads), "host"
301+
toolchain_archive_path(
302+
"binutils",
303+
host_platform,
304+
downloads=downloads,
305+
),
306+
"host",
299307
)
300308

301309

302-
def materialize_clang(host_platform: str, target_triple: str, downloads):
310+
def materialize_clang(host_platform: str, target_triple: str, *, downloads: Downloads):
303311
entry = clang_toolchain(host_platform, target_triple)
304-
tar_zst = download_entry(entry, DOWNLOADS_PATH, downloads)
312+
tar_zst = download_entry(entry, DOWNLOADS_PATH, downloads=downloads)
305313
local_filename = "%s-%s-%s.tar" % (
306314
entry,
307315
downloads[entry]["version"],
@@ -315,12 +323,24 @@ def materialize_clang(host_platform: str, target_triple: str, downloads):
315323
dctx.copy_stream(ifh, ofh)
316324

317325

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

321336
with build_environment(client, image) as build_env:
322337
build_env.install_toolchain(
323-
BUILD, host_platform, target_triple, binutils=True, clang=True
338+
BUILD,
339+
host_platform,
340+
target_triple,
341+
binutils=True,
342+
clang=True,
343+
downloads=downloads,
324344
)
325345
build_env.copy_file(musl_archive)
326346
build_env.copy_file(SUPPORT / "build-musl.sh")
@@ -333,7 +353,12 @@ def build_musl(client, image, host_platform: str, target_triple: str, downloads)
333353
build_env.run("build-musl.sh", environment=env)
334354

335355
build_env.get_tools_archive(
336-
toolchain_archive_path("musl", host_platform), "host"
356+
toolchain_archive_path(
357+
"musl",
358+
host_platform,
359+
downloads=downloads,
360+
),
361+
"host",
337362
)
338363

339364

@@ -345,9 +370,10 @@ def build_libedit(
345370
target_triple,
346371
optimizations,
347372
dest_archive,
373+
*,
348374
downloads: Downloads,
349375
):
350-
libedit_archive = download_entry("libedit", DOWNLOADS_PATH, downloads)
376+
libedit_archive = download_entry("libedit", DOWNLOADS_PATH, downloads=downloads)
351377

352378
with build_environment(client, image) as build_env:
353379
if settings.get("needs_toolchain"):
@@ -358,10 +384,11 @@ def build_libedit(
358384
binutils=install_binutils(host_platform),
359385
clang=True,
360386
musl="musl" in target_triple,
387+
downloads=downloads,
361388
)
362389

363390
build_env.install_artifact_archive(
364-
BUILD, "ncurses", target_triple, optimizations
391+
BUILD, "ncurses", target_triple, optimizations, downloads=downloads
365392
)
366393
build_env.copy_file(libedit_archive)
367394
build_env.copy_file(SUPPORT / "build-libedit.sh")
@@ -384,11 +411,12 @@ def build_tix(
384411
target_triple,
385412
optimizations,
386413
dest_archive,
414+
*,
387415
downloads: Downloads,
388416
):
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)
417+
tcl_archive = download_entry("tcl", DOWNLOADS_PATH, downloads=downloads)
418+
tk_archive = download_entry("tk", DOWNLOADS_PATH, downloads=downloads)
419+
tix_archive = download_entry("tix", DOWNLOADS_PATH, downloads=downloads)
392420

393421
with build_environment(client, image) as build_env:
394422
if settings.get("needs_toolchain"):
@@ -399,14 +427,15 @@ def build_tix(
399427
binutils=install_binutils(host_platform),
400428
clang=True,
401429
musl="musl" in target_triple,
430+
downloads=downloads,
402431
)
403432

404433
depends = {"tcl", "tk"}
405434
if host_platform != "macos":
406435
depends |= {"libX11", "xorgproto"}
407436

408437
for p in sorted(depends):
409-
build_env.install_artifact_archive(BUILD, p, target_triple, optimizations)
438+
build_env.install_artifact_archive(BUILD, p, target_triple, optimizations, downloads=downloads)
410439

411440
for p in (tcl_archive, tk_archive, tix_archive, SUPPORT / "build-tix.sh"):
412441
build_env.copy_file(p)
@@ -432,10 +461,11 @@ def build_cpython_host(
432461
target_triple: str,
433462
optimizations: str,
434463
dest_archive,
464+
*,
435465
downloads: Downloads,
436466
):
437467
"""Build binutils in the Docker image."""
438-
archive = download_entry(entry, DOWNLOADS_PATH, downloads)
468+
archive = download_entry(entry, DOWNLOADS_PATH, downloads=downloads)
439469

440470
with build_environment(client, image) as build_env:
441471
python_version = downloads[entry]["version"]
@@ -446,6 +476,7 @@ def build_cpython_host(
446476
target_triple,
447477
binutils=install_binutils(host_platform),
448478
clang=True,
479+
downloads=downloads,
449480
)
450481

451482
build_env.copy_file(archive)
@@ -463,7 +494,7 @@ def build_cpython_host(
463494
"m4",
464495
}
465496
for p in sorted(packages):
466-
build_env.install_artifact_archive(BUILD, p, target_triple, optimizations)
497+
build_env.install_artifact_archive(BUILD, p, target_triple, optimizations,downloads=downloads)
467498

468499
env = {
469500
"PYTHON_VERSION": python_version,
@@ -492,12 +523,13 @@ def build_cpython_host(
492523
def python_build_info(
493524
build_env,
494525
version,
495-
platform,
526+
host_platform,
496527
target_triple,
497528
musl,
498529
optimizations,
499530
extensions,
500531
extra_metadata,
532+
*,
501533
downloads: Downloads,
502534
):
503535
"""Obtain build metadata for the Python distribution."""
@@ -508,7 +540,7 @@ def python_build_info(
508540

509541
binary_suffix = ""
510542

511-
if platform == "linux64":
543+
if host_platform == "linux64":
512544
bi["core"]["static_lib"] = (
513545
"install/lib/python{version}/config-{version}{binary_suffix}-x86_64-linux-gnu/libpython{version}{binary_suffix}.a".format(
514546
version=version, binary_suffix=binary_suffix
@@ -522,7 +554,7 @@ def python_build_info(
522554
)
523555

524556
if optimizations in ("lto", "pgo+lto"):
525-
llvm_version = downloads[clang_toolchain(platform, target_triple)][
557+
llvm_version = downloads[clang_toolchain(host_platform, target_triple)][
526558
"version"
527559
]
528560
if "+" in llvm_version:
@@ -531,7 +563,7 @@ def python_build_info(
531563
object_file_format = f"llvm-bitcode:%{llvm_version}"
532564
else:
533565
object_file_format = "elf"
534-
elif platform == "macos":
566+
elif host_platform == "macos":
535567
bi["core"]["static_lib"] = (
536568
"install/lib/python{version}/config-{version}{binary_suffix}-darwin/libpython{version}{binary_suffix}.a".format(
537569
version=version, binary_suffix=binary_suffix
@@ -549,7 +581,7 @@ def python_build_info(
549581
else:
550582
object_file_format = "mach-o"
551583
else:
552-
raise Exception("unsupported platform: %s" % platform)
584+
raise Exception("unsupported platform: %s" % host_platform)
553585

554586
bi["object_file_format"] = object_file_format
555587

@@ -564,9 +596,9 @@ def python_build_info(
564596
if lib.startswith("-l"):
565597
lib = lib[2:]
566598

567-
if platform == "linux64" and lib not in LINUX_ALLOW_SYSTEM_LIBRARIES:
599+
if host_platform == "linux64" and lib not in LINUX_ALLOW_SYSTEM_LIBRARIES:
568600
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))
569-
elif platform == "macos" and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES:
601+
elif host_platform == "macos" and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES:
570602
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))
571603

572604
log("adding core system link library: %s" % lib)
@@ -681,7 +713,7 @@ def python_build_info(
681713
extension_suffix = extra_metadata["python_config_vars"]["EXT_SUFFIX"]
682714
entry["shared_lib"] = "%s/%s%s" % (shared_dir, extension, extension_suffix)
683715

684-
add_licenses_to_extension_entry(entry)
716+
add_licenses_to_extension_entry(entry, downloads=downloads)
685717

686718
bi["extensions"].setdefault(extension, []).append(entry)
687719

@@ -701,17 +733,18 @@ def build_cpython(
701733
host_platform,
702734
target_triple,
703735
optimizations,
704-
downloads: Downloads,
705736
dest_archive,
706737
version=None,
707738
python_source=None,
739+
*,
740+
downloads: Downloads,
708741
):
709742
"""Build CPython in a Docker image'"""
710743
entry_name = "cpython-%s" % version
711744
entry = downloads[entry_name]
712745
if not python_source:
713746
python_version = entry["version"]
714-
python_archive = download_entry(entry_name, DOWNLOADS_PATH, downloads)
747+
python_archive = download_entry(entry_name, DOWNLOADS_PATH, downloads=downloads)
715748
else:
716749
python_version = os.environ["PYBUILD_PYTHON_VERSION"]
717750
python_archive = DOWNLOADS_PATH / ("Python-%s.tar.xz" % python_version)
@@ -721,8 +754,10 @@ def build_cpython(
721754
fh, python_source, path_prefix="Python-%s" % python_version
722755
)
723756

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

727762
ems = extension_modules_config(EXTENSION_MODULES)
728763

@@ -746,6 +781,7 @@ def build_cpython(
746781
binutils=install_binutils(host_platform),
747782
clang=True,
748783
musl="musl" in target_triple,
784+
downloads=downloads,
749785
)
750786

751787
packages = target_needs(TARGETS_CONFIG, target_triple, python_version)
@@ -754,10 +790,10 @@ def build_cpython(
754790
packages.discard("musl")
755791

756792
for p in sorted(packages):
757-
build_env.install_artifact_archive(BUILD, p, target_triple, optimizations)
793+
build_env.install_artifact_archive(BUILD, p, target_triple, optimizations, downloads=downloads)
758794

759795
build_env.install_toolchain_archive(
760-
BUILD, entry_name, host_platform, version=python_version
796+
BUILD, entry_name, host_platform, version=python_version, downloads=downloads
761797
)
762798

763799
for p in (
@@ -1008,9 +1044,9 @@ def main():
10081044
write_dockerfiles(SUPPORT, BUILD)
10091045
elif action == "makefiles":
10101046
targets = get_targets(TARGETS_CONFIG)
1011-
write_triples_makefiles(targets, BUILD, SUPPORT)
1047+
write_triples_makefiles(targets, BUILD, SUPPORT, downloads=downloads)
10121048
write_target_settings(targets, BUILD / "targets")
1013-
write_package_versions(BUILD / "versions")
1049+
write_package_versions(BUILD / "versions", downloads=downloads)
10141050

10151051
# Override the DOWNLOADS package entry for CPython for the local build
10161052
if python_source:
@@ -1056,9 +1092,9 @@ def main():
10561092
target_triple=target_triple,
10571093
optimizations=optimizations,
10581094
dest_archive=dest_archive,
1059-
downloads=downloads,
10601095
tools_path="host",
10611096
extra_archives=["m4"],
1097+
downloads=downloads,
10621098
)
10631099

10641100
elif action == "libedit":
@@ -1110,8 +1146,8 @@ def main():
11101146
target_triple=target_triple,
11111147
optimizations=optimizations,
11121148
dest_archive=dest_archive,
1113-
downloads=downloads,
11141149
tools_path=tools_path,
1150+
downloads=downloads,
11151151
)
11161152

11171153
elif action == "libX11":
@@ -1243,9 +1279,9 @@ def main():
12431279
target_triple=target_triple,
12441280
optimizations=optimizations,
12451281
dest_archive=dest_archive,
1246-
downloads=downloads,
12471282
version=action.split("-")[1],
12481283
python_source=python_source,
1284+
downloads=downloads,
12491285
)
12501286

12511287
else:

0 commit comments

Comments
 (0)