-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_interpreter_metadata.py
36 lines (32 loc) · 1.23 KB
/
get_interpreter_metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import platform
import sys
import sysconfig
import struct
if platform.python_implementation() == "PyPy":
# Workaround for PyPy 3.6 on windows:
# - sysconfig.get_config_var("EXT_SUFFIX") differs to importlib until
# Python 3.8
# - PyPy does not load the plain ".pyd" suffix because it expects that's
# for a CPython extension module
#
# This workaround can probably be removed once PyPy for Python 3.8 is the
# main PyPy version.
import importlib.machinery
ext_suffix = importlib.machinery.EXTENSION_SUFFIXES[0]
else:
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
metadata = {
"major": sys.version_info.major,
"minor": sys.version_info.minor,
"abiflags": sysconfig.get_config_var("ABIFLAGS") or "",
"interpreter": platform.python_implementation().lower(),
"ext_suffix": ext_suffix,
"abi_tag": (sysconfig.get_config_var("SOABI") or "-").split("-")[1] or None,
"platform": sysconfig.get_platform(),
# This one isn't technically necessary, but still very useful for sanity checks
"system": platform.system().lower(),
# This one is for generating a config file for pyo3
"pointer_width": struct.calcsize("P") * 8,
}
print(json.dumps(metadata))