Newer
Older

Nathan Hertz
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import setuptools
def get_data(field, data):
"""
Get data from field if it exists.
:return: None if not found. Datum of field if found.
"""
datum = None
try:
datum = data[field]
except KeyError as e:
pass
return datum
data = {}
def my_setup(*args, **kwargs):
"""
A replacement for setuptools.setup().
"""
fields = [
'name',
'version',
'description',
'license',
'install_requires',
'tests_require',
'entry_points'
]
for field in fields:
data[field] = get_data(field, kwargs)
def main():
# Author of these shenanigans: Daniel Lyons (but you already knew that)
# Monkey-patch over the setuptools setup() function to do our function instead
setuptools.setup = my_setup
# Load the setup.py file
import setup
# Instead of exiting, we now have populated our global variable, without doing any parsing
for field, datum in data.items():
print('{}: {}'.format(field, datum))
if __name__ == "__main__":
main()