33load ("//python/private:version.bzl" , "version" )
44load (":parse_whl_name.bzl" , "parse_whl_name" )
55
6+ # Taken from
7+ # https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#python-tag
8+ _PY_TAGS = {
9+ # "py": Generic Python (does not require implementation-specific features)
10+ "cpython" : "cp" ,
11+ "ironpython" : "ip" ,
12+ "jython" : "jy" ,
13+ "pypy" : "pp" ,
14+ }
15+ _PY = "py"
16+
617def _get_priority (* , tag , values , allow_wildcard = True ):
718 for priority , wp in enumerate (values ):
819 head , sep , tail = wp .partition ("*" )
@@ -19,7 +30,7 @@ def _get_priority(*, tag, values, allow_wildcard = True):
1930
2031 return None
2132
22- def select_whl (* , whls , python_version , platforms , want_abis , implementation = "cp " , limit = 1 , logger = None ):
33+ def select_whl (* , whls , python_version , platforms , want_abis , implementation_name = "cpython " , limit = 1 , logger = None ):
2334 """Select a whl that is the most suitable for the given platform.
2435
2536 Args:
@@ -28,7 +39,7 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
2839 python_version: {type}`str` the target python version.
2940 platforms: {type}`list[str]` the target platform identifiers that may contain
3041 a single `*` character.
31- implementation : {type}`str` a 2 letter implementation name. Defaults to "cp"
42+ implementation_name : {type}`str` the `implementation_name` from the target_platform env.
3243 want_abis: {type}`str` the ABIs that the target_platform is compatible with.
3344 limit: {type}`int` number of wheels to return. Defaults to 1.
3445 logger: {type}`struct` the logger instance.
@@ -40,11 +51,12 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
4051 """
4152 py_version = version .parse (python_version , strict = True )
4253 candidates = {}
54+ implementation = _PY_TAGS .get (implementation_name , implementation_name )
4355
4456 for whl in whls :
4557 parsed = parse_whl_name (whl .filename )
4658
47- if parsed .python_tag .startswith ("py" ):
59+ if parsed .python_tag .startswith (_PY ):
4860 pass
4961 elif not parsed .python_tag .startswith (implementation ):
5062 if logger :
@@ -57,7 +69,7 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
5769 if parsed .python_tag == "py2.py3" :
5870 min_version = "2"
5971 else :
60- min_version = parsed .python_tag [2 :]
72+ min_version = parsed .python_tag [len ( implementation ) :]
6173
6274 if len (min_version ) > 1 :
6375 min_version = "{}.{}" .format (min_version [0 ], min_version [1 :])
0 commit comments