diff --git a/src/python_inspector/utils_pypi.py b/src/python_inspector/utils_pypi.py index df14920..33a2454 100644 --- a/src/python_inspector/utils_pypi.py +++ b/src/python_inspector/utils_pypi.py @@ -30,6 +30,7 @@ from packvers import tags as packaging_tags from packvers import version as packaging_version from packvers.specifiers import SpecifierSet +from urllib.parse import urljoin from python_inspector import DEFAULT_PYTHON_VERSION from python_inspector import utils_pip_compatibility_tags @@ -1593,8 +1594,15 @@ def fetch_links( for anchor_tag in anchor_tags: python_requires = None url, _, _sha256 = anchor_tag["href"].partition("#sha256=") + if url.startswith(".."): + # Handle relative links + url = urljoin(package_url, url) if "data-requires-python" in anchor_tag.attrs: python_requires = anchor_tag.attrs["data-requires-python"] + # Check if the link is a relative URL + if not url.startswith(("http://", "https://")): + base_url = "/".join(package_url.split("/")[:-1]) # Extract base URL + url = urljoin(base_url, url) # Resolve relative URL links.append(Link(url=url, python_requires=python_requires)) # TODO: keep sha256 return links