From 963f910a57ea2ef79e0be717e671224a59d639a9 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Tue, 18 Aug 2026 16:22:07 -0700 Subject: [PATCH 1/3] Don't leak out exceptions when running Platforms/WASI --- Platforms/WASI/_build.py | 17 +++++++- Platforms/WASI/_package.py | 84 +++++++++++++++++++++----------------- 2 files changed, 63 insertions(+), 38 deletions(-) diff --git a/Platforms/WASI/_build.py b/Platforms/WASI/_build.py index 66e2ae64e181d70..b609acb8753448b 100644 --- a/Platforms/WASI/_build.py +++ b/Platforms/WASI/_build.py @@ -129,7 +129,22 @@ def call(command, *, context=None, quiet=False, **kwargs): stderr = subprocess.STDOUT _shared.log("📝", f"Logging output to {stdout.name} (--quiet)...") - subprocess.check_call(command, **kwargs, stdout=stdout, stderr=stderr) + try: + subprocess.check_call(command, **kwargs, stdout=stdout, stderr=stderr) + except subprocess.CalledProcessError as error: + if quiet: + _shared.log( + "❌", + f"Exit code {error.returncode}" + ) + separator() + with open(stdout.name, "r", encoding="utf-8") as file: + lines = file.readlines() + # Inefficient, but the log shouldn't be dramatically large. + print("".join(lines[-10:]), end="") + if not lines[-1].endswith("\n"): + print() + sys.exit(error.returncode) @subdir("build_python_path", clean_ok=True) diff --git a/Platforms/WASI/_package.py b/Platforms/WASI/_package.py index 37119799c233a23..d1d43e5da2843c1 100644 --- a/Platforms/WASI/_package.py +++ b/Platforms/WASI/_package.py @@ -4,6 +4,7 @@ "pathlib", "shutil", "subprocess", + "sys", "_shared", ] @@ -12,6 +13,7 @@ import pathlib import shutil import subprocess +import sys import _shared @@ -376,45 +378,53 @@ def archive(context): int(source_date_epoch), datetime.UTC ).strftime(mtime_format) else: - mtime = subprocess.run( + try: + mtime = subprocess.run( + [ + "git", + "log", + "-1", + "--format=tformat:%cd", + f"--date=format:{mtime_format}", + os.fsdecode(context.checkout), + ], + env={"TZ": "UTC0"}, + capture_output=True, + text=True, + check=True, + ).stdout.strip() + except subprocess.CalledProcessError as error: + print(error.output) + sys.exit(error.returncode) + + try: + subprocess.run( [ - "git", - "log", - "-1", - "--format=tformat:%cd", - f"--date=format:{mtime_format}", - os.fsdecode(context.checkout), + "tar", + "-c", + "-f", + os.fsdecode(file_path), + "--sort=name", + "--mtime", + mtime, + "--clamp-mtime", + "--owner=0", + "--group=0", + "--numeric-owner", + "--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime", + "--mode=go+u,go-w", + # Explicitly using `-T` because if you don't compress with threads you can't + # uncompress with them and the size difference is negligible when using + # single-threaded compression. + "--use-compress-program", + "xz -T 0", + to_compress.name, ], - env={"TZ": "UTC0"}, + cwd=to_compress.parent, capture_output=True, text=True, check=True, - ).stdout.strip() - - subprocess.run( - [ - "tar", - "-c", - "-f", - os.fsdecode(file_path), - "--sort=name", - "--mtime", - mtime, - "--clamp-mtime", - "--owner=0", - "--group=0", - "--numeric-owner", - "--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime", - "--mode=go+u,go-w", - # Explicitly using `-T` because if you don't compress with threads you can't - # uncompress with them and the size difference is negligible when using - # single-threaded compression. - "--use-compress-program", - "xz -T 0", - to_compress.name, - ], - cwd=to_compress.parent, - capture_output=True, - text=True, - check=True, - ) + ) + except subprocess.CalledProcessError as error: + print(error.output) + sys.exit(error.returncode) From ddb9a3aec48dbf4bc2f887b54db8b1bb4028338d Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Tue, 18 Aug 2026 16:24:30 -0700 Subject: [PATCH 2/3] `ruff format` --- Platforms/WASI/_build.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Platforms/WASI/_build.py b/Platforms/WASI/_build.py index b609acb8753448b..b522c87c58b81c0 100644 --- a/Platforms/WASI/_build.py +++ b/Platforms/WASI/_build.py @@ -133,10 +133,7 @@ def call(command, *, context=None, quiet=False, **kwargs): subprocess.check_call(command, **kwargs, stdout=stdout, stderr=stderr) except subprocess.CalledProcessError as error: if quiet: - _shared.log( - "❌", - f"Exit code {error.returncode}" - ) + _shared.log("❌", f"Exit code {error.returncode}") separator() with open(stdout.name, "r", encoding="utf-8") as file: lines = file.readlines() From d3ebc46edf75d42873be6e5bc71b4bcec4fe1f94 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Wed, 19 Aug 2026 12:05:13 -0700 Subject: [PATCH 3/3] `ruff check` --- Platforms/WASI/_build.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Platforms/WASI/_build.py b/Platforms/WASI/_build.py index b522c87c58b81c0..fff7e3f9f8cdada 100644 --- a/Platforms/WASI/_build.py +++ b/Platforms/WASI/_build.py @@ -135,7 +135,7 @@ def call(command, *, context=None, quiet=False, **kwargs): if quiet: _shared.log("❌", f"Exit code {error.returncode}") separator() - with open(stdout.name, "r", encoding="utf-8") as file: + with open(stdout.name, encoding="utf-8") as file: lines = file.readlines() # Inefficient, but the log shouldn't be dramatically large. print("".join(lines[-10:]), end="") @@ -175,8 +175,7 @@ def make_build_python(context, _working_dir): cmd = [ binary, "-c", - "import sys; " - "print(f'{sys.version_info.major}.{sys.version_info.minor}')", + "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')", ] version = subprocess.check_output(cmd, encoding="utf-8").strip()