Skip to content

Commit 390182d

Browse files
committed
Address review comments
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 06da225 commit 390182d

5 files changed

Lines changed: 4467 additions & 74 deletions

File tree

src/python_inspector/resolve_cli.py

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

273276
if verbose:
274277
print_message("Resolving dependencies...", ctx=ctx)
@@ -423,10 +426,11 @@ def resolver_api(
423426
)
424427

425428
if not ctx:
426-
if json_output:
427-
json_output = open(file=json_output, mode="w", encoding="utf-8")
428-
if pdt_output:
429-
pdt_output = open(file=pdt_output, mode="w", encoding="utf-8")
429+
return dict(
430+
headers=headers,
431+
requirements=requirements,
432+
resolved_dependencies=resolved_dependencies,
433+
)
430434

431435
if json_output:
432436
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/flask@2.1.2",
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)