Skip to content

Commit f279194

Browse files
committed
Provide metadata from manifest files without dependencies
Currently if there is no direct dependencies provided in a manifest file we raise exception and don't process it anymore, but this is incorrect we should provide metadata in manifest files instead of failing altogether Signed-off-by: Tushar Goel <[email protected]>
1 parent 52c8f7b commit f279194

File tree

6 files changed

+149
-3
lines changed

6 files changed

+149
-3
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ v0.9.0
66
------
77

88
- Add API function for using cleanly as a library.
9-
9+
- Add support for setuptools.setup in live evaluation.
10+
- Do not fail if no direct dependencies are provided.
1011

1112
v0.8.4
1213
------

src/python_inspector/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def resolver_api(
192192
setup_py_file_deps = insecure_setup_py_deps
193193
direct_dependencies.extend(insecure_setup_py_deps)
194194
else:
195-
raise Exception("Unable to collect setup.py dependencies securely")
195+
printer("Unable to collect setup.py dependencies securely")
196196

197197
package_data.dependencies = setup_py_file_deps
198198
file_package_data = [package_data.to_dict()]

src/python_inspector/resolution.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,4 +719,6 @@ def get_setup_dependencies(location, analyze_setup_py_insecurely=False, use_requ
719719
if analyze_setup_py_insecurely:
720720
yield from parse_reqs_from_setup_py_insecurely(setup_py=setup_py_location)
721721
else:
722-
raise Exception("Unable to collect setup.py dependencies securely")
722+
# We should not raise exception here as we may have a setup.py that does not
723+
# have any dependencies. We should not fail in this case.
724+
print(f"Unable to collect setup.py dependencies securely: {setup_py_location}")
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
from __future__ import absolute_import
4+
from __future__ import print_function
5+
6+
import unittest
7+
8+
from setuptools import setup
9+
10+
11+
def test_suite():
12+
return unittest.TestLoader().discover("tests", pattern="test_*.py")
13+
14+
15+
setup(
16+
name="spdx-tools",
17+
version="0.5.4",
18+
description="SPDX parser and tools.",
19+
packages=["spdx", "spdx.parsers", "spdx.writers", "spdx.parsers.lexers"],
20+
package_data={"spdx": ["spdx_licenselist.csv"]},
21+
include_package_data=True,
22+
zip_safe=False,
23+
test_suite="setup.test_suite",
24+
install_requires=[],
25+
entry_points={
26+
"console_scripts": [
27+
"spdx-tv2rdf = spdx.tv_to_rdf:main",
28+
],
29+
},
30+
tests_require=[
31+
"xmltodict",
32+
],
33+
author="Ahmed H. Ismail",
34+
author_email="[email protected]",
35+
maintainer="Philippe Ombredanne, SPDX group at the Linux Foundation and others",
36+
maintainer_email="[email protected]",
37+
url="https://github.com/spdx/tools-python",
38+
license="Apache-2.0",
39+
classifiers=[
40+
"Intended Audience :: Developers",
41+
"License :: OSI Approved :: Apache Software License",
42+
"Programming Language :: Python :: 2.7",
43+
],
44+
)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"headers": {
3+
"tool_name": "python-inspector",
4+
"tool_homepageurl": "https://github.com/nexB/python-inspector",
5+
"tool_version": "0.9.0",
6+
"options": [
7+
"--index-url https://pypi.org/simple",
8+
"--python-version 27",
9+
"--operating-system linux",
10+
"--json <file>"
11+
],
12+
"notice": "Dependency tree generated with python-inspector.\npython-inspector is a free software tool from nexB Inc. and others.\nVisit https://github.com/nexB/python-inspector/ for support and download.",
13+
"warnings": [],
14+
"errors": []
15+
},
16+
"files": [
17+
{
18+
"type": "file",
19+
"path": "/home/tg1999/Desktop/python-inspector-1/tests/data/setup/no-direct-dependencies-setup.py",
20+
"package_data": [
21+
{
22+
"type": "pypi",
23+
"namespace": null,
24+
"name": "spdx-tools",
25+
"version": "0.5.4",
26+
"qualifiers": {},
27+
"subpath": null,
28+
"primary_language": "Python",
29+
"description": "SPDX parser and tools.",
30+
"release_date": null,
31+
"parties": [
32+
{
33+
"type": "person",
34+
"role": "author",
35+
"name": "Ahmed H. Ismail",
36+
"email": "[email protected]",
37+
"url": null
38+
},
39+
{
40+
"type": "person",
41+
"role": "maintainer",
42+
"name": "Philippe Ombredanne, SPDX group at the Linux Foundation and others",
43+
"email": "[email protected]",
44+
"url": null
45+
}
46+
],
47+
"keywords": [
48+
"Intended Audience :: Developers",
49+
"Programming Language :: Python :: 2.7"
50+
],
51+
"homepage_url": "https://github.com/spdx/tools-python",
52+
"download_url": null,
53+
"size": null,
54+
"sha1": null,
55+
"md5": null,
56+
"sha256": null,
57+
"sha512": null,
58+
"bug_tracking_url": null,
59+
"code_view_url": null,
60+
"vcs_url": null,
61+
"copyright": null,
62+
"license_expression": null,
63+
"declared_license": {
64+
"license": "Apache-2.0",
65+
"classifiers": [
66+
"License :: OSI Approved :: Apache Software License"
67+
]
68+
},
69+
"notice_text": null,
70+
"source_packages": [],
71+
"file_references": [],
72+
"extra_data": {},
73+
"dependencies": [],
74+
"repository_homepage_url": "https://pypi.org/project/spdx-tools",
75+
"repository_download_url": "https://pypi.org/packages/source/s/spdx-tools/spdx-tools-0.5.4.tar.gz",
76+
"api_data_url": "https://pypi.org/pypi/spdx-tools/0.5.4/json",
77+
"datasource_id": "pypi_setup_py",
78+
"purl": "pkg:pypi/[email protected]"
79+
}
80+
]
81+
}
82+
],
83+
"packages": [],
84+
"resolved_dependencies_graph": {}
85+
}

tests/test_cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,20 @@ def test_cli_with_setup_py():
312312
)
313313

314314

315+
@pytest.mark.online
316+
def test_cli_with_setup_py_no_direct_dependencies():
317+
setup_py_file = setup_test_env.get_test_loc("no-direct-dependencies-setup.py")
318+
expected_file = setup_test_env.get_test_loc(
319+
"no-direct-dependencies-setup.py-expected.json", must_exist=False
320+
)
321+
check_setup_py_resolution(
322+
setup_py=setup_py_file,
323+
expected_file=expected_file,
324+
regen=REGEN_TEST_FIXTURES,
325+
extra_options=["--python-version", "27"],
326+
)
327+
328+
315329
def check_specs_resolution(
316330
specifier,
317331
expected_file,

0 commit comments

Comments
 (0)