Skip to content

Commit cf394b9

Browse files
committed
Make mypy happy
1 parent 52f41cd commit cf394b9

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Tools/wasm/wasm_build.py

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

2930
SRCDIR = pathlib.Path(__file__).parent.parent.parent.absolute()
3031
WASMTOOLS = SRCDIR / "Tools" / "wasm"
@@ -77,7 +78,7 @@
7778
"""
7879

7980

80-
def get_emscripten_root(emconfig: pathlib.Path = EM_CONFIG) -> pathlib.Path:
81+
def get_emscripten_root(emconfig: pathlib.Path = EM_CONFIG) -> pathlib.PurePath:
8182
"""Parse EM_CONFIG file and lookup EMSCRIPTEN_ROOT
8283
8384
The ".emscripten" config file is a Python snippet that uses "EM_CONFIG"
@@ -89,7 +90,7 @@ def get_emscripten_root(emconfig: pathlib.Path = EM_CONFIG) -> pathlib.Path:
8990
with open(emconfig, encoding="utf-8") as f:
9091
code = f.read()
9192
# EM_CONFIG file is a Python snippet
92-
local = {}
93+
local: Dict[str, Any] = {}
9394
exec(code, globals(), local)
9495
return pathlib.Path(local["EMSCRIPTEN_ROOT"])
9596

@@ -127,9 +128,9 @@ class Platform:
127128

128129
name: str
129130
pythonexe: str
130-
config_site: pathlib.Path
131-
configure_wrapper: pathlib.Path
132-
make_wrapper: pathlib.Path
131+
config_site: Optional[pathlib.PurePath]
132+
configure_wrapper: Optional[pathlib.PurePath]
133+
make_wrapper: Optional[pathlib.PurePath]
133134
environ: dict
134135
check: Callable[[], None]
135136

@@ -144,12 +145,13 @@ def _check_clean_src():
144145
]
145146
for candidate in candidates:
146147
if candidate.exists():
147-
raise DirtySourceDirectory(candidate, CLEAN_SRCDIR)
148+
raise DirtySourceDirectory(os.fspath(candidate), CLEAN_SRCDIR)
148149

149150

150151
NATIVE = Platform(
151152
"native",
152-
pythonexe=sysconfig.get_config_var("BUILDPYTHON"), # macOS has python.exe
153+
# macOS has python.exe
154+
pythonexe=sysconfig.get_config_var("BUILDPYTHON") or "python",
153155
config_site=None,
154156
configure_wrapper=None,
155157
make_wrapper=None,
@@ -164,17 +166,17 @@ def _check_emscripten():
164166
# sanity check
165167
emconfigure = EMSCRIPTEN.configure_wrapper
166168
if not emconfigure.exists():
167-
raise MissingDependency(emconfigure, INSTALL_EMSDK)
169+
raise MissingDependency(os.fspath(emconfigure), INSTALL_EMSDK)
168170
# version check
169171
version_txt = EMSCRIPTEN_ROOT / "emscripten-version.txt"
170172
if not version_txt.exists():
171-
raise MissingDependency(version_txt, INSTALL_EMSDK)
173+
raise MissingDependency(os.fspath(version_txt), INSTALL_EMSDK)
172174
with open(version_txt) as f:
173175
version = f.read().strip().strip('"')
174176
version_tuple = tuple(int(v) for v in version.split("."))
175177
if version_tuple < EMSDK_MIN_VERSION:
176178
raise MissingDependency(
177-
version_txt,
179+
os.fspath(version_txt),
178180
f"Emscripten SDK {version} in '{EMSCRIPTEN_ROOT}' is older than "
179181
"minimum required version "
180182
f"{'.'.join(str(v) for v in EMSDK_MIN_VERSION)}.",
@@ -196,7 +198,7 @@ def _check_emscripten():
196198
def _check_wasi():
197199
wasm_ld = WASI_SDK_PATH / "bin" / "wasm-ld"
198200
if not wasm_ld.exists():
199-
raise MissingDependency(wasm_ld, INSTALL_WASI_SDK)
201+
raise MissingDependency(os.fspath(wasm_ld), INSTALL_WASI_SDK)
200202
wasmtime = shutil.which("wasmtime")
201203
if wasmtime is None:
202204
raise MissingDependency("wasmtime", INSTALL_WASMTIME)

0 commit comments

Comments
 (0)