From 05f45c7016592fd95d2a8f040de0a3822525e7f7 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sun, 12 Mar 2023 23:34:46 -0700 Subject: [PATCH] Fix sys.platform when cross-compiling with emscripten --- mypy/options.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mypy/options.py b/mypy/options.py index 077e0d4ed90a..a33fa6dd3407 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -3,6 +3,7 @@ import pprint import re import sys +import sysconfig from typing import Any, Callable, Dict, Mapping, Pattern from typing_extensions import Final @@ -86,7 +87,15 @@ def __init__(self) -> None: # The executable used to search for PEP 561 packages. If this is None, # then mypy does not search for PEP 561 packages. self.python_executable: str | None = sys.executable - self.platform = sys.platform + + # When cross compiling to emscripten, we need to rely on MACHDEP because + # sys.platform is the host build platform, not emscripten. + MACHDEP = sysconfig.get_config_var("MACHDEP") + if MACHDEP == "emscripten": + self.platform = MACHDEP + else: + self.platform = sys.platform + self.custom_typing_module: str | None = None self.custom_typeshed_dir: str | None = None # The abspath() version of the above, we compute it once as an optimization.