-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
79 lines (65 loc) · 2.36 KB
/
setup.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import ConfigParser
from sys import argv
try:
from setuptools import setup
use_setuptools = True
except ImportError, err:
from distutils.core import setup
use_setuptools = False
import os
SETUP_ARGS = {"name" : ("metadata",),
"version" : ("metadata",),
"description" : ("metadata", "summary"),
"classifiers" : ("metadata", "classifier"),
"author" : ("metadata",),
"author_email": ("metadata",),
"keywords" : ("metadata",),
"url" : ("metadata", "home_page"),
"license" : ("metadata",),
"packages" : ("files",),
"requires" : ("metadata", "requires_dist"),
"test_suite" : ('specific',),
"entry_points" : ('specific',),
}
MULTI = ("classifiers",
"requires",
"packages",
"scripts")
def generate_setuptools_kwargs_from_setup_cfg():
config = ConfigParser.RawConfigParser()
config.read('setup.cfg')
kwargs = {}
for arg in SETUP_ARGS:
if len(SETUP_ARGS[arg]) == 2:
section, option = SETUP_ARGS[arg]
elif len(SETUP_ARGS[arg]) == 1:
section = SETUP_ARGS[arg][0]
option = arg
try:
in_cfg_value = config.get(section, option)
except ConfigParser.NoOptionError, e:
# There is no such option in the setup.cfg
continue
if arg in MULTI:
# Special behaviour when we have a multi line option
if "\n" in in_cfg_value:
in_cfg_value = in_cfg_value.strip().split('\n')
else:
in_cfg_value = list((in_cfg_value,))
if arg == "requires" and use_setuptools:
arg = "install_requires"
new_requires_list = []
for version in in_cfg_value:
version = version.replace(' (', '')
version = version.replace(')', '')
new_requires_list.append(version)
in_cfg_value = new_requires_list
kwargs[arg] = in_cfg_value
if config.has_option("metadata", "description_file"):
kwargs["long_description"] = open(config.get("metadata",
"description_file")).read()
return kwargs
kwargs = generate_setuptools_kwargs_from_setup_cfg()
setup(**kwargs)