Skip to content

Commit db27f06

Browse files
committed
extract logic into a seperate function
Signed-off-by: mathioud <[email protected]>
1 parent 1189e7b commit db27f06

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/python_inspector/utils_pypi.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -1593,20 +1593,24 @@ def fetch_links(
15931593
for anchor_tag in anchor_tags:
15941594
python_requires = None
15951595
url, _, _sha256 = anchor_tag["href"].partition("#sha256=")
1596-
if url.startswith(".."):
1597-
# Handle relative links
1598-
url = urljoin(package_url, url)
15991596
if "data-requires-python" in anchor_tag.attrs:
16001597
python_requires = anchor_tag.attrs["data-requires-python"]
1601-
# Check if the link is a relative URL
1602-
if not url.startswith(("http://", "https://")):
1603-
base_url = "/".join(package_url.split("/")[:-1]) # Extract base URL
1604-
url = urljoin(base_url, url) # Resolve relative URL
1598+
url = resolve_relative_url(package_url, url) # Resolve relative URL
16051599
links.append(Link(url=url, python_requires=python_requires))
16061600
# TODO: keep sha256
16071601
return links
16081602

16091603

1604+
def resolve_relative_url(package_url, url):
1605+
"""
1606+
Resolve a relative URL based on the package URL.
1607+
"""
1608+
if not url.startswith(("http://", "https://")):
1609+
base_url = "/".join(package_url.split("/")[:-1]) # Extract base URL
1610+
url = urljoin(base_url, url) # Resolve relative URL
1611+
return url
1612+
1613+
16101614
PYPI_PUBLIC_REPO = PypiSimpleRepository(index_url=PYPI_SIMPLE_URL)
16111615
DEFAULT_PYPI_REPOS = (PYPI_PUBLIC_REPO,)
16121616
DEFAULT_PYPI_REPOS_BY_URL = {r.index_url: r for r in DEFAULT_PYPI_REPOS}

0 commit comments

Comments
 (0)