| 1 |
import json |
| 2 |
import platform |
| 3 |
import sys |
| 4 |
import sysconfig |
| 5 |
import struct |
| 6 |
|
| 7 |
if platform.python_implementation() == "PyPy": |
| 8 |
# Workaround for PyPy 3.6 on windows: |
| 9 |
# - sysconfig.get_config_var("EXT_SUFFIX") differs to importlib until |
| 10 |
# Python 3.8 |
| 11 |
# - PyPy does not load the plain ".pyd" suffix because it expects that's |
| 12 |
# for a CPython extension module |
| 13 |
# |
| 14 |
# This workaround can probably be removed once PyPy for Python 3.8 is the |
| 15 |
# main PyPy version. |
| 16 |
import importlib.machinery |
| 17 |
|
| 18 |
ext_suffix = importlib.machinery.EXTENSION_SUFFIXES[0] |
| 19 |
else: |
| 20 |
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") |
| 21 |
|
| 22 |
metadata = { |
| 23 |
# sys.implementation.name can differ from platform.python_implementation(), for example |
| 24 |
# Pyston has sys.implementation.name == "pyston" while platform.python_implementation() == cpython |
| 25 |
"implementation_name": sys.implementation.name, |
| 26 |
"executable": sys.executable or None, |
| 27 |
"major": sys.version_info.major, |
| 28 |
"minor": sys.version_info.minor, |
| 29 |
"abiflags": sysconfig.get_config_var("ABIFLAGS"), |
| 30 |
"interpreter": platform.python_implementation().lower(), |
| 31 |
"ext_suffix": ext_suffix, |
| 32 |
"soabi": sysconfig.get_config_var("SOABI") or None, |
| 33 |
"platform": sysconfig.get_platform(), |
| 34 |
# This one isn't technically necessary, but still very useful for sanity checks |
| 35 |
"system": platform.system().lower(), |
| 36 |
# This one is for generating a config file for pyo3 |
| 37 |
"pointer_width": struct.calcsize("P") * 8, |
| 38 |
"gil_disabled": sysconfig.get_config_var("Py_GIL_DISABLED") == 1, |
| 39 |
} |
| 40 |
|
| 41 |
print(json.dumps(metadata)) |