forked from pinard/Pymacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
118 lines (98 loc) · 4.18 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# This script was automatically generated by distutils2
import codecs
from distutils.core import setup
try:
from ConfigParser import RawConfigParser
except ImportError:
from configparser import RawConfigParser
def split_multiline(value):
"""Split a multiline string into a list, excluding blank lines."""
return [element for element in
(line.strip() for line in value.split('\n'))
if element]
def cfg_to_args(path='setup.cfg'):
"""Compatibility helper to use setup.cfg in setup.py.
This functions uses an existing setup.cfg to generate a dictionnary of
keywords that can be used by distutils.core.setup(**kwargs). It is used
by generate_setup_py.
*file* is the path to the setup.cfg file. If it doesn't exist,
PackagingFileError is raised.
"""
# XXX ** == needs testing
D1_D2_SETUP_ARGS = {"name": ("metadata",),
"version": ("metadata",),
"author": ("metadata",),
"author_email": ("metadata",),
"maintainer": ("metadata",),
"maintainer_email": ("metadata",),
"url": ("metadata", "home_page"),
"description": ("metadata", "summary"),
"long_description": ("metadata", "description"),
"download-url": ("metadata",),
"classifiers": ("metadata", "classifier"),
"platforms": ("metadata", "platform"), # **
"license": ("metadata",),
"requires": ("metadata", "requires_dist"),
"provides": ("metadata", "provides_dist"), # **
"obsoletes": ("metadata", "obsoletes_dist"), # **
"package_dir": ("files", 'packages_root'),
"packages": ("files",),
"scripts": ("files",),
"py_modules": ("files", "modules"), # **
}
MULTI_FIELDS = ("classifiers",
"platforms",
"requires",
"provides",
"obsoletes",
"packages",
"scripts",
"py_modules")
def has_get_option(config, section, option):
if config.has_option(section, option):
return config.get(section, option)
elif config.has_option(section, option.replace('_', '-')):
return config.get(section, option.replace('_', '-'))
else:
return False
# The real code starts here
config = RawConfigParser()
f = codecs.open(path, encoding='utf-8')
try:
config.readfp(f)
finally:
f.close()
kwargs = {}
for arg in D1_D2_SETUP_ARGS:
if len(D1_D2_SETUP_ARGS[arg]) == 2:
# The distutils field name is different than distutils2's
section, option = D1_D2_SETUP_ARGS[arg]
else:
# The distutils field name is the same thant distutils2's
section = D1_D2_SETUP_ARGS[arg][0]
option = arg
in_cfg_value = has_get_option(config, section, option)
if not in_cfg_value:
# There is no such option in the setup.cfg
if arg == 'long_description':
filenames = has_get_option(config, section, 'description-file')
if filenames:
filenames = split_multiline(filenames)
in_cfg_value = []
for filename in filenames:
fp = codecs.open(filename, encoding='utf-8')
try:
in_cfg_value.append(fp.read())
finally:
fp.close()
in_cfg_value = '\n\n'.join(in_cfg_value)
else:
continue
if arg == 'package_dir' and in_cfg_value:
in_cfg_value = {'': in_cfg_value}
if arg in MULTI_FIELDS:
# support multiline options
in_cfg_value = split_multiline(in_cfg_value)
kwargs[arg] = in_cfg_value
return kwargs
setup(**cfg_to_args())