-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
321 lines (269 loc) · 9.42 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
"""
The setup file for packaging pakit
"""
from __future__ import absolute_import, print_function
import fnmatch
import glob
import os
import shlex
import shutil
import subprocess
import sys
from setuptools import setup, find_packages, Command
ROOT = os.path.abspath(os.path.dirname(__file__))
if os.path.dirname(__file__) == '':
ROOT = os.getcwd()
def get_version():
"""
Read version from source code.
"""
v_line = None
with open(os.path.join(ROOT, 'pakit', '__init__.py')) as fin:
for line in fin:
if line.find('__version__') == 0:
v_line = line
break
return v_line.split()[2].replace("'", '', 2)
def get_short_desc():
"""
Fetch one line description from pakit's code.
"""
with open(os.path.join(ROOT, 'pakit', '__init__.py')) as fin:
d_line = fin.readlines()[1]
return d_line.split(':')[1].strip()
def get_long_desc():
"""
Creates a long description for pypi.
If possible, by converting the README.md with pandoc.
"""
rst_file = os.path.join(os.getcwd(), 'README.rst')
try:
subprocess.check_call(['python',
os.path.join(ROOT, 'docs', 'pand.py')])
with open(rst_file) as fin:
lines = fin.readlines()
return '\n' + ''.join(lines)
except subprocess.CalledProcessError:
return '\nFor more information: https://github.com/starcraftman/pakit'
finally:
try:
os.remove(rst_file)
except OSError:
pass
def rec_search(wildcard):
"""
Traverse all subfolders and match files against the wildcard.
Returns:
A list of all matching files absolute paths.
"""
matched = []
for dirpath, _, files in os.walk(os.getcwd()):
fn_files = [os.path.join(dirpath, fn_file) for fn_file
in fnmatch.filter(files, wildcard)]
matched.extend(fn_files)
return matched
class CleanCommand(Command):
"""
Equivalent of make clean.
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
pycs = ' '.join(rec_search('*.pyc'))
eggs = ' '.join(glob.glob('*.egg-info') + glob.glob('*.egg'))
cmd = 'rm -vrf .eggs .tox build dist {0} {1}'.format(eggs, pycs)
print('Executing: ' + cmd)
if raw_input('OK? y/n ').strip().lower()[0] == 'y':
subprocess.call(shlex.split(cmd))
class ReleaseCommand(Command):
"""
Prepare for twine upload by building distributions.
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
old_cwd = os.getcwd()
os.chdir(os.path.join(ROOT, 'docs'))
try:
subprocess.check_call(shlex.split('make man'))
except OSError:
print('Please install GNU Make.')
sys.exit(1)
os.chdir(ROOT)
self.copy_files_to(os.path.join('pakit', 'extra'))
cmds = [
'python setup.py sdist --formats=gztar,zip',
'python setup.py bdist_wheel --universal',
]
for cmd in cmds:
subprocess.call(shlex.split(cmd))
os.chdir(old_cwd)
def copy_files_to(self, target):
"""
Copy some files into the package for distribution.
"""
man_dir = os.path.join('docs', '_build', 'man')
to_move = ['CHANGELOG', 'DEMO.md', 'LICENSE', 'README.md'] + \
[os.path.join(man_dir, man) for man in os.listdir(man_dir)]
try:
shutil.rmtree(target)
except OSError:
pass
try:
os.makedirs(target)
except OSError:
pass
for fname in to_move:
shutil.copy(fname, target)
shutil.copytree('completion', os.path.join(target, 'completion'))
class InstallDeps(Command):
"""
Install dependencies to run & test.
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print('Installing runtime & testing dependencies')
cmd = 'pip install ' + ' '.join(RUN_DEPS + TEST_DEPS)
print('Will execute: ' + cmd)
subprocess.call(shlex.split(cmd))
class UMLDocs(Command):
"""
Generate UML class and module diagrams.
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def check_prereqs(self):
"""
Checks required programs.
"""
try:
with open(os.devnull, 'w') as dnull:
subprocess.check_call(shlex.split('pyreverse -h'),
stdout=dnull, stderr=dnull)
except OSError:
print('Missing pylint library (pyreverse). Please run:')
print('pip install pylint')
sys.exit(1)
try:
with open(os.devnull, 'w') as dnull:
subprocess.check_call(shlex.split('dot -V'),
stdout=dnull, stderr=dnull)
except OSError:
print('Missing graphviz library (dot). Please run:')
print('sudo apt-get install graphviz')
sys.exit(1)
def run(self):
self.check_prereqs()
old_cwd = os.getcwd()
os.chdir(ROOT)
cmds = [
'pyreverse pakit',
'dot -Tps classes_No_Name.dot -o class_diagram.ps',
'dot -Tps packages_No_Name.dot -o module_diagram.ps',
]
for cmd in cmds:
subprocess.call(shlex.split(cmd))
for fname in glob.glob('*.dot'):
os.remove(fname)
print('Diagrams available in: ' + ROOT)
print('Use any postscript viewer to open them.')
os.chdir(old_cwd)
MY_NAME = 'Jeremy Pallats / starcraft.man'
MY_EMAIL = 'N/A'
RUN_DEPS = ['argparse', 'pyyaml']
TEST_DEPS = ['coverage', 'flake8', 'mock', 'pytest', 'sphinx', 'tox']
setup(
name='pakit',
version=get_version(),
description=get_short_desc(),
long_description=get_long_desc(),
url='https://github.com/starcraftman/pakit',
author=MY_NAME,
author_email=MY_EMAIL,
maintainer=MY_NAME,
maintainer_email=MY_EMAIL,
license='BSD',
platforms=['any'],
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX :: Linux',
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Software Development :: Build Tools',
'Topic :: System :: Installation/Setup',
],
# What does your project relate to?
keywords='development',
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
# packages=find_packages(exclude=['venv', 'test*']),
packages=find_packages(exclude=['venv', 'tests*']),
# List run-time dependencies here. These will be installed by pip when
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=RUN_DEPS,
tests_require=TEST_DEPS,
# # List additional groups of dependencies here (e.g. development
# # dependencies). You can install these using the following syntax,
# # for example:
# # $ pip install -e .[dev,test]
extras_require={
'dev': ['pyandoc'],
'test': TEST_DEPS,
},
# # If there are data files included in your packages that need to be
# # installed, specify them here. If using Python 2.6 or less, then these
# # have to be included in MANIFEST.in as well.
package_data={
'pakit': ['extra/CHANGELOG', 'extra/DEMO.md', 'extra/LICENSE',
'extra/README.md', 'extra/pakit.1',
'extra/completion/pakit-bash.sh',
'extra/completion/README.md'],
},
# # Although 'package_data' is the preferred approach, in some case you may
# # need to place data files outside of your packages. See:
# # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa
# # In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
# data_files=[('my_data', ['data/data_file'])],
# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
entry_points={
'console_scripts': [
'pakit = pakit.main:main',
],
},
cmdclass={
'clean': CleanCommand,
'deps': InstallDeps,
'release': ReleaseCommand,
'uml': UMLDocs,
}
)