Skip to content

Commit 02f7659

Browse files
committed
relatives links fix
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] Signed-off-by: mathioud <[email protected]>
1 parent 1831e01 commit 02f7659

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/python_inspector/resolution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def get_requirements_from_python_manifest(
303303
else:
304304
# Do not raise exception here as we may have a setup.py that does not
305305
# have any dependencies.
306-
with (open(setup_py_location)) as sf:
306+
with open(setup_py_location) as sf:
307307
file_contents = sf.read()
308308
node = ast.parse(file_contents)
309309
setup_fct = [

src/python_inspector/utils_pypi.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import List
2121
from typing import NamedTuple
2222
from urllib.parse import quote_plus
23+
from urllib.parse import urljoin
2324

2425
import attr
2526
import packageurl
@@ -949,7 +950,6 @@ def get_sdist_name_ver_ext(filename):
949950

950951
@attr.attributes
951952
class Sdist(Distribution):
952-
953953
extension = attr.ib(
954954
repr=False,
955955
type=str,
@@ -1593,8 +1593,15 @@ 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)
15961599
if "data-requires-python" in anchor_tag.attrs:
15971600
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
15981605
links.append(Link(url=url, python_requires=python_requires))
15991606
# TODO: keep sha256
16001607
return links

0 commit comments

Comments
 (0)