4545
4646PYTHON_VERSION = Version (python_version ())
4747DEBUG_RESOLVER = os .environ .get ("DEBUG_RESOLVER" , "" )
48- SUPPORTED_TAGS = set (sys_tags ())
4948PYPI_SERVER_URL = "https://pypi.org/simple"
5049GITHUB_URL = "https://github.com"
5150
51+ # all supported tags
52+ SUPPORTED_TAGS : frozenset [Tag ] = frozenset (sys_tags ())
53+ # same, but ignore the platform for 'ignore_platform' flag
54+ IGNORE_PLATFORM : str = "ignore"
55+ SUPPORTED_TAGS_IGNORE_PLATFORM : frozenset [Tag ] = frozenset (
56+ Tag (t .interpreter , t .abi , IGNORE_PLATFORM ) for t in SUPPORTED_TAGS
57+ )
58+
5259
5360def resolve (
5461 * ,
@@ -58,6 +65,7 @@ def resolve(
5865 include_sdists : bool = True ,
5966 include_wheels : bool = True ,
6067 req_type : RequirementType | None = None ,
68+ ignore_platform : bool = False ,
6169) -> tuple [str , Version ]:
6270 # Create the (reusable) resolver.
6371 provider = overrides .find_and_invoke (
@@ -70,6 +78,7 @@ def resolve(
7078 include_wheels = include_wheels ,
7179 sdist_server_url = sdist_server_url ,
7280 req_type = req_type ,
81+ ignore_platform = ignore_platform ,
7382 )
7483 return resolve_from_provider (provider , req )
7584
@@ -81,6 +90,7 @@ def default_resolver_provider(
8190 include_sdists : bool ,
8291 include_wheels : bool ,
8392 req_type : RequirementType | None = None ,
93+ ignore_platform : bool = False ,
8494) -> PyPIProvider | GenericProvider | GitHubTagProvider :
8595 """Lookup resolver provider to resolve package versions"""
8696 return PyPIProvider (
@@ -89,6 +99,7 @@ def default_resolver_provider(
8999 sdist_server_url = sdist_server_url ,
90100 constraints = ctx .constraints ,
91101 req_type = req_type ,
102+ ignore_platform = ignore_platform ,
92103 )
93104
94105
@@ -144,6 +155,7 @@ def get_project_from_pypi(
144155 project : str ,
145156 extras : typing .Iterable [str ],
146157 sdist_server_url : str ,
158+ ignore_platform : bool = False ,
147159) -> typing .Iterable [Candidate ]:
148160 """Return candidates created from the project name and extras."""
149161 found_candidates : set [str ] = set ()
@@ -210,6 +222,15 @@ def get_project_from_pypi(
210222 # FIXME: This doesn't take into account precedence of
211223 # the supported tags for best fit.
212224 matching_tags = SUPPORTED_TAGS .intersection (tags )
225+ if not matching_tags and ignore_platform :
226+ if DEBUG_RESOLVER :
227+ logger .debug (f"{ project } : ignoring platform for { filename } " )
228+ ignore_platform_tags : frozenset [Tag ] = frozenset (
229+ Tag (t .interpreter , t .abi , IGNORE_PLATFORM ) for t in tags
230+ )
231+ matching_tags = SUPPORTED_TAGS_IGNORE_PLATFORM .intersection (
232+ ignore_platform_tags
233+ )
213234 if not matching_tags :
214235 if DEBUG_RESOLVER :
215236 logger .debug (f"{ project } : ignoring { filename } with tags { tags } " )
@@ -272,13 +293,15 @@ def __init__(
272293 sdist_server_url : str = "https://pypi.org/simple/" ,
273294 constraints : Constraints | None = None ,
274295 req_type : RequirementType | None = None ,
296+ ignore_platform : bool = False ,
275297 ):
276298 super ().__init__ ()
277299 self .include_sdists = include_sdists
278300 self .include_wheels = include_wheels
279301 self .sdist_server_url = sdist_server_url
280302 self .constraints = constraints or Constraints ()
281303 self .req_type = req_type
304+ self .ignore_platform = ignore_platform
282305
283306 def identify (self , requirement_or_candidate : Requirement | Candidate ) -> str :
284307 return canonicalize_name (requirement_or_candidate .name )
@@ -405,13 +428,15 @@ def __init__(
405428 sdist_server_url : str = "https://pypi.org/simple/" ,
406429 constraints : Constraints | None = None ,
407430 req_type : RequirementType | None = None ,
431+ ignore_platform : bool = False ,
408432 ):
409433 super ().__init__ (
410434 include_sdists = include_sdists ,
411435 include_wheels = include_wheels ,
412436 sdist_server_url = sdist_server_url ,
413437 constraints = constraints ,
414438 req_type = req_type ,
439+ ignore_platform = ignore_platform ,
415440 )
416441
417442 def get_cache (self ) -> dict [str , list [Candidate ]]:
@@ -456,7 +481,10 @@ def find_matches(
456481 # are added to the candidate at creation - we
457482 # treat candidates as immutable once created.
458483 for candidate in get_project_from_pypi (
459- identifier , set (), self .sdist_server_url
484+ identifier ,
485+ set (),
486+ self .sdist_server_url ,
487+ self .ignore_platform ,
460488 ):
461489 if self .validate_candidate (
462490 identifier , requirements , incompatibilities , candidate
0 commit comments