DOC update FAQ instruction for detecting Emscripten runtime (#2552)

This commit is contained in:
Roman Yurchak 2022-05-13 00:39:50 -06:00 committed by GitHub
parent 0fbbeb319e
commit 3b74dcbfcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 11 deletions

View File

@ -110,7 +110,18 @@ my_namespace.get("z"); // ==> 4
## How to detect that code is run with Pyodide?
**At run time**, you can detect that a code is running with Pyodide using,
**At run time**, you can check if Python is built with Emscripten (which is the
case for Pyodide) with,
```py
import sys
if sys.platform == 'emscripten':
# running in Pyodide or other Emscripten based build
```
To detect that a code is running with Pyodide specifically, you can check
for the loaded `pyodide` module,
```py
import sys
@ -119,16 +130,6 @@ if "pyodide" in sys.modules:
# running in Pyodide
```
More generally you can detect Python built with Emscripten (which includes
Pyodide) with,
```py
import platform
if platform.system() == 'Emscripten':
# running in Pyodide or other Emscripten based build
```
This however will not work at build time (i.e. in a `setup.py`) due to the way
the Pyodide build system works. It first compiles packages with the host compiler
(e.g. gcc) and then re-runs the compilation commands with emsdk. So the `setup.py` is