Skip to content

Commit

Permalink
Parse dependencies from Python setup.cfg files
Browse files Browse the repository at this point in the history
  • Loading branch information
Antti Kaihola committed Jul 5, 2020
1 parent 9f7b264 commit bca6b15
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions python/helpers/lib/parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from distutils.core import run_setup
from itertools import chain
import glob
import io
Expand Down Expand Up @@ -90,6 +91,21 @@ def setup(*args, **kwargs):
for key in extras_require_dict:
for req in extras_require_dict[key]:
parse_requirement(req, 'extras_require:{}'.format(key))

try:
# Use distutils.core.run_setup() - this will also parse setup.cfg
setup_result = run_setup(directory + "/setup.py", stop_after="init")
except Exception:
# Try with the original exec() method below
pass
else:
setup(
setup_requires=getattr(setup_result, "setup_requires", None),
install_requires=getattr(setup_result, "install_requires", None),
tests_requires=getattr(setup_result, "tests_requires", None),
extras_require=getattr(setup_result, "extras_require", None),
)

setuptools.setup = setup

def noop(*args, **kwargs):
Expand Down Expand Up @@ -132,7 +148,8 @@ def fake_open(*args, **kwargs):
# Run as main (since setup.py is a script)
__name__ = '__main__'

# Exec the setup.py
exec(content) in globals(), locals()
# Exec the setup.py if distutils.core.run_setup() above didn't succeed
if not setup_packages:
exec(content) in globals(), locals()

return json.dumps({ "result": setup_packages })

0 comments on commit bca6b15

Please sign in to comment.