Skip to content

Commit 0faa413

Browse files
Use PYODIDE environment variable for Emscripten cross-compilation detection (#21714)
I noticed that y'all were carrying this workaround ever since #14888. A better way to detect this is through [the `PYODIDE` environment variable, which we've documented over the years](https://pyodide-build.readthedocs.io/en/latest/how-to/migrate.html#detecting-pyodide-at-build-time), and is what most projects use now. The MACHDEP generality would mostly apply to non-Pyodide-specific WASM build targets, which are growing in relevance but are a bit less mature as Pyodide at this time.
1 parent 3d75cdb commit 0faa413

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

mypy/options.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import annotations
22

3+
import os
34
import pprint
45
import re
56
import sys
6-
import sysconfig
77
from collections.abc import Callable
88
from re import Pattern
99
from typing import Any, Final
@@ -112,11 +112,11 @@ def __init__(self) -> None:
112112
# then mypy does not search for PEP 561 packages.
113113
self.python_executable: str | None = sys.executable
114114

115-
# When cross compiling to emscripten, we need to rely on MACHDEP because
116-
# sys.platform is the host build platform, not emscripten.
117-
MACHDEP = sysconfig.get_config_var("MACHDEP")
118-
if MACHDEP == "emscripten":
119-
self.platform = MACHDEP
115+
# When cross compiling to emscripten, sys.platform is the host build
116+
# platform, not emscripten. Pyodide sets the PYODIDE environment variable
117+
# at build time, so we use it to detect the emscripten target.
118+
if "PYODIDE" in os.environ:
119+
self.platform = "emscripten"
120120
else:
121121
self.platform = sys.platform
122122

0 commit comments

Comments
 (0)