-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
231 lines (182 loc) · 6.47 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
# -*- coding: utf-8 -*-
#
# This file is part of RestAuthCommon (https://common.restauth.net).
#
# RestAuthCommon is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# RestAuthCommon is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with RestAuthCommon. If
# not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
name = 'RestAuthCommon'
url = 'https://common.restauth.net'
import os
import re
import shutil
import sys
import unittest
from subprocess import PIPE
from subprocess import Popen
from distutils.command.clean import clean as _clean
from setuptools import Command
from setuptools import find_packages
from setuptools import setup
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
LATEST_RELEASE = '0.7.1'
requires = []
if sys.version_info < (2, 7):
print('ERROR: Sphinx requires at least Python 2.7 to run.')
sys.exit(1)
if 'python' not in sys.path:
sys.path.insert(0, 'python')
class build_doc(Command):
description = "Build API documentation."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
version = get_version()
sphinxopts = '-D release=%s -D version=%s' % (version, version)
os.environ['SPHINXOPTS'] = sphinxopts
os.environ['LATEST_RELEASE'] = LATEST_RELEASE
cmd = ['make', '-C', 'doc', 'html']
p = Popen(cmd)
p.communicate()
def get_version():
version = LATEST_RELEASE
if os.path.exists('.version'):
version = open('.version').readlines()[0]
elif os.path.exists('.git'): # get from git
cmd = ['git', 'describe', 'master']
p = Popen(cmd, stdout=PIPE)
version = p.communicate()[0].decode('utf-8')
elif os.path.exists('debian/changelog'): # building .deb
f = open('debian/changelog')
version = re.search('\((.*)\)', f.readline()).group(1)
f.close()
if ':' in version: # strip epoch:
version = version.split(':', 1)[1]
version = version.rsplit('-', 1)[0] # strip debian revision
return version.strip()
class version(Command):
description = "Print version and exit."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print(get_version())
class clean(_clean):
def run(self):
cmd = ['make', '-C', 'doc', 'clean', ]
p = Popen(cmd, stdout=PIPE)
p.communicate()
if os.path.exists('build'):
shutil.rmtree('build')
if os.path.exists('dist'):
shutil.rmtree('dist')
if os.path.exists('MANIFEST'):
os.remove('MANIFEST')
coverage = os.path.join('doc', 'coverage')
if os.path.exists(coverage):
print('rm -r %s' % coverage)
shutil.rmtree(coverage)
_clean.run(self)
class test(Command):
description = "Run test suite."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
suite = unittest.TestLoader().discover('python')
unittest.TextTestRunner().run(suite)
class coverage(Command):
description = "Run test suite and generate code coverage analysis."
user_options = []
def initialize_options(self):
self.dir = os.path.join('doc', 'coverage')
def finalize_options(self):
pass
def run(self):
try:
import coverage
except ImportError:
print("You need coverage.py installed.")
return
if not os.path.exists(self.dir):
os.makedirs(self.dir)
omit = [
'python/RestAuthCommon/test/*',
]
cov = coverage.coverage(cover_pylib=False, source=['python/RestAuthCommon', ],
branch=True, omit=omit)
if PY3:
cov.exclude('pragma: .*py2')
else:
cov.exclude('pragma: .*py3')
import bson
if hasattr(bson, 'BSON'):
cov.exclude('pragma: libbson')
else:
cov.exclude('pragma: pymongo')
cov.start()
suite = unittest.TestLoader().discover('python')
unittest.TextTestRunner().run(suite)
cov.stop()
cov.save()
cov.html_report(directory=self.dir)
setup(
name=name,
version=str(get_version()),
description='RestAuth shared library',
author='Mathias Ertl',
author_email='mati@restauth.net',
platforms='any',
url=url,
download_url='https://common.restauth.net/download/',
package_dir={str(''): str('python')},
packages=find_packages(str('python'), exclude=['RestAuthCommon.test', ]),
keywords=[],
install_requires=requires,
license="GNU General Public License (GPL) v3",
classifiers=[
"Development Status :: 6 - Mature",
"Environment :: Other Environment",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Operating System :: OS Independent",
"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",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Systems Administration :: Authentication/Directory",
],
cmdclass={
'build_doc': build_doc,
'clean': clean,
'coverage': coverage,
'version': version,
'test': test,
},
long_description="""RestAuthCommon is a small set of classes used by both `RestAuth server
<https://server.restauth.net>`_ and `RestAuthClient <https://python.restauth.net>`_ (`PyPI
<http://pypi.python.org/pypi/RestAuthClient/>`_)."""
)