1515if typing .TYPE_CHECKING : # pragma: no cover
1616 from typing import Optional , Union
1717
18+ from mesonpy ._compat import TypedDict
19+
20+ class _AbiDict (TypedDict ):
21+ extension_suffix : str
22+
23+ class _ImplementationVersionDict (TypedDict ):
24+ major : int
25+ minor : int
26+
27+ class _ImplementationDict (TypedDict ):
28+ name : str
29+ version : _ImplementationVersionDict
30+
31+ class BuildDetailsDict (TypedDict ):
32+ abi : _AbiDict
33+ implementation : _ImplementationDict
34+ platform : str
35+
1836
1937# https://peps.python.org/pep-0425/#python-tag
2038INTERPRETERS = {
2947_32_BIT_INTERPRETER = struct .calcsize ('P' ) == 4
3048
3149
32- def get_interpreter_tag () -> str :
33- name = sys .implementation .name
50+ def get_interpreter_tag (build_details : Optional [BuildDetailsDict ] = None ) -> str :
51+ if build_details is None :
52+ name = sys .implementation .name
53+ major , minor = sys .version_info [:2 ]
54+ else :
55+ name = build_details ['implementation' ]['name' ]
56+ _v = build_details ['implementation' ]['version' ]
57+ major = _v ['major' ]
58+ minor = _v ['minor' ]
3459 name = INTERPRETERS .get (name , name )
35- version = sys .version_info
36- return f'{ name } { version [0 ]} { version [1 ]} '
60+ return f'{ name } { major } { minor } '
3761
3862
3963def _get_config_var (name : str , default : Union [str , int , None ] = None ) -> Union [str , int , None ]:
@@ -53,7 +77,12 @@ def _get_cpython_abi() -> str:
5377 return f'cp{ version [0 ]} { version [1 ]} { debug } { pymalloc } '
5478
5579
56- def get_abi_tag () -> str :
80+ def get_abi_tag (build_details : Optional [BuildDetailsDict ] = None ) -> str :
81+ if build_details is not None :
82+ ext_suffix = build_details ['abi' ]['extension_suffix' ]
83+ else :
84+ ext_suffix = sysconfig .get_config_var ('EXT_SUFFIX' )
85+
5786 # The best solution to obtain the Python ABI is to parse the
5887 # $SOABI or $EXT_SUFFIX sysconfig variables as defined in PEP-314.
5988
@@ -62,7 +91,7 @@ def get_abi_tag() -> str:
6291 # See https://foss.heptapod.net/pypy/pypy/-/issues/3816 and
6392 # https://github.com/pypa/packaging/pull/607.
6493 try :
65- empty , abi , ext = str (sysconfig . get_config_var ( 'EXT_SUFFIX' ) ).split ('.' )
94+ empty , abi , ext = str (ext_suffix ).split ('.' )
6695 except ValueError as exc :
6796 # CPython <= 3.8.7 on Windows does not implement PEP3149 and
6897 # uses '.pyd' as $EXT_SUFFIX, which does not allow to extract
@@ -178,8 +207,8 @@ def _get_ios_platform_tag() -> str:
178207 return f'ios_{ version [0 ]} _{ version [1 ]} _{ multiarch } '
179208
180209
181- def get_platform_tag () -> str :
182- platform = sysconfig .get_platform ()
210+ def get_platform_tag (build_details : Optional [ BuildDetailsDict ] = None ) -> str :
211+ platform = build_details [ 'platform' ] if build_details is not None else sysconfig .get_platform ()
183212 if platform .startswith ('macosx' ):
184213 return _get_macosx_platform_tag ()
185214 if platform .startswith ('ios' ):
@@ -194,10 +223,11 @@ def get_platform_tag() -> str:
194223
195224
196225class Tag :
197- def __init__ (self , interpreter : Optional [str ] = None , abi : Optional [str ] = None , platform : Optional [str ] = None ):
198- self .interpreter = interpreter or get_interpreter_tag ()
199- self .abi = abi or get_abi_tag ()
200- self .platform = platform or get_platform_tag ()
226+ def __init__ (self , interpreter : Optional [str ] = None , abi : Optional [str ] = None , platform : Optional [str ] = None ,
227+ build_details : Optional [BuildDetailsDict ] = None ):
228+ self .interpreter = interpreter or get_interpreter_tag (build_details )
229+ self .abi = abi or get_abi_tag (build_details )
230+ self .platform = platform or get_platform_tag (build_details )
201231
202232 def __str__ (self ) -> str :
203233 return f'{ self .interpreter } -{ self .abi } -{ self .platform } '
0 commit comments