Skip to content

Commit

Permalink
relatives links fix
Browse files Browse the repository at this point in the history
This a fix for issue

It adds the ability to handle relative links
first check if a link is relative and joining to the full package url

Signed-off-by: Georgios Mathioudakis [email protected]
  • Loading branch information
gmathiou4 committed Jun 15, 2023
1 parent 1831e01 commit 3513ff1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/python_inspector/utils_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3513ff1

Please sign in to comment.