Skip to content

Commit ea71c68

Browse files
committed
Add filename-based URL matching fallback
Artifactory URLs have different path structures than PyPI URLs, but filenames are identical. When exact URL match fails, fall back to matching by filename to ensure packages array is populated. Signed-off-by: Kai Hodžić <hodzic.e.k@outlook.com>
1 parent cf4c2ad commit ea71c68

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/python_inspector/package_data.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#
1111

1212
import os
13+
import posixpath
1314
from urllib.parse import urlparse, urlunparse
1415

1516
from typing import Dict
@@ -145,6 +146,12 @@ def canonicalize_url(url: str):
145146

146147
urls_sanitized[url_sanitized] = value
147148

149+
urls_by_filename = {
150+
posixpath.basename(urlparse(e.get("url")).path): e
151+
for e in response.get("urls") or []
152+
if e.get("url")
153+
}
154+
148155
def remove_credentials_from_url(url: str):
149156
# Parse the URL into its components
150157
parsed = urlparse(url)
@@ -163,10 +170,12 @@ def remove_credentials_from_url(url: str):
163170
# iterate over the valid distribution urls and return the first
164171
# one that is matching.
165172
for dist_url in valid_distribution_urls:
166-
if dist_url not in urls_sanitized:
167-
continue
168-
169173
url_data = urls_sanitized.get(dist_url)
174+
if not url_data:
175+
filename = posixpath.basename(urlparse(dist_url).path)
176+
url_data = urls_by_filename.get(filename)
177+
if not url_data:
178+
continue
170179
digests = url_data.get("digests") or {}
171180

172181
return PackageData(

0 commit comments

Comments
 (0)