Skip to content

Commit a471aee

Browse files
committed
Use get_description to build description
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 0892a6a commit a471aee

19 files changed

+616
-601
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ Changelog
22
=========
33

44

5+
v0.8.5
6+
------
7+
- Adapt python-inspector output according to SCTK output.
8+
9+
510
v0.8.4
611
------
712

src/python_inspector/package_data.py

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from _packagedcode.models import PackageData
1717
from _packagedcode.pypi import get_declared_license
18+
from _packagedcode.pypi import get_description
1819
from _packagedcode.pypi import get_keywords
1920
from _packagedcode.pypi import get_parties
2021
from python_inspector import utils_pypi
@@ -23,66 +24,15 @@
2324
from python_inspector.utils_pypi import PypiSimpleRepository
2425

2526

26-
def get_pypi_bugtracker_url(project_urls):
27-
bug_tracking_url = project_urls.get("Tracker")
28-
if not (bug_tracking_url):
29-
bug_tracking_url = project_urls.get("Issue Tracker")
30-
if not (bug_tracking_url):
31-
bug_tracking_url = project_urls.get("Bug Tracker")
32-
return bug_tracking_url
33-
34-
35-
def get_pypi_codeview_url(project_urls):
36-
code_view_url = project_urls.get("Source")
37-
if not (code_view_url):
38-
code_view_url = project_urls.get("Code")
39-
if not (code_view_url):
40-
code_view_url = project_urls.get("Source Code")
41-
return code_view_url
42-
43-
44-
def get_wheel_download_urls(
45-
purl: PackageURL,
46-
repos: List[PypiSimpleRepository],
47-
environment: Environment,
48-
python_version: str,
49-
) -> List[str]:
50-
"""
51-
Return a list of download urls for the given purl.
52-
"""
53-
for repo in repos:
54-
for wheel in utils_pypi.get_supported_and_valid_wheels(
55-
repo=repo,
56-
name=purl.name,
57-
version=purl.version,
58-
environment=environment,
59-
python_version=python_version,
60-
):
61-
yield wheel.download_url
62-
63-
64-
def get_sdist_download_url(
65-
purl: PackageURL, repos: List[PypiSimpleRepository], python_version: str
66-
) -> str:
67-
"""
68-
Return a list of download urls for the given purl.
69-
"""
70-
for repo in repos:
71-
sdist = utils_pypi.get_valid_sdist(
72-
repo=repo,
73-
name=purl.name,
74-
version=purl.version,
75-
python_version=python_version,
76-
)
77-
if sdist:
78-
return sdist.download_url
79-
80-
8127
def get_pypi_data_from_purl(
8228
purl: str, environment: Environment, repos: List[PypiSimpleRepository]
8329
) -> PackageData:
8430
"""
85-
Generate `Package` object from the `purl` string of npm type
31+
Generate `Package` object from the `purl` string of pypi type
32+
33+
``purl`` is a package-url of pypi type
34+
``environment`` is a `Environment` object defaulting Python version 3.8 and linux OS
35+
``repos`` is a list of `PypiSimpleRepository` objects
8636
"""
8737
purl = PackageURL.from_string(purl)
8838
name = purl.name
@@ -129,7 +79,7 @@ def get_pypi_data_from_purl(
12979

13080
yield PackageData(
13181
primary_language="Python",
132-
description=info.get("summary") or info.get("description"),
82+
description=get_description(info),
13383
homepage_url=homepage_url,
13484
api_data_url=api_url,
13585
bug_tracking_url=bug_tracking_url,
@@ -149,4 +99,59 @@ def get_pypi_data_from_purl(
14999
maintainer_email_key="maintainer_email",
150100
),
151101
**purl.to_dict(),
152-
).to_dict()
102+
)
103+
104+
105+
def get_pypi_bugtracker_url(project_urls):
106+
bug_tracking_url = project_urls.get("Tracker")
107+
if not (bug_tracking_url):
108+
bug_tracking_url = project_urls.get("Issue Tracker")
109+
if not (bug_tracking_url):
110+
bug_tracking_url = project_urls.get("Bug Tracker")
111+
return bug_tracking_url
112+
113+
114+
def get_pypi_codeview_url(project_urls):
115+
code_view_url = project_urls.get("Source")
116+
if not (code_view_url):
117+
code_view_url = project_urls.get("Code")
118+
if not (code_view_url):
119+
code_view_url = project_urls.get("Source Code")
120+
return code_view_url
121+
122+
123+
def get_wheel_download_urls(
124+
purl: PackageURL,
125+
repos: List[PypiSimpleRepository],
126+
environment: Environment,
127+
python_version: str,
128+
) -> List[str]:
129+
"""
130+
Return a list of download urls for the given purl.
131+
"""
132+
for repo in repos:
133+
for wheel in utils_pypi.get_supported_and_valid_wheels(
134+
repo=repo,
135+
name=purl.name,
136+
version=purl.version,
137+
environment=environment,
138+
python_version=python_version,
139+
):
140+
yield wheel.download_url
141+
142+
143+
def get_sdist_download_url(
144+
purl: PackageURL, repos: List[PypiSimpleRepository], python_version: str
145+
) -> str:
146+
"""
147+
Return a list of download urls for the given purl.
148+
"""
149+
for repo in repos:
150+
sdist = utils_pypi.get_valid_sdist(
151+
repo=repo,
152+
name=purl.name,
153+
version=purl.version,
154+
python_version=python_version,
155+
)
156+
if sdist:
157+
return sdist.download_url

src/python_inspector/resolve_cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
TRACE = False
3838

39-
__version__ = "0.8.4"
39+
__version__ = "0.8.5"
4040

4141
DEFAULT_PYTHON_VERSION = "38"
4242
PYPI_SIMPLE_URL = "https://pypi.org/simple"
@@ -424,7 +424,12 @@ def resolve_dependencies(
424424

425425
for package in purls:
426426
packages.extend(
427-
list(get_pypi_data_from_purl(package, repos=repos, environment=environment)),
427+
[
428+
pkg.to_dict()
429+
for pkg in list(
430+
get_pypi_data_from_purl(package, repos=repos, environment=environment)
431+
)
432+
],
428433
)
429434

430435
output = dict(

tests/data/azure-devops.req-310-expected.json

Lines changed: 35 additions & 35 deletions
Large diffs are not rendered by default.

tests/data/azure-devops.req-38-expected.json

Lines changed: 35 additions & 35 deletions
Large diffs are not rendered by default.

tests/data/default-url-expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"headers": {
33
"tool_name": "python-inspector",
44
"tool_homepageurl": "https://github.com/nexB/python-inspector",
5-
"tool_version": "0.8.4",
5+
"tool_version": "0.8.5",
66
"options": [
77
"--specifier zipp==3.8.0",
88
"--index-url https://pypi.org/simple",

tests/data/environment-marker-test-requirements.txt-expected.json

Lines changed: 9 additions & 9 deletions
Large diffs are not rendered by default.

tests/data/frozen-requirements.txt-expected.json

Lines changed: 143 additions & 143 deletions
Large diffs are not rendered by default.

tests/data/insecure-setup-2/setup.py-expected.json

Lines changed: 127 additions & 127 deletions
Large diffs are not rendered by default.

tests/data/insecure-setup/setup.py-expected.json

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)