Skip to content

Commit c378442

Browse files
committed
Lint fixes
1 parent b6a2be3 commit c378442

File tree

1 file changed

+39
-45
lines changed

1 file changed

+39
-45
lines changed

Tools/wasm/wasm_build.py

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"""
2424

2525
import argparse
26-
import enum
2726
import dataclasses
27+
import enum
2828
import logging
2929
import os
3030
import pathlib
@@ -39,18 +39,12 @@
3939
import time
4040
import warnings
4141
import webbrowser
42+
from collections.abc import Callable, Iterable
4243

4344
# for Python 3.8
4445
from typing import (
45-
cast,
4646
Any,
47-
Callable,
48-
Dict,
49-
Iterable,
50-
List,
51-
Optional,
52-
Tuple,
53-
Union,
47+
cast,
5448
)
5549

5650
logger = logging.getLogger("wasm_build")
@@ -122,7 +116,7 @@
122116

123117
def parse_emconfig(
124118
emconfig: pathlib.Path = EM_CONFIG,
125-
) -> Tuple[pathlib.Path, pathlib.Path]:
119+
) -> tuple[pathlib.Path, pathlib.Path]:
126120
"""Parse EM_CONFIG file and lookup EMSCRIPTEN_ROOT and NODE_JS.
127121
128122
The ".emscripten" config file is a Python snippet that uses "EM_CONFIG"
@@ -134,7 +128,7 @@ def parse_emconfig(
134128
with open(emconfig, encoding="utf-8") as f:
135129
code = f.read()
136130
# EM_CONFIG file is a Python snippet
137-
local: Dict[str, Any] = {}
131+
local: dict[str, Any] = {}
138132
exec(code, globals(), local)
139133
emscripten_root = pathlib.Path(local["EMSCRIPTEN_ROOT"])
140134
node_js = pathlib.Path(local["NODE_JS"])
@@ -192,16 +186,16 @@ class Platform:
192186

193187
name: str
194188
pythonexe: str
195-
config_site: Optional[pathlib.PurePath]
196-
configure_wrapper: Optional[pathlib.Path]
197-
make_wrapper: Optional[pathlib.PurePath]
198-
environ: Dict[str, Any]
189+
config_site: pathlib.PurePath | None
190+
configure_wrapper: pathlib.Path | None
191+
make_wrapper: pathlib.PurePath | None
192+
environ: dict[str, Any]
199193
check: Callable[[], None]
200194
# Used for build_emports().
201-
ports: Optional[pathlib.PurePath]
202-
cc: Optional[pathlib.PurePath]
195+
ports: pathlib.PurePath | None
196+
cc: pathlib.PurePath | None
203197

204-
def getenv(self, profile: "BuildProfile") -> Dict[str, Any]:
198+
def getenv(self, profile: "BuildProfile") -> dict[str, Any]:
205199
return self.environ.copy()
206200

207201

@@ -264,7 +258,7 @@ def _check_emscripten() -> None:
264258
# git / upstream / tot-upstream installation
265259
version = version[:-4]
266260
version_tuple = cast(
267-
Tuple[int, int, int], tuple(int(v) for v in version.split("."))
261+
tuple[int, int, int], tuple(int(v) for v in version.split("."))
268262
)
269263
if version_tuple < EMSDK_MIN_VERSION:
270264
raise ConditionError(
@@ -388,7 +382,7 @@ def get_extra_paths(self) -> Iterable[pathlib.PurePath]:
388382
return []
389383

390384
@property
391-
def emport_args(self) -> List[str]:
385+
def emport_args(self) -> list[str]:
392386
"""Host-specific port args (Emscripten)."""
393387
cls = type(self)
394388
if self is cls.wasm64_emscripten:
@@ -399,7 +393,7 @@ def emport_args(self) -> List[str]:
399393
return []
400394

401395
@property
402-
def embuilder_args(self) -> List[str]:
396+
def embuilder_args(self) -> list[str]:
403397
"""Host-specific embuilder args (Emscripten)."""
404398
cls = type(self)
405399
if self is cls.wasm64_emscripten:
@@ -422,7 +416,7 @@ def is_browser(self) -> bool:
422416
return self in {cls.browser, cls.browser_debug}
423417

424418
@property
425-
def emport_args(self) -> List[str]:
419+
def emport_args(self) -> list[str]:
426420
"""Target-specific port args."""
427421
cls = type(self)
428422
if self in {cls.browser_debug, cls.node_debug}:
@@ -448,9 +442,9 @@ class BuildProfile:
448442
name: str
449443
support_level: SupportLevel
450444
host: Host
451-
target: Union[EmscriptenTarget, None] = None
452-
dynamic_linking: Union[bool, None] = None
453-
pthreads: Union[bool, None] = None
445+
target: EmscriptenTarget | None = None
446+
dynamic_linking: bool | None = None
447+
pthreads: bool | None = None
454448
default_testopts: str = "-j2"
455449

456450
@property
@@ -474,7 +468,7 @@ def makefile(self) -> pathlib.Path:
474468
return self.builddir / "Makefile"
475469

476470
@property
477-
def configure_cmd(self) -> List[str]:
471+
def configure_cmd(self) -> list[str]:
478472
"""Generate configure command"""
479473
# use relative path, so WASI tests can find lib prefix.
480474
# pathlib.Path.relative_to() does not work here.
@@ -509,15 +503,15 @@ def configure_cmd(self) -> List[str]:
509503
return cmd
510504

511505
@property
512-
def make_cmd(self) -> List[str]:
506+
def make_cmd(self) -> list[str]:
513507
"""Generate make command"""
514508
cmd = ["make"]
515509
platform = self.host.platform
516510
if platform.make_wrapper:
517511
cmd.insert(0, os.fspath(platform.make_wrapper))
518512
return cmd
519513

520-
def getenv(self) -> Dict[str, Any]:
514+
def getenv(self) -> dict[str, Any]:
521515
"""Generate environ dict for platform"""
522516
env = os.environ.copy()
523517
if hasattr(os, "process_cpu_count"):
@@ -531,7 +525,7 @@ def getenv(self) -> Dict[str, Any]:
531525
env.pop(key, None)
532526
elif key == "PATH":
533527
# list of path items, prefix with extra paths
534-
new_path: List[pathlib.PurePath] = []
528+
new_path: list[pathlib.PurePath] = []
535529
new_path.extend(self.host.get_extra_paths())
536530
new_path.extend(value)
537531
env[key] = os.pathsep.join(os.fspath(p) for p in new_path)
@@ -549,7 +543,7 @@ def _run_cmd(
549543
self,
550544
cmd: Iterable[str],
551545
args: Iterable[str] = (),
552-
cwd: Optional[pathlib.Path] = None,
546+
cwd: pathlib.Path | None = None,
553547
) -> int:
554548
cmd = list(cmd)
555549
cmd.extend(args)
@@ -587,7 +581,7 @@ def run_pythoninfo(self, *args: str) -> int:
587581
self._check_execute()
588582
return self.run_make("pythoninfo", *args)
589583

590-
def run_test(self, target: str, testopts: Optional[str] = None) -> int:
584+
def run_test(self, target: str, testopts: str | None = None) -> int:
591585
"""Run buildbottests"""
592586
self._check_execute()
593587
if testopts is None:
@@ -823,8 +817,8 @@ def build_emports(self, force: bool = False) -> None:
823817
)
824818

825819
# Don't list broken and experimental variants in help
826-
platforms_choices = list(p.name for p in _profiles) + ["cleanall"]
827-
platforms_help = list(p.name for p in _profiles if p.support_level) + [
820+
platforms_choices = [p.name for p in _profiles] + ["cleanall"]
821+
platforms_help = [p.name for p in _profiles if p.support_level] + [
828822
"cleanall"
829823
]
830824
parser.add_argument(
@@ -834,18 +828,18 @@ def build_emports(self, force: bool = False) -> None:
834828
choices=platforms_choices,
835829
)
836830

837-
ops = dict(
838-
build="auto build (build 'build' Python, emports, configure, compile)",
839-
configure="run ./configure",
840-
compile="run 'make all'",
841-
pythoninfo="run 'make pythoninfo'",
842-
test="run 'make buildbottest TESTOPTS=...' (supports parallel tests)",
843-
hostrunnertest="run 'make hostrunnertest TESTOPTS=...'",
844-
repl="start interactive REPL / webserver + browser session",
845-
clean="run 'make clean'",
846-
cleanall="remove all build directories",
847-
emports="build Emscripten port with embuilder (only Emscripten)",
848-
)
831+
ops = {
832+
"build": "auto build (build 'build' Python, emports, configure, compile)",
833+
"configure": "run ./configure",
834+
"compile": "run 'make all'",
835+
"pythoninfo": "run 'make pythoninfo'",
836+
"test": "run 'make buildbottest TESTOPTS=...' (supports parallel tests)",
837+
"hostrunnertest": "run 'make hostrunnertest TESTOPTS=...'",
838+
"repl": "start interactive REPL / webserver + browser session",
839+
"clean": "run 'make clean'",
840+
"cleanall": "remove all build directories",
841+
"emports": "build Emscripten port with embuilder (only Emscripten)",
842+
}
849843
ops_help = "\n".join(f"{op:16s} {help}" for op, help in ops.items())
850844
parser.add_argument(
851845
"ops",

0 commit comments

Comments
 (0)