Skip to content

Commit c7b6bd0

Browse files
committed
fix: Fetch package metadata from private artifactory if specified
If a private repository is specified, the package metadata should be fetched from it, not from pypi.org. Please note the limitation that querying from multiple private repositories is currently not supported. Fixes #260. Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
1 parent 082f47d commit c7b6bd0

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/python_inspector/api.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,11 @@ def resolve_dependencies(
296296
async def gather_pypi_data():
297297
async def get_pypi_data(package):
298298
data = await get_pypi_data_from_purl(
299-
package, repos=repos, environment=environment, prefer_source=prefer_source
299+
package,
300+
repos=repos,
301+
environment=environment,
302+
prefer_source=prefer_source,
303+
index_urls=list(repos_by_url.keys()),
300304
)
301305

302306
if verbose:

src/python_inspector/package_data.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727

2828

2929
async def get_pypi_data_from_purl(
30-
purl: str, environment: Environment, repos: List[PypiSimpleRepository], prefer_source: bool
30+
purl: str,
31+
environment: Environment,
32+
repos: List[PypiSimpleRepository],
33+
prefer_source: bool,
34+
index_urls: List[str],
3135
) -> Optional[PackageData]:
3236
"""
3337
Generate `Package` object from the `purl` string of pypi type
@@ -43,7 +47,22 @@ async def get_pypi_data_from_purl(
4347
version = parsed_purl.version
4448
if not version:
4549
raise Exception("Version is not specified in the purl")
46-
base_path = "https://pypi.org/pypi"
50+
51+
# Todo: address the case where several index URLs are passed
52+
if index_urls:
53+
# Backward compatibility: If pypi.org is passed as index url, always resolve against it.
54+
# When multiple index URLs are supported and the todo above is fixed, then this hack can be removed.
55+
if "https://pypi.org/simple" in index_urls:
56+
index_url = None
57+
else:
58+
index_url = index_urls[0]
59+
else:
60+
index_url = None
61+
62+
base_path = (
63+
index_url.removesuffix("/simple") + "/pypi" if index_url else "https://pypi.org/pypi"
64+
)
65+
4766
api_url = f"{base_path}/{name}/{version}/json"
4867

4968
from python_inspector.utils import get_response_async

0 commit comments

Comments
 (0)