|
30 | 30 | from python_inspector.utils_pypi import PypiSimpleRepository |
31 | 31 |
|
32 | 32 |
|
| 33 | +def get_sdist_from_urls(urls: list) -> Optional[dict]: |
| 34 | + """Extract source distribution info from PyPI urls array.""" |
| 35 | + for entry in urls or []: |
| 36 | + if entry.get("packagetype") == "sdist": |
| 37 | + return { |
| 38 | + "url": entry.get("url", ""), |
| 39 | + "sha256": entry.get("digests", {}).get("sha256", ""), |
| 40 | + "md5": entry.get("digests", {}).get("md5") or entry.get("md5_digest", ""), |
| 41 | + "size": entry.get("size"), |
| 42 | + "filename": entry.get("filename", ""), |
| 43 | + } |
| 44 | + return None |
| 45 | + |
| 46 | + |
33 | 47 | async def get_pypi_data_from_purl( |
34 | 48 | purl: str, |
35 | 49 | environment: Environment, |
@@ -88,6 +102,7 @@ async def get_pypi_data_from_purl( |
88 | 102 | if not response: |
89 | 103 | return None |
90 | 104 |
|
| 105 | + sdist_info = get_sdist_from_urls(response.get("urls", [])) |
91 | 106 | homepage_url = info.get("home_page") |
92 | 107 | project_urls = info.get("project_urls") or {} |
93 | 108 | code_view_url = get_pypi_codeview_url(project_urls) |
@@ -202,6 +217,7 @@ def remove_credentials_from_url(url: str): |
202 | 217 | api_data_url=remove_credentials_from_url(api_url), |
203 | 218 | bug_tracking_url=bug_tracking_url, |
204 | 219 | code_view_url=code_view_url, |
| 220 | + extra_data={"source_artifact": sdist_info} if sdist_info else {}, |
205 | 221 | vcs_url=vcs_url, |
206 | 222 | license_expression=info.get("license_expression"), |
207 | 223 | declared_license=get_declared_license(info), |
|
0 commit comments