-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
372 lines (318 loc) · 9.65 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# coding=utf8
"""setup.py
Examples:
# simple setup.py
from setuptools import setup
setup(
name="my_other_package",
version="1.0.0",
author="me",
author_email="my.self@example.com",
url="https://github.com/me/my_other_package",
description="Descriptive",
license="Open-Source-Baybeeeeee-1.0",
install_requires=["setuptools"],
packages=["my_other_package"],
package_data={"my_other_package": ["py.typed", "bar.pyi"]},
data_files=[],
)
References:
https://packaging.python.org/guides/distributing-packages-using-setuptools/
https://setuptools.readthedocs.io/en/latest/setuptools.html
https://pypi.org/classifiers/
"""
from __future__ import absolute_import, print_function, unicode_literals
import re
import sys
# io.open is needed for projects that support Python 2.7. It ensures open()
# defaults to text mode with universal newlines, and accepts an argument to
# specify the text encoding. Python 3 only projects can skip this import.
#
# References:
# https://raw.githubusercontent.com/pypa/sampleproject/master/setup.py
from io import open
from os import path
from setuptools import find_packages, setup
ROOT = path.abspath(path.dirname(__file__))
MODULE_META_RE = re.compile(
r"^__(?P<name>.*)__ = ['\"](?P<value>[^'\"]*)['\"]", re.M
)
DEFAULT_LICENSE = "MIT"
def __find_meta(filepath):
content = __readfile(filepath)
match = MODULE_META_RE.findall(content)
if not match:
raise RuntimeError("error finding module meta in file: %s" % filepath)
return dict(match)
def __find_readme(basename="README", extensions=("rst", "md", "txt", "")):
"""Locate the Projects README file and determine its content type.
Args:
basename (str): README File basename.
extensions (list of str): List of README file extensions.
Returns:
(tuple of str,str): Tuple containing the file content and content type.
"""
def _readme_content_type(_filename, _default=None):
"""Determine README file content type.
Notes:
Currently based off file extension.
Args:
_filename (str): README file name.
_default (str): Default content type.
Returns:
str: Content type of the README file.
"""
if _filename.endswith(".rst"):
return "text/x-rst"
if _filename.endswith(".md"):
return "text/x-markdown"
if _filename.endswith(".txt"):
return "text"
return _default
long_description = None
long_description_content_type = None
for ext in extensions:
filename = (
basename
if not ext or ext is None
else "{0}.{1}".format(basename, ext)
)
filepath = path.join(ROOT, filename)
if path.exists(filepath):
long_description = __readfile(filepath)
long_description_content_type = _readme_content_type(filename, "text")
break
return long_description, long_description_content_type
def __iterlines(filepath, **kwargs):
if "b" not in kwargs.get("mode", ""):
kwargs.setdefault("encoding", "utf8")
with open(filepath, **kwargs) as fd:
for line in filter(None, (line.strip() for line in fd)):
yield line
def __readfile(filepath, **kwargs):
if "b" not in kwargs.get("mode", ""):
kwargs.setdefault("encoding", "utf8")
with open(filepath, **kwargs) as fd:
return fd.read()
def __readlines(filepath, **kwargs):
return list(__iterlines(filepath, **kwargs))
# class MakeCleanCommand(Command):
# """A custom command to delete all generated doc files.
# """
# description = "run 'make --clean' to delete generated doc files"
# user_options = [
# # The format is (long option, short option, description).
# ('build-dir=', None, 'path to docs build dir'),
# ]
#
# def initialize_options(self):
# """Set default values for options.
# """
# # Each user option must be listed here with their default value.
# # noinspection PyAttributeOutsideInit
# self.build_dir = 'docs'
#
# def finalize_options(self):
# """Post-process options.
# """
# if self.build_dir:
# assert path.exists(self.build_dir), (
# 'Docs build dir %s does not exist.' % self.build_dir
# )
#
# def run(self):
# """Run command.
# """
# command = (
# "cd %(build_dir)s || echo directory %(build_dir)s does not exist. | "
# "exit 1; make clean; cd .." % {"build_dir": self.build_dir}
# )
# self.announce('Running command: make --clean', level=INFO)
# check_call(command, shell=True)
# self.announce('Generated doc files cleaned from dir: %s' % self.build_dir,
# level=INFO)
#
#
# class RunTestsCommand(Command):
# """A custom command to run tests.
# """
# description = "run 'scripts/run-tests' to run tests"
# user_options = [
# # The format is (long option, short option, description).
# ('test-runner', None, 'path to test runner script'),
# ]
#
# def initialize_options(self):
# """Set default values for options.
# """
# # Each user option must be listed here with their default value.
# # noinspection PyAttributeOutsideInit
# self.test_runner = 'pytest'
#
# def finalize_options(self):
# """Post-process options.
# """
# if not self.test_runner:
# assert self.test_runner, 'Missing Test Runner.'
#
# def run(self):
# """Run Command.
# """
# command = "%s" % self.test_runner
# self.announce('Running test script: %s' % command, level=INFO)
# try:
# check_call(command, shell=True)
# except CalledProcessError as e:
# self.announce("%s" % e, level=ERROR)
PACKAGES = find_packages(exclude=("doc*", "example*", "script*", "test*"))
NAME = PACKAGES[0]
METADATA = __find_meta(path.join(ROOT, NAME, "__version__.py"))
AUTHOR = METADATA.get("author")
AUTHOR_EMAIL = METADATA.get("author_email")
CLASSIFIERS = [
"Development Status :: 2 - Pre-Alpha",
"Natural Language :: English",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Software Development :: Libraries :: Python Modules"
]
DESCRIPTION = METADATA.get("description")
ENTRY_POINTS = {
"console_scripts": [
"{0}={0}.__main__:main".format(NAME)
]
}
EXTRAS_REQUIRE = {
"docs": [
"sphinx",
"sphinxcontrib-napoleon",
"guzzle_sphinx_theme"
],
"tests": [
"check-manifest",
"coverage",
"pycodestyle",
"pytest",
"pytest-cov",
"pytest-html",
"tox",
"tox-travis",
"twine",
"wheel"
],
":python_version==\"2.6\"": [
"ordereddict==1.1",
"simplejson==3.3.0"
],
":python_version==\"2.7\"": [
"ipaddress"
],
}
INCLUDE_PACKAGE_DATA = False
KEYWORDS = "{0} template".format(NAME)
LICENSE = METADATA.get("license", DEFAULT_LICENSE)
LONG_DESCRIPTION, LONG_DESCRIPTION_CONTENT_TYPE = __find_readme()
PACKAGE_DATA = {}
PLATFORMS = "Posix; MacOS X; Windows"
REQUIREMENTS = __readlines(path.join(ROOT, "requirements.txt"))
SCRIPTS = []
TITLE = METADATA.get("title", NAME)
URL = METADATA.get("url")
VERSION = METADATA["version"]
ZIP_SAFE = False
PROJECT_URLS = {
# TODO: support more than github-based repositories.
# - bitbucket
# - gitlab
# - etc...
"Source": URL,
"Tracker": "{0}/issues".format(URL)
}
# setup options
setup_options = dict(
author=AUTHOR,
author_email=AUTHOR_EMAIL,
classifiers=CLASSIFIERS,
description=DESCRIPTION,
entry_points=ENTRY_POINTS,
extras_require=EXTRAS_REQUIRE,
include_package_data=INCLUDE_PACKAGE_DATA,
install_requires=REQUIREMENTS,
keywords=KEYWORDS,
license=LICENSE,
long_description=LONG_DESCRIPTION,
long_description_content_type=LONG_DESCRIPTION_CONTENT_TYPE,
name=NAME,
packages=PACKAGES,
package_data=PACKAGE_DATA,
platforms=PLATFORMS,
project_urls=PROJECT_URLS,
scripts=SCRIPTS,
url=URL,
version=VERSION,
zip_safe=ZIP_SAFE
)
# compile module as executable
if "py2exe" in sys.argv:
# TODO: Test py2exe References:
# https://github.com/aws/aws-cli/blob/develop/setup.py
import py2exe # noqa
# py2exe specific options
setup_options["options"] = {
"py2exe": {
"optimize": 0,
"skip_archive": True,
"dll_excludes": [
"crypt32.dll"
],
"packages": [
"docutils",
"urllib",
"httplib",
"HTMLParser",
NAME,
"ConfigParser",
"xml.etree",
"pipes"
],
}
}
setup_options["console"] = [
path.join("bin", NAME)
]
# run setup
setup(
author=AUTHOR,
author_email=AUTHOR_EMAIL,
classifiers=CLASSIFIERS,
description=DESCRIPTION,
entry_points=ENTRY_POINTS,
extras_require=EXTRAS_REQUIRE,
include_package_data=INCLUDE_PACKAGE_DATA,
install_requires=REQUIREMENTS,
keywords=KEYWORDS,
license=LICENSE,
long_description=LONG_DESCRIPTION,
long_description_content_type=LONG_DESCRIPTION_CONTENT_TYPE,
name=NAME,
packages=PACKAGES,
package_data=PACKAGE_DATA,
platforms=PLATFORMS,
project_urls=PROJECT_URLS,
scripts=SCRIPTS,
url=URL,
version=VERSION,
zip_safe=ZIP_SAFE
)