Skip to content

Commit

Permalink
feat: extract the wheel tag validation method
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed Jan 15, 2024
1 parent 49dea44 commit fc1757b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/unearth/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
import os
import sys
from typing import Any
from typing import Any, Iterable

import packaging.requirements
from packaging.specifiers import InvalidSpecifier, SpecifierSet
Expand Down Expand Up @@ -175,6 +175,16 @@ def check_requires_python(self, link: Link) -> None:
),
)

def validate_wheel_tag(self, tags: Iterable[Tag]) -> bool:
"""Check if the wheel tags are compatible with the target Python.
Args:
tags (Iterable[Tag]): The wheel tags to check.
"""
if self.ignore_compatibility:
return True
return not set(tags).isdisjoint(self.target_python.supported_tags())

def evaluate_link(self, link: Link) -> Package | None:
"""
Evaluate the link and return the package if it matches or None if it doesn't.
Expand All @@ -193,9 +203,7 @@ def evaluate_link(self, link: Link) -> Package | None:
raise LinkMismatchError(
f"The package name doesn't match {wheel_info[0]}"
)
if not self.ignore_compatibility and wheel_info[3].isdisjoint(
self.target_python.supported_tags()
):
if not self.validate_wheel_tag(wheel_info[3]):
raise LinkMismatchError(
"none of the wheel tags({}) are compatible".format(
", ".join(sorted(str(tag) for tag in wheel_info[3]))
Expand Down

0 comments on commit fc1757b

Please sign in to comment.