Skip to content

Commit 3f3d400

Browse files
committed
Address review comments
Signed-off-by: Tushar Goel <[email protected]>
1 parent fc28934 commit 3f3d400

File tree

6 files changed

+4468
-75
lines changed

6 files changed

+4468
-75
lines changed

src/python_inspector/resolve_cli.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ def resolve_dependencies(
207207
208208
python-inspector --spec "flask==2.1.2" --json -
209209
"""
210+
if not (json_output or pdt_output):
211+
click.secho("No output file specified. Use --json or --json-pdt.", err=True)
212+
ctx.exit(1)
213+
214+
if json_output and pdt_output:
215+
click.secho("Only one of --json or --json-pdt can be used.", err=True)
216+
ctx.exit(1)
217+
210218
resolver_api(
211219
requirement_files=requirement_files,
212220
setup_py_file=setup_py_file,
@@ -263,11 +271,6 @@ def resolver_api(
263271
more ``requirement_files``, one or more ``specifiers`` and one setuptools
264272
``setup_py_file`` file and save the results as JSON to FILE.
265273
"""
266-
if not (json_output or pdt_output):
267-
raise_error("No output file specified. Use --json or --json-pdt.", ctx=ctx)
268-
269-
if json_output and pdt_output:
270-
raise_error("Only one of --json or --json-pdt can be used.", ctx=ctx)
271274

272275
if verbose:
273276
print_message("Resolving dependencies...", ctx=ctx)
@@ -415,10 +418,11 @@ def resolver_api(
415418
)
416419

417420
if not ctx:
418-
if json_output:
419-
json_output = open(file=json_output, mode="w", encoding="utf-8")
420-
if pdt_output:
421-
pdt_output = open(file=pdt_output, mode="w", encoding="utf-8")
421+
return dict(
422+
headers=headers,
423+
requirements=requirements,
424+
resolved_dependencies=resolved_dependencies,
425+
)
422426

423427
if json_output:
424428
write_output(
Lines changed: 76 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,76 @@
1-
[
2-
{
3-
"key": "flask",
4-
"package_name": "flask",
5-
"installed_version": "2.1.2",
6-
"dependencies": [
7-
{
8-
"key": "click",
9-
"package_name": "click",
10-
"installed_version": "8.1.3",
11-
"dependencies": []
12-
},
13-
{
14-
"key": "itsdangerous",
15-
"package_name": "itsdangerous",
16-
"installed_version": "2.1.2",
17-
"dependencies": []
18-
},
19-
{
20-
"key": "jinja2",
21-
"package_name": "jinja2",
22-
"installed_version": "3.1.2",
23-
"dependencies": [
24-
{
25-
"key": "markupsafe",
26-
"package_name": "markupsafe",
27-
"installed_version": "2.1.1",
28-
"dependencies": []
29-
}
30-
]
31-
},
32-
{
33-
"key": "werkzeug",
34-
"package_name": "werkzeug",
35-
"installed_version": "2.2.2",
36-
"dependencies": [
37-
{
38-
"key": "markupsafe",
39-
"package_name": "markupsafe",
40-
"installed_version": "2.1.1",
41-
"dependencies": []
42-
}
43-
]
44-
}
45-
]
46-
}
47-
]
1+
{
2+
"headers": {
3+
"tool_name": "python-inspector",
4+
"tool_homepageurl": "https://github.com/nexB/python-inspector",
5+
"tool_version": "0.6.5",
6+
"options": [
7+
"specifiers- flask==2.1.2",
8+
"index_urls- https://pypi.org/simple",
9+
"python-version 3.10",
10+
"operating-system linux",
11+
"json "
12+
],
13+
"notice": "Dependency tree generated with python-inspector.\npython-inspector is a free software tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
14+
"warnings": [],
15+
"errors": []
16+
},
17+
"requirements": [
18+
{
19+
"purl": "pkg:pypi/[email protected]",
20+
"extracted_requirement": "flask==2.1.2",
21+
"scope": "install",
22+
"is_runtime": true,
23+
"is_optional": false,
24+
"is_resolved": true,
25+
"resolved_package": {},
26+
"extra_data": {}
27+
}
28+
],
29+
"resolved_dependencies": [
30+
{
31+
"key": "flask",
32+
"package_name": "flask",
33+
"installed_version": "2.1.2",
34+
"dependencies": [
35+
{
36+
"key": "click",
37+
"package_name": "click",
38+
"installed_version": "8.1.3",
39+
"dependencies": []
40+
},
41+
{
42+
"key": "itsdangerous",
43+
"package_name": "itsdangerous",
44+
"installed_version": "2.1.2",
45+
"dependencies": []
46+
},
47+
{
48+
"key": "jinja2",
49+
"package_name": "jinja2",
50+
"installed_version": "3.1.2",
51+
"dependencies": [
52+
{
53+
"key": "markupsafe",
54+
"package_name": "markupsafe",
55+
"installed_version": "2.1.1",
56+
"dependencies": []
57+
}
58+
]
59+
},
60+
{
61+
"key": "werkzeug",
62+
"package_name": "werkzeug",
63+
"installed_version": "2.2.2",
64+
"dependencies": [
65+
{
66+
"key": "markupsafe",
67+
"package_name": "markupsafe",
68+
"installed_version": "2.1.1",
69+
"dependencies": []
70+
}
71+
]
72+
}
73+
]
74+
}
75+
]
76+
}

0 commit comments

Comments
 (0)