Skip to content

Commit 93c803d

Browse files
committed
Fail gracefully at parsing setup.py with no deps.
Raise an exception in 'get_requirements_from_python_manifest' only if dependencies are defined in 'setup.py'. Signed-off-by: Bennati, Stefano <stefano.bennati@here.com>
1 parent 9e765ec commit 93c803d

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/python_inspector/resolution.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import operator
1111
import os
1212
import tarfile
13+
import re
1314
from typing import Dict
1415
from typing import Generator
1516
from typing import List
@@ -299,11 +300,17 @@ def get_requirements_from_python_manifest(
299300
)
300301

301302
else:
302-
# We should not raise exception here as we may have a setup.py that does not
303-
# have any dependencies. We should not fail in this case.
304-
raise Exception(
305-
f"Unable to collect setup.py dependencies securely: {setup_py_location}"
306-
)
303+
# Do not raise exception here as we may have a setup.py that does not
304+
# have any dependencies.
305+
with(open(setup_py_location)) as sf:
306+
install_requires = []
307+
parameters = re.sub(r"\s", "", re.findall(r'install_requires[\s]*=[\s]*\[[^\]]*\]',
308+
sf.read())[0])
309+
exec(parameters) # update 'install_requires' from setup.py
310+
if install_requires != []:
311+
raise Exception(
312+
f"Unable to collect setup.py dependencies securely: {setup_py_location}"
313+
)
307314

308315

309316
DEFAULT_ENVIRONMENT = utils_pypi.Environment.from_pyver_and_os(

0 commit comments

Comments
 (0)