Skip to content

Commit 72223ce

Browse files
committed
Make mypy happy
1 parent 52f41cd commit 72223ce

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Tools/wasm/wasm_build.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import shutil
2525
import subprocess
2626
import sysconfig
27-
from typing import Callable, List, Union # for Python 3.8
27+
28+
# for Python 3.8
29+
from typing import Any, Dict, Callable, Iterable, List, Optional, Union
2830

2931
SRCDIR = pathlib.Path(__file__).parent.parent.parent.absolute()
3032
WASMTOOLS = SRCDIR / "Tools" / "wasm"
@@ -77,7 +79,7 @@
7779
"""
7880

7981

80-
def get_emscripten_root(emconfig: pathlib.Path = EM_CONFIG) -> pathlib.Path:
82+
def get_emscripten_root(emconfig: pathlib.Path = EM_CONFIG) -> pathlib.PurePath:
8183
"""Parse EM_CONFIG file and lookup EMSCRIPTEN_ROOT
8284
8385
The ".emscripten" config file is a Python snippet that uses "EM_CONFIG"
@@ -89,7 +91,7 @@ def get_emscripten_root(emconfig: pathlib.Path = EM_CONFIG) -> pathlib.Path:
8991
with open(emconfig, encoding="utf-8") as f:
9092
code = f.read()
9193
# EM_CONFIG file is a Python snippet
92-
local = {}
94+
local: Dict[str, Any] = {}
9395
exec(code, globals(), local)
9496
return pathlib.Path(local["EMSCRIPTEN_ROOT"])
9597

@@ -127,9 +129,9 @@ class Platform:
127129

128130
name: str
129131
pythonexe: str
130-
config_site: pathlib.Path
131-
configure_wrapper: pathlib.Path
132-
make_wrapper: pathlib.Path
132+
config_site: Optional[pathlib.PurePath]
133+
configure_wrapper: Optional[pathlib.PurePath]
134+
make_wrapper: Optional[pathlib.PurePath]
133135
environ: dict
134136
check: Callable[[], None]
135137

@@ -144,12 +146,13 @@ def _check_clean_src():
144146
]
145147
for candidate in candidates:
146148
if candidate.exists():
147-
raise DirtySourceDirectory(candidate, CLEAN_SRCDIR)
149+
raise DirtySourceDirectory(os.fspath(candidate), CLEAN_SRCDIR)
148150

149151

150152
NATIVE = Platform(
151153
"native",
152-
pythonexe=sysconfig.get_config_var("BUILDPYTHON"), # macOS has python.exe
154+
# macOS has python.exe
155+
pythonexe=sysconfig.get_config_var("BUILDPYTHON") or "python",
153156
config_site=None,
154157
configure_wrapper=None,
155158
make_wrapper=None,
@@ -164,17 +167,17 @@ def _check_emscripten():
164167
# sanity check
165168
emconfigure = EMSCRIPTEN.configure_wrapper
166169
if not emconfigure.exists():
167-
raise MissingDependency(emconfigure, INSTALL_EMSDK)
170+
raise MissingDependency(os.fspath(emconfigure), INSTALL_EMSDK)
168171
# version check
169172
version_txt = EMSCRIPTEN_ROOT / "emscripten-version.txt"
170173
if not version_txt.exists():
171-
raise MissingDependency(version_txt, INSTALL_EMSDK)
174+
raise MissingDependency(os.fspath(version_txt), INSTALL_EMSDK)
172175
with open(version_txt) as f:
173176
version = f.read().strip().strip('"')
174177
version_tuple = tuple(int(v) for v in version.split("."))
175178
if version_tuple < EMSDK_MIN_VERSION:
176179
raise MissingDependency(
177-
version_txt,
180+
os.fspath(version_txt),
178181
f"Emscripten SDK {version} in '{EMSCRIPTEN_ROOT}' is older than "
179182
"minimum required version "
180183
f"{'.'.join(str(v) for v in EMSDK_MIN_VERSION)}.",
@@ -196,7 +199,7 @@ def _check_emscripten():
196199
def _check_wasi():
197200
wasm_ld = WASI_SDK_PATH / "bin" / "wasm-ld"
198201
if not wasm_ld.exists():
199-
raise MissingDependency(wasm_ld, INSTALL_WASI_SDK)
202+
raise MissingDependency(os.fspath(wasm_ld), INSTALL_WASI_SDK)
200203
wasmtime = shutil.which("wasmtime")
201204
if wasmtime is None:
202205
raise MissingDependency("wasmtime", INSTALL_WASMTIME)

0 commit comments

Comments
 (0)