3
3
load ("//python/private:version.bzl" , "version" )
4
4
load (":parse_whl_name.bzl" , "parse_whl_name" )
5
5
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
+
6
17
def _get_priority (* , tag , values , allow_wildcard = True ):
7
18
for priority , wp in enumerate (values ):
8
19
head , sep , tail = wp .partition ("*" )
@@ -19,7 +30,7 @@ def _get_priority(*, tag, values, allow_wildcard = True):
19
30
20
31
return None
21
32
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 ):
23
34
"""Select a whl that is the most suitable for the given platform.
24
35
25
36
Args:
@@ -28,7 +39,7 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
28
39
python_version: {type}`str` the target python version.
29
40
platforms: {type}`list[str]` the target platform identifiers that may contain
30
41
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.
32
43
want_abis: {type}`str` the ABIs that the target_platform is compatible with.
33
44
limit: {type}`int` number of wheels to return. Defaults to 1.
34
45
logger: {type}`struct` the logger instance.
@@ -40,11 +51,12 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
40
51
"""
41
52
py_version = version .parse (python_version , strict = True )
42
53
candidates = {}
54
+ implementation = _PY_TAGS .get (implementation_name , implementation_name )
43
55
44
56
for whl in whls :
45
57
parsed = parse_whl_name (whl .filename )
46
58
47
- if parsed .python_tag .startswith ("py" ):
59
+ if parsed .python_tag .startswith (_PY ):
48
60
pass
49
61
elif not parsed .python_tag .startswith (implementation ):
50
62
if logger :
@@ -57,7 +69,7 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
57
69
if parsed .python_tag == "py2.py3" :
58
70
min_version = "2"
59
71
else :
60
- min_version = parsed .python_tag [2 :]
72
+ min_version = parsed .python_tag [len ( implementation ) :]
61
73
62
74
if len (min_version ) > 1 :
63
75
min_version = "{}.{}" .format (min_version [0 ], min_version [1 :])
0 commit comments