Skip to content

Commit

Permalink
extract logic into a seperate function
Browse files Browse the repository at this point in the history
Signed-off-by: mathioud <[email protected]>
  • Loading branch information
gmathiou4 committed Jun 28, 2023
1 parent 1189e7b commit db27f06
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/python_inspector/utils_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,20 +1593,24 @@ 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
url = resolve_relative_url(package_url, url) # Resolve relative URL
links.append(Link(url=url, python_requires=python_requires))
# TODO: keep sha256
return links


def resolve_relative_url(package_url, url):
"""
Resolve a relative URL based on the package 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
return url


PYPI_PUBLIC_REPO = PypiSimpleRepository(index_url=PYPI_SIMPLE_URL)
DEFAULT_PYPI_REPOS = (PYPI_PUBLIC_REPO,)
DEFAULT_PYPI_REPOS_BY_URL = {r.index_url: r for r in DEFAULT_PYPI_REPOS}
Expand Down

0 comments on commit db27f06

Please sign in to comment.