Skip to content

Commit f4203b4

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: Stefano Bennati <stefano.bennati@here.com>
1 parent f2b19f9 commit f4203b4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/python_inspector/resolution.py

Lines changed: 11 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,16 @@ 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("\s","",re.findall(r'install_requires[\s]*=[\s]*\[[^\]]*\]',sf.read())[0])
308+
exec(parameters) # update 'install_requires' from setup.py
309+
if install_requires != []:
310+
raise Exception(
311+
f"Unable to collect setup.py dependencies securely: {setup_py_location}"
312+
)
307313

308314

309315
DEFAULT_ENVIRONMENT = utils_pypi.Environment.from_pyver_and_os(

0 commit comments

Comments
 (0)