| 1 |
import sys |
| 2 |
from distutils import sysconfig |
| 3 |
|
| 4 |
|
| 5 |
HPY_ABI_VERSION = 0 |
| 6 |
HPY_ABI_VERSION_MINOR = 0 |
| 7 |
HPY_ABI_TAG = 'hpy%d' % HPY_ABI_VERSION |
| 8 |
|
| 9 |
def parse_ext_suffix(ext_suffix=None): |
| 10 |
""" |
| 11 |
Parse EXT_SUFFIX and return abi_tag, ext. |
| 12 |
|
| 13 |
- abi_tag is a string representing the CPython ABI tag: e.g. 'cp38', 'cp310d', etc. |
| 14 |
- ext is the filename extension, e.g 'so', 'pyd' or 'dylib' |
| 15 |
""" |
| 16 |
if ext_suffix is None: |
| 17 |
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX') |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
assert ext_suffix[0] == '.' |
| 28 |
_, soabi, ext = ext_suffix.split('.') |
| 29 |
|
| 30 |
|
| 31 |
parts = soabi.split('-') |
| 32 |
if parts[0].startswith('cpython'): |
| 33 |
n = 2 |
| 34 |
elif parts[0].startswith('cp'): |
| 35 |
n = 1 |
| 36 |
elif parts[0].startswith('pypy'): |
| 37 |
n = 2 |
| 38 |
elif parts[0].startswith('graalpy'): |
| 39 |
n = 3 |
| 40 |
else: |
| 41 |
n = len(parts) |
| 42 |
|
| 43 |
abi_tag = '-'.join(parts[:n]) |
| 44 |
|
| 45 |
|
| 46 |
abi_tag = abi_tag.replace('cpython-', 'cp') |
| 47 |
return abi_tag, ext |
| 48 |
|
| 49 |
|
| 50 |
def get_hpy_ext_suffix(hpy_abi, ext_suffix=None): |
| 51 |
""" |
| 52 |
Return the proper filename extension for the given hpy_abi. |
| 53 |
|
| 54 |
For example with CPython 3.10 on Linux, it will return: |
| 55 |
|
| 56 |
- universal ==> .hpy0.so |
| 57 |
- hybrid ==> .hpy0-cp310.so |
| 58 |
""" |
| 59 |
assert hpy_abi in ('cpython', 'universal', 'hybrid') |
| 60 |
cpy_abi_tag, ext = parse_ext_suffix(ext_suffix) |
| 61 |
if hpy_abi == 'cpython': |
| 62 |
return sysconfig.get_config_var('EXT_SUFFIX') |
| 63 |
elif hpy_abi == 'universal': |
| 64 |
return '.%s.%s' % (HPY_ABI_TAG, ext) |
| 65 |
else: |
| 66 |
return '.%s-%s.%s' % (HPY_ABI_TAG, cpy_abi_tag, ext) |