[3.13] GH-139590: Run ruff format on pre-commit for Tools/wasm (GH-139591) (#139745)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
Savannah Ostrowski 2025-10-08 08:10:25 -07:00 committed by GitHub
parent de84a03099
commit 5a98f85c9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 246 additions and 121 deletions

View file

@ -26,6 +26,10 @@ repos:
name: Run Ruff (format) on Doc/ name: Run Ruff (format) on Doc/
args: [--check] args: [--check]
files: ^Doc/ files: ^Doc/
- id: ruff-format
name: Run Ruff (format) on Tools/wasm/
args: [--check, --config=Tools/wasm/.ruff.toml]
files: ^Tools/wasm/
- repo: https://github.com/psf/black-pre-commit-mirror - repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.1.0 rev: 25.1.0

28
Tools/wasm/.ruff.toml Normal file
View file

@ -0,0 +1,28 @@
extend = "../../.ruff.toml" # Inherit the project-wide settings
[format]
preview = true
docstring-code-format = true
[lint]
select = [
"C4", # flake8-comprehensions
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"ISC", # flake8-implicit-str-concat
"LOG", # flake8-logging
"PGH", # pygrep-hooks
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
"RUF100", # Ban unused `# noqa` comments
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
]
ignore = [
"E501", # Line too long
"F541", # f-string without any placeholders
"PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple`
"PYI025", # Use `from collections.abc import Set as AbstractSet`
]

View file

@ -4,6 +4,7 @@
import contextlib import contextlib
import functools import functools
import os import os
try: try:
from os import process_cpu_count as cpu_count from os import process_cpu_count as cpu_count
except ImportError: except ImportError:
@ -37,7 +38,9 @@ def updated_env(updates={}):
# https://reproducible-builds.org/docs/source-date-epoch/ # https://reproducible-builds.org/docs/source-date-epoch/
git_epoch_cmd = ["git", "log", "-1", "--pretty=%ct"] git_epoch_cmd = ["git", "log", "-1", "--pretty=%ct"]
try: try:
epoch = subprocess.check_output(git_epoch_cmd, encoding="utf-8").strip() epoch = subprocess.check_output(
git_epoch_cmd, encoding="utf-8"
).strip()
env_defaults["SOURCE_DATE_EPOCH"] = epoch env_defaults["SOURCE_DATE_EPOCH"] = epoch
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
pass # Might be building from a tarball. pass # Might be building from a tarball.
@ -58,6 +61,7 @@ def updated_env(updates={}):
def subdir(working_dir, *, clean_ok=False): def subdir(working_dir, *, clean_ok=False):
"""Decorator to change to a working directory.""" """Decorator to change to a working directory."""
def decorator(func): def decorator(func):
@functools.wraps(func) @functools.wraps(func)
def wrapper(context): def wrapper(context):
@ -66,16 +70,20 @@ def wrapper(context):
if callable(working_dir): if callable(working_dir):
working_dir = working_dir(context) working_dir = working_dir(context)
try: try:
tput_output = subprocess.check_output(["tput", "cols"], tput_output = subprocess.check_output(
encoding="utf-8") ["tput", "cols"], encoding="utf-8"
)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
terminal_width = 80 terminal_width = 80
else: else:
terminal_width = int(tput_output.strip()) terminal_width = int(tput_output.strip())
print("" * terminal_width) print("" * terminal_width)
print("📁", working_dir) print("📁", working_dir)
if (clean_ok and getattr(context, "clean", False) and if (
working_dir.exists()): clean_ok
and getattr(context, "clean", False)
and working_dir.exists()
):
print(f"🚮 Deleting directory (--clean)...") print(f"🚮 Deleting directory (--clean)...")
shutil.rmtree(working_dir) shutil.rmtree(working_dir)
@ -99,10 +107,13 @@ def call(command, *, quiet, **kwargs):
stdout = None stdout = None
stderr = None stderr = None
else: else:
stdout = tempfile.NamedTemporaryFile("w", encoding="utf-8", stdout = tempfile.NamedTemporaryFile(
delete=False, "w",
prefix="cpython-wasi-", encoding="utf-8",
suffix=".log") delete=False,
prefix="cpython-wasi-",
suffix=".log",
)
stderr = subprocess.STDOUT stderr = subprocess.STDOUT
print(f"📝 Logging output to {stdout.name} (--quiet)...") print(f"📝 Logging output to {stdout.name} (--quiet)...")
@ -121,8 +132,9 @@ def build_python_path():
if not binary.is_file(): if not binary.is_file():
binary = binary.with_suffix(".exe") binary = binary.with_suffix(".exe")
if not binary.is_file(): if not binary.is_file():
raise FileNotFoundError("Unable to find `python(.exe)` in " raise FileNotFoundError(
f"{BUILD_DIR}") f"Unable to find `python(.exe)` in {BUILD_DIR}"
)
return binary return binary
@ -136,7 +148,7 @@ def configure_build_python(context, working_dir):
print(f"📝 Touching {LOCAL_SETUP} ...") print(f"📝 Touching {LOCAL_SETUP} ...")
LOCAL_SETUP.write_bytes(LOCAL_SETUP_MARKER) LOCAL_SETUP.write_bytes(LOCAL_SETUP_MARKER)
configure = [os.path.relpath(CHECKOUT / 'configure', working_dir)] configure = [os.path.relpath(CHECKOUT / "configure", working_dir)]
if context.args: if context.args:
configure.extend(context.args) configure.extend(context.args)
@ -146,13 +158,15 @@ def configure_build_python(context, working_dir):
@subdir(BUILD_DIR) @subdir(BUILD_DIR)
def make_build_python(context, working_dir): def make_build_python(context, working_dir):
"""Make/build the build Python.""" """Make/build the build Python."""
call(["make", "--jobs", str(cpu_count()), "all"], call(["make", "--jobs", str(cpu_count()), "all"], quiet=context.quiet)
quiet=context.quiet)
binary = build_python_path() binary = build_python_path()
cmd = [binary, "-c", cmd = [
"import sys; " binary,
"print(f'{sys.version_info.major}.{sys.version_info.minor}')"] "-c",
"import sys; "
"print(f'{sys.version_info.major}.{sys.version_info.minor}')",
]
version = subprocess.check_output(cmd, encoding="utf-8").strip() version = subprocess.check_output(cmd, encoding="utf-8").strip()
print(f"🎉 {binary} {version}") print(f"🎉 {binary} {version}")
@ -170,8 +184,13 @@ def wasi_sdk_env(context):
"""Calculate environment variables for building with wasi-sdk.""" """Calculate environment variables for building with wasi-sdk."""
wasi_sdk_path = context.wasi_sdk_path wasi_sdk_path = context.wasi_sdk_path
sysroot = wasi_sdk_path / "share" / "wasi-sysroot" sysroot = wasi_sdk_path / "share" / "wasi-sysroot"
env = {"CC": "clang", "CPP": "clang-cpp", "CXX": "clang++", env = {
"AR": "llvm-ar", "RANLIB": "ranlib"} "CC": "clang",
"CPP": "clang-cpp",
"CXX": "clang++",
"AR": "llvm-ar",
"RANLIB": "ranlib",
}
for env_var, binary_name in list(env.items()): for env_var, binary_name in list(env.items()):
env[env_var] = os.fsdecode(wasi_sdk_path / "bin" / binary_name) env[env_var] = os.fsdecode(wasi_sdk_path / "bin" / binary_name)
@ -182,16 +201,20 @@ def wasi_sdk_env(context):
env["PKG_CONFIG_PATH"] = "" env["PKG_CONFIG_PATH"] = ""
env["PKG_CONFIG_LIBDIR"] = os.pathsep.join( env["PKG_CONFIG_LIBDIR"] = os.pathsep.join(
map(os.fsdecode, map(
[sysroot / "lib" / "pkgconfig", os.fsdecode,
sysroot / "share" / "pkgconfig"])) [sysroot / "lib" / "pkgconfig", sysroot / "share" / "pkgconfig"],
)
)
env["PKG_CONFIG_SYSROOT_DIR"] = os.fsdecode(sysroot) env["PKG_CONFIG_SYSROOT_DIR"] = os.fsdecode(sysroot)
env["WASI_SDK_PATH"] = os.fsdecode(wasi_sdk_path) env["WASI_SDK_PATH"] = os.fsdecode(wasi_sdk_path)
env["WASI_SYSROOT"] = os.fsdecode(sysroot) env["WASI_SYSROOT"] = os.fsdecode(sysroot)
env["PATH"] = os.pathsep.join([os.fsdecode(wasi_sdk_path / "bin"), env["PATH"] = os.pathsep.join([
os.environ["PATH"]]) os.fsdecode(wasi_sdk_path / "bin"),
os.environ["PATH"],
])
return env return env
@ -200,18 +223,24 @@ def wasi_sdk_env(context):
def configure_wasi_python(context, working_dir): def configure_wasi_python(context, working_dir):
"""Configure the WASI/host build.""" """Configure the WASI/host build."""
if not context.wasi_sdk_path or not context.wasi_sdk_path.exists(): if not context.wasi_sdk_path or not context.wasi_sdk_path.exists():
raise ValueError("WASI-SDK not found; " raise ValueError(
"download from " "WASI-SDK not found; "
"https://github.com/WebAssembly/wasi-sdk and/or " "download from "
"specify via $WASI_SDK_PATH or --wasi-sdk") "https://github.com/WebAssembly/wasi-sdk and/or "
"specify via $WASI_SDK_PATH or --wasi-sdk"
)
config_site = os.fsdecode(CHECKOUT / "Tools" / "wasm" / "config.site-wasm32-wasi") config_site = os.fsdecode(
CHECKOUT / "Tools" / "wasm" / "config.site-wasm32-wasi"
)
wasi_build_dir = working_dir.relative_to(CHECKOUT) wasi_build_dir = working_dir.relative_to(CHECKOUT)
python_build_dir = BUILD_DIR / "build" python_build_dir = BUILD_DIR / "build"
lib_dirs = list(python_build_dir.glob("lib.*")) lib_dirs = list(python_build_dir.glob("lib.*"))
assert len(lib_dirs) == 1, f"Expected a single lib.* directory in {python_build_dir}" assert len(lib_dirs) == 1, (
f"Expected a single lib.* directory in {python_build_dir}"
)
lib_dir = os.fsdecode(lib_dirs[0]) lib_dir = os.fsdecode(lib_dirs[0])
pydebug = lib_dir.endswith("-pydebug") pydebug = lib_dir.endswith("-pydebug")
python_version = lib_dir.removesuffix("-pydebug").rpartition("-")[-1] python_version = lib_dir.removesuffix("-pydebug").rpartition("-")[-1]
@ -221,36 +250,44 @@ def configure_wasi_python(context, working_dir):
# Use PYTHONPATH to include sysconfig data which must be anchored to the # Use PYTHONPATH to include sysconfig data which must be anchored to the
# WASI guest's `/` directory. # WASI guest's `/` directory.
args = {"GUEST_DIR": "/", args = {
"HOST_DIR": CHECKOUT, "GUEST_DIR": "/",
"ENV_VAR_NAME": "PYTHONPATH", "HOST_DIR": CHECKOUT,
"ENV_VAR_VALUE": f"/{sysconfig_data}", "ENV_VAR_NAME": "PYTHONPATH",
"PYTHON_WASM": working_dir / "python.wasm"} "ENV_VAR_VALUE": f"/{sysconfig_data}",
"PYTHON_WASM": working_dir / "python.wasm",
}
# Check dynamically for wasmtime in case it was specified manually via # Check dynamically for wasmtime in case it was specified manually via
# `--host-runner`. # `--host-runner`.
if WASMTIME_HOST_RUNNER_VAR in context.host_runner: if WASMTIME_HOST_RUNNER_VAR in context.host_runner:
if wasmtime := shutil.which("wasmtime"): if wasmtime := shutil.which("wasmtime"):
args[WASMTIME_VAR_NAME] = wasmtime args[WASMTIME_VAR_NAME] = wasmtime
else: else:
raise FileNotFoundError("wasmtime not found; download from " raise FileNotFoundError(
"https://github.com/bytecodealliance/wasmtime") "wasmtime not found; download from "
"https://github.com/bytecodealliance/wasmtime"
)
host_runner = context.host_runner.format_map(args) host_runner = context.host_runner.format_map(args)
env_additions = {"CONFIG_SITE": config_site, "HOSTRUNNER": host_runner} env_additions = {"CONFIG_SITE": config_site, "HOSTRUNNER": host_runner}
build_python = os.fsdecode(build_python_path()) build_python = os.fsdecode(build_python_path())
# The path to `configure` MUST be relative, else `python.wasm` is unable # The path to `configure` MUST be relative, else `python.wasm` is unable
# to find the stdlib due to Python not recognizing that it's being # to find the stdlib due to Python not recognizing that it's being
# executed from within a checkout. # executed from within a checkout.
configure = [os.path.relpath(CHECKOUT / 'configure', working_dir), configure = [
f"--host={context.host_triple}", os.path.relpath(CHECKOUT / "configure", working_dir),
f"--build={build_platform()}", f"--host={context.host_triple}",
f"--with-build-python={build_python}"] f"--build={build_platform()}",
f"--with-build-python={build_python}",
]
if pydebug: if pydebug:
configure.append("--with-pydebug") configure.append("--with-pydebug")
if context.args: if context.args:
configure.extend(context.args) configure.extend(context.args)
call(configure, call(
env=updated_env(env_additions | wasi_sdk_env(context)), configure,
quiet=context.quiet) env=updated_env(env_additions | wasi_sdk_env(context)),
quiet=context.quiet,
)
python_wasm = working_dir / "python.wasm" python_wasm = working_dir / "python.wasm"
exec_script = working_dir / "python.sh" exec_script = working_dir / "python.sh"
@ -264,9 +301,11 @@ def configure_wasi_python(context, working_dir):
@subdir(lambda context: CROSS_BUILD_DIR / context.host_triple) @subdir(lambda context: CROSS_BUILD_DIR / context.host_triple)
def make_wasi_python(context, working_dir): def make_wasi_python(context, working_dir):
"""Run `make` for the WASI/host build.""" """Run `make` for the WASI/host build."""
call(["make", "--jobs", str(cpu_count()), "all"], call(
env=updated_env(), ["make", "--jobs", str(cpu_count()), "all"],
quiet=context.quiet) env=updated_env(),
quiet=context.quiet,
)
exec_script = working_dir / "python.sh" exec_script = working_dir / "python.sh"
subprocess.check_call([exec_script, "--version"]) subprocess.check_call([exec_script, "--version"])
@ -274,11 +313,16 @@ def make_wasi_python(context, working_dir):
def build_all(context): def build_all(context):
"""Build everything.""" """Build everything."""
steps = [configure_build_python, make_build_python, configure_wasi_python, steps = [
make_wasi_python] configure_build_python,
make_build_python,
configure_wasi_python,
make_wasi_python,
]
for step in steps: for step in steps:
step(context) step(context)
def clean_contents(context): def clean_contents(context):
"""Delete all files created by this script.""" """Delete all files created by this script."""
if CROSS_BUILD_DIR.exists(): if CROSS_BUILD_DIR.exists():
@ -292,74 +336,109 @@ def clean_contents(context):
def main(): def main():
default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run " default_host_runner = (
# Make sure the stack size will work for a pydebug f"{WASMTIME_HOST_RUNNER_VAR} run "
# build. # Make sure the stack size will work for a pydebug
# The 8388608 value comes from `ulimit -s` under Linux # build.
# which equates to 8291 KiB. # The 8388608 value comes from `ulimit -s` under Linux
"--wasm max-wasm-stack=8388608 " # which equates to 8291 KiB.
# Use WASI 0.2 primitives. "--wasm max-wasm-stack=8388608 "
"--wasi preview2 " # Use WASI 0.2 primitives.
# Enable thread support; causes use of preview1. "--wasi preview2 "
#"--wasm threads=y --wasi threads=y " # Enable thread support; causes use of preview1.
# Map the checkout to / to load the stdlib from /Lib. # "--wasm threads=y --wasi threads=y "
"--dir {HOST_DIR}::{GUEST_DIR} " # Map the checkout to / to load the stdlib from /Lib.
# Set PYTHONPATH to the sysconfig data. "--dir {HOST_DIR}::{GUEST_DIR} "
"--env {ENV_VAR_NAME}={ENV_VAR_VALUE}") # Set PYTHONPATH to the sysconfig data.
"--env {ENV_VAR_NAME}={ENV_VAR_VALUE}"
)
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
subcommands = parser.add_subparsers(dest="subcommand") subcommands = parser.add_subparsers(dest="subcommand")
build = subcommands.add_parser("build", help="Build everything") build = subcommands.add_parser("build", help="Build everything")
configure_build = subcommands.add_parser("configure-build-python", configure_build = subcommands.add_parser(
help="Run `configure` for the " "configure-build-python", help="Run `configure` for the build Python"
"build Python") )
make_build = subcommands.add_parser("make-build-python", make_build = subcommands.add_parser(
help="Run `make` for the build Python") "make-build-python", help="Run `make` for the build Python"
configure_host = subcommands.add_parser("configure-host", )
help="Run `configure` for the " configure_host = subcommands.add_parser(
"host/WASI (pydebug builds " "configure-host",
"are inferred from the build " help="Run `configure` for the "
"Python)") "host/WASI (pydebug builds "
make_host = subcommands.add_parser("make-host", "are inferred from the build "
help="Run `make` for the host/WASI") "Python)",
clean = subcommands.add_parser("clean", help="Delete files and directories " )
"created by this script") make_host = subcommands.add_parser(
for subcommand in build, configure_build, make_build, configure_host, make_host: "make-host", help="Run `make` for the host/WASI"
subcommand.add_argument("--quiet", action="store_true", default=False, )
dest="quiet", clean = subcommands.add_parser(
help="Redirect output from subprocesses to a log file") "clean", help="Delete files and directories created by this script"
)
for subcommand in (
build,
configure_build,
make_build,
configure_host,
make_host,
):
subcommand.add_argument(
"--quiet",
action="store_true",
default=False,
dest="quiet",
help="Redirect output from subprocesses to a log file",
)
for subcommand in configure_build, configure_host: for subcommand in configure_build, configure_host:
subcommand.add_argument("--clean", action="store_true", default=False, subcommand.add_argument(
dest="clean", "--clean",
help="Delete any relevant directories before building") action="store_true",
default=False,
dest="clean",
help="Delete any relevant directories before building",
)
for subcommand in build, configure_build, configure_host: for subcommand in build, configure_build, configure_host:
subcommand.add_argument("args", nargs="*", subcommand.add_argument(
help="Extra arguments to pass to `configure`") "args", nargs="*", help="Extra arguments to pass to `configure`"
)
for subcommand in build, configure_host: for subcommand in build, configure_host:
subcommand.add_argument("--wasi-sdk", type=pathlib.Path, subcommand.add_argument(
dest="wasi_sdk_path", "--wasi-sdk",
default=find_wasi_sdk(), type=pathlib.Path,
help="Path to wasi-sdk; defaults to " dest="wasi_sdk_path",
"$WASI_SDK_PATH or /opt/wasi-sdk") default=find_wasi_sdk(),
subcommand.add_argument("--host-runner", action="store", help="Path to wasi-sdk; defaults to "
default=default_host_runner, dest="host_runner", "$WASI_SDK_PATH or /opt/wasi-sdk",
help="Command template for running the WASI host " )
"(default designed for wasmtime 14 or newer: " subcommand.add_argument(
f"`{default_host_runner}`)") "--host-runner",
action="store",
default=default_host_runner,
dest="host_runner",
help="Command template for running the WASI host "
"(default designed for wasmtime 14 or newer: "
f"`{default_host_runner}`)",
)
for subcommand in build, configure_host, make_host: for subcommand in build, configure_host, make_host:
subcommand.add_argument("--host-triple", action="store", default="wasm32-wasip1", subcommand.add_argument(
help="The target triple for the WASI host build") "--host-triple",
action="store",
default="wasm32-wasip1",
help="The target triple for the WASI host build",
)
context = parser.parse_args() context = parser.parse_args()
dispatch = {"configure-build-python": configure_build_python, dispatch = {
"make-build-python": make_build_python, "configure-build-python": configure_build_python,
"configure-host": configure_wasi_python, "make-build-python": make_build_python,
"make-host": make_wasi_python, "configure-host": configure_wasi_python,
"build": build_all, "make-host": make_wasi_python,
"clean": clean_contents} "build": build_all,
"clean": clean_contents,
}
dispatch[context.subcommand](context) dispatch[context.subcommand](context)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -21,6 +21,7 @@
./Tools/wasm/wasm_builder.py --clean build build ./Tools/wasm/wasm_builder.py --clean build build
""" """
import argparse import argparse
import enum import enum
import dataclasses import dataclasses
@ -67,7 +68,9 @@
# path to Emscripten SDK config file. # path to Emscripten SDK config file.
# auto-detect's EMSDK in /opt/emsdk without ". emsdk_env.sh". # auto-detect's EMSDK in /opt/emsdk without ". emsdk_env.sh".
EM_CONFIG = pathlib.Path(os.environ.setdefault("EM_CONFIG", "/opt/emsdk/.emscripten")) EM_CONFIG = pathlib.Path(
os.environ.setdefault("EM_CONFIG", "/opt/emsdk/.emscripten")
)
EMSDK_MIN_VERSION = (3, 1, 19) EMSDK_MIN_VERSION = (3, 1, 19)
EMSDK_BROKEN_VERSION = { EMSDK_BROKEN_VERSION = {
(3, 1, 14): "https://github.com/emscripten-core/emscripten/issues/17338", (3, 1, 14): "https://github.com/emscripten-core/emscripten/issues/17338",
@ -261,8 +264,7 @@ def _check_emscripten() -> None:
# git / upstream / tot-upstream installation # git / upstream / tot-upstream installation
version = version[:-4] version = version[:-4]
version_tuple = cast( version_tuple = cast(
Tuple[int, int, int], Tuple[int, int, int], tuple(int(v) for v in version.split("."))
tuple(int(v) for v in version.split("."))
) )
if version_tuple < EMSDK_MIN_VERSION: if version_tuple < EMSDK_MIN_VERSION:
raise ConditionError( raise ConditionError(
@ -518,7 +520,7 @@ def make_cmd(self) -> List[str]:
def getenv(self) -> Dict[str, Any]: def getenv(self) -> Dict[str, Any]:
"""Generate environ dict for platform""" """Generate environ dict for platform"""
env = os.environ.copy() env = os.environ.copy()
if hasattr(os, 'process_cpu_count'): if hasattr(os, "process_cpu_count"):
cpu_count = os.process_cpu_count() cpu_count = os.process_cpu_count()
else: else:
cpu_count = os.cpu_count() cpu_count = os.cpu_count()
@ -596,7 +598,9 @@ def run_py(self, *args: str) -> int:
"""Run Python with hostrunner""" """Run Python with hostrunner"""
self._check_execute() self._check_execute()
return self.run_make( return self.run_make(
"--eval", f"run: all; $(HOSTRUNNER) ./$(PYTHON) {shlex.join(args)}", "run" "--eval",
f"run: all; $(HOSTRUNNER) ./$(PYTHON) {shlex.join(args)}",
"run",
) )
def run_browser(self, bind: str = "127.0.0.1", port: int = 8000) -> None: def run_browser(self, bind: str = "127.0.0.1", port: int = 8000) -> None:
@ -666,9 +670,12 @@ def build_emports(self, force: bool = False) -> None:
# Pre-build libbz2, libsqlite3, libz, and some system libs. # Pre-build libbz2, libsqlite3, libz, and some system libs.
ports_cmd.extend(["-sUSE_ZLIB", "-sUSE_BZIP2", "-sUSE_SQLITE3"]) ports_cmd.extend(["-sUSE_ZLIB", "-sUSE_BZIP2", "-sUSE_SQLITE3"])
# Multi-threaded sqlite3 has different suffix # Multi-threaded sqlite3 has different suffix
embuilder_cmd.extend( embuilder_cmd.extend([
["build", "bzip2", "sqlite3-mt" if self.pthreads else "sqlite3", "zlib"] "build",
) "bzip2",
"sqlite3-mt" if self.pthreads else "sqlite3",
"zlib",
])
self._run_cmd(embuilder_cmd, cwd=SRCDIR) self._run_cmd(embuilder_cmd, cwd=SRCDIR)
@ -817,7 +824,9 @@ def build_emports(self, force: bool = False) -> None:
# Don't list broken and experimental variants in help # Don't list broken and experimental variants in help
platforms_choices = list(p.name for p in _profiles) + ["cleanall"] platforms_choices = list(p.name for p in _profiles) + ["cleanall"]
platforms_help = list(p.name for p in _profiles if p.support_level) + ["cleanall"] platforms_help = list(p.name for p in _profiles if p.support_level) + [
"cleanall"
]
parser.add_argument( parser.add_argument(
"platform", "platform",
metavar="PLATFORM", metavar="PLATFORM",

View file

@ -6,20 +6,24 @@
description="Start a local webserver with a Python terminal." description="Start a local webserver with a Python terminal."
) )
parser.add_argument( parser.add_argument(
"--port", type=int, default=8000, help="port for the http server to listen on" "--port",
type=int,
default=8000,
help="port for the http server to listen on",
) )
parser.add_argument( parser.add_argument(
"--bind", type=str, default="127.0.0.1", help="Bind address (empty for all)" "--bind",
type=str,
default="127.0.0.1",
help="Bind address (empty for all)",
) )
class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler): class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler):
extensions_map = server.SimpleHTTPRequestHandler.extensions_map.copy() extensions_map = server.SimpleHTTPRequestHandler.extensions_map.copy()
extensions_map.update( extensions_map.update({
{ ".wasm": "application/wasm",
".wasm": "application/wasm", })
}
)
def end_headers(self) -> None: def end_headers(self) -> None:
self.send_my_headers() self.send_my_headers()
@ -42,5 +46,6 @@ def main() -> None:
bind=args.bind, bind=args.bind,
) )
if __name__ == "__main__": if __name__ == "__main__":
main() main()