Skip to content

Commit 2ff65f9

Browse files
committed
simplify the code
1 parent 9af5ba0 commit 2ff65f9

File tree

1 file changed

+26
-52
lines changed

1 file changed

+26
-52
lines changed

python/private/pypi/select_whl.bzl

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -50,58 +50,33 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
5050
for whl in whls:
5151
parsed = parse_whl_name(whl.filename)
5252

53-
suffix = ""
54-
if parsed.abi_tag.startswith(implementation):
55-
v = parsed.abi_tag[2:]
56-
min_whl_py_version = version.parse(
57-
"{}.{}".format(v[0], v[1:].strip("tmu")),
58-
strict = False,
59-
)
60-
if not min_whl_py_version:
61-
if logger:
62-
logger.warn(lambda: "Discarding the wheel ('{}') because we could not parse the version from the abi tag".format(whl.filename))
63-
continue
64-
65-
if parsed.abi_tag.endswith("t"):
66-
suffix = "t"
67-
68-
if not version.is_eq(py_version, min_whl_py_version):
69-
if logger:
70-
logger.debug(lambda: "Discarding the wheel ('{}') because the min version supported based on the wheel ABI tag '{}' ({}) is not compatible with the provided target Python version '{}'".format(
71-
whl.filename,
72-
parsed.abi_tag,
73-
min_whl_py_version.string,
74-
py_version.string,
75-
))
76-
continue
53+
if parsed.python_tag.startswith("py"):
54+
pass
55+
elif not parsed.python_tag.startswith(implementation):
56+
if logger:
57+
logger.debug(lambda: "Discarding the wheel because the implementation '{}' is not compatible with target implementation '{}'".format(
58+
parsed.python_tag,
59+
implementation,
60+
))
61+
continue
62+
63+
if parsed.python_tag == "py2.py3":
64+
min_version = "2"
7765
else:
78-
if parsed.python_tag.startswith("py"):
79-
pass
80-
elif not parsed.python_tag.startswith(implementation):
81-
if logger:
82-
logger.debug(lambda: "Discarding the wheel because the implementation '{}' is not compatible with target implementation '{}'".format(
83-
parsed.python_tag,
84-
implementation,
85-
))
86-
continue
87-
88-
if parsed.python_tag == "py2.py3":
89-
min_version = "2"
90-
else:
91-
min_version = parsed.python_tag[2:]
92-
93-
if len(min_version) > 1:
94-
min_version = "{}.{}".format(min_version[0], min_version[1:])
95-
96-
min_whl_py_version = version.parse(min_version, strict = True)
97-
if not version.is_ge(py_version, min_whl_py_version):
98-
if logger:
99-
logger.debug(lambda: "Discarding the wheel because the min version supported based on the wheel ABI tag '{}' ({}) is not compatible with the provided target Python version '{}'".format(
100-
parsed.abi_tag,
101-
min_whl_py_version.string,
102-
py_version.string,
103-
))
104-
continue
66+
min_version = parsed.python_tag[2:]
67+
68+
if len(min_version) > 1:
69+
min_version = "{}.{}".format(min_version[0], min_version[1:])
70+
71+
min_whl_py_version = version.parse(min_version, strict = True)
72+
if not version.is_ge(py_version, min_whl_py_version):
73+
if logger:
74+
logger.debug(lambda: "Discarding the wheel because the min version supported based on the wheel ABI tag '{}' ({}) is not compatible with the provided target Python version '{}'".format(
75+
parsed.abi_tag,
76+
min_whl_py_version.string,
77+
py_version.string,
78+
))
79+
continue
10580

10681
abi_priority = _get_priority(
10782
tag = parsed.abi_tag,
@@ -134,7 +109,6 @@ def select_whl(*, whls, python_version, platforms, want_abis, implementation = "
134109
# prefer abi_tags in this order
135110
version.key(min_whl_py_version),
136111
abi_priority,
137-
suffix,
138112
)
139113
candidates.setdefault(key, whl)
140114

0 commit comments

Comments
 (0)