-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathsetup_metadata.py
51 lines (40 loc) · 1.36 KB
/
setup_metadata.py
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
45
46
47
48
49
50
51
#!/usr/bin/python3
"""Read options from [metadata] section from setup.cfg
"""
from os.path import dirname, abspath, join
from configparser import ConfigParser
THIS_FILE = __file__
def get_metadata():
"""Read the [metadata] section of setup.cfg and return it as a dict.
"""
parser = ConfigParser()
parser.read(_get_cfg_fname())
options = dict(parser.items("metadata"))
# return options
return _normalize(options)
def _get_cfg_fname():
return join(dirname(abspath(THIS_FILE)), "setup.cfg")
def _normalize(options):
"""Return correct kwargs for setup() from provided options-dict.
"""
retval = {
key.replace("-", "_"): value for key, value in options.items()
}
# Classifiers
value = retval.pop("classifiers", None)
if value and isinstance(value, str):
classifiers = value.splitlines()
while "" in classifiers:
classifiers.remove("")
retval["classifiers"] = classifiers
# Long description from file
description_file = retval.pop("long_description_file", None)
if description_file:
try:
with open(description_file) as fdesc:
retval["long_description"] = fdesc.read()
except IOError:
retval["long_description"] = "Read the accompanying {}".format(
description_file
)
return retval