@@ -105,6 +105,46 @@ def _python_tag_priority(*, tag, implementation, py_version):
105105 version .key (ver ),
106106 )
107107
108+ def _filter_platform_tags (tags ):
109+ ret = []
110+ replacements = {}
111+ for tag in tags :
112+ if not (
113+ tag .startswith (_ANDROID ) or
114+ tag .startswith (_IOS ) or
115+ tag .startswith (_MACOSX ) or
116+ tag .startswith (_MANYLINUX ) or
117+ tag .startswith (_MUSLLINUX )
118+ ):
119+ ret .append (tag )
120+ continue
121+
122+ want_os , sep , tail = tag .partition ("_" )
123+ if not sep :
124+ fail ("could not parse the tag" )
125+
126+ want_major , _ , tail = tail .partition ("_" )
127+ if want_major == "*" :
128+ # the expected match is any version
129+ want_arch = tail
130+ elif want_os .startswith (_ANDROID ):
131+ want_arch = tail
132+ else :
133+ # drop the minor version segment
134+ _ , _ , want_arch = tail .partition ("_" )
135+
136+ placeholder = "{}_*_{}" .format (want_os , want_arch )
137+ replacements [placeholder ] = tag
138+ if placeholder in ret :
139+ ret .remove (placeholder )
140+
141+ ret .append (placeholder )
142+
143+ return [
144+ replacements .get (p , p )
145+ for p in ret
146+ ]
147+
108148def _candidates_by_priority (
109149 * ,
110150 whls ,
@@ -121,6 +161,9 @@ def _candidates_by_priority(
121161 """
122162 py_version = version .parse (python_version , strict = True )
123163 implementation = python_tag (implementation_name )
164+ logger .debug (lambda : "input: {}" .format (whl_platform_tags ))
165+ whl_platform_tags = _filter_platform_tags (whl_platform_tags )
166+ logger .debug (lambda : "output: {}" .format (whl_platform_tags ))
124167
125168 ret = {}
126169 for whl in whls :
0 commit comments