forked from arskom/spyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·309 lines (237 loc) · 8.52 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
#!/usr/bin/env python
#encoding: utf8
from __future__ import print_function
import io
import os
import re
import sys
import inspect
from glob import glob
from itertools import chain
from os.path import join, dirname, abspath
from setuptools import setup
from setuptools import find_packages
from setuptools.command.test import test as TestCommand
try:
import colorama
colorama.init()
from colorama import Fore
RESET = Fore.RESET
GREEN = Fore.GREEN
RED = Fore.RED
except ImportError:
RESET = ''
GREEN = ''
RED = ''
IS_PYPY = '__pypy__' in sys.builtin_module_names
OWN_PATH = abspath(inspect.getfile(inspect.currentframe()))
EXAMPLES_DIR = join(dirname(OWN_PATH), 'examples')
PYVER = ''.join([str(i) for i in sys.version_info[:2]])
with io.open(os.path.join(os.path.dirname(__file__), 'spyne', '__init__.py'), 'r') as v:
VERSION = re.match(r".*__version__ = '(.*?)'", v.read(), re.S).group(1)
SHORT_DESC="A transport and architecture agnostic rpc library that focuses on" \
" exposing public services with a well-defined API."
LONG_DESC = """Homepage: http://spyne.io
Spyne aims to save the protocol implementers the hassle of
implementing their own remote procedure call api and the application programmers
the hassle of jumping through hoops just to expose their services using multiple
protocols and transports.
"""
try:
os.stat('CHANGELOG.rst')
with io.open('CHANGELOG.rst', 'rb') as f:
LONG_DESC += u"\n\n" + f.read().decode('utf8')
except OSError:
pass
###############################
# Testing stuff
def call_test(f, a, tests, env={}):
import spyne.test
from multiprocessing import Process, Queue
tests_dir = os.path.dirname(spyne.test.__file__)
if len(tests) > 0:
a.extend(chain(*[glob(join(tests_dir, test)) for test in tests]))
queue = Queue()
p = Process(target=_wrapper(f), args=[a, queue, env])
p.start()
p.join()
ret = queue.get()
if ret == 0:
print(tests or a, "OK")
else:
print(tests or a, "FAIL")
print()
return ret
def _wrapper(f):
import traceback
def _(args, queue, env):
print("env:", env)
for k, v in env.items():
os.environ[k] = v
try:
retval = f(args)
except SystemExit as e:
retval = e.code
except BaseException as e:
print(traceback.format_exc())
retval = 1
queue.put(retval)
return _
def run_tests_and_create_report(report_name, *tests, **kwargs):
import spyne.test
import pytest
if os.path.isfile(report_name):
os.unlink(report_name)
tests_dir = os.path.dirname(spyne.test.__file__)
args = [
'--verbose',
'--cov-report=', '--cov', 'spyne',
'--cov-append',
'--tb=short',
'--junitxml=%s' % report_name,
]
args.extend('--{0}={1}'.format(k, v) for k, v in kwargs.items())
args.extend(chain(*[glob("%s/%s" % (tests_dir, test)) for test in tests]))
return pytest.main(args)
_ctr = 0
def call_pytest(*tests, **kwargs):
global _ctr
_ctr += 1
file_name = 'test_result.%d.xml' % _ctr
os.environ['COVERAGE_FILE'] = '.coverage.%d' % _ctr
return run_tests_and_create_report(file_name, *tests, **kwargs)
def call_pytest_subprocess(*tests, **kwargs):
global _ctr
import pytest
_ctr += 1
file_name = 'test_result.%d.xml' % _ctr
if os.path.isfile(file_name):
os.unlink(file_name)
# env = {'COVERAGE_FILE': '.coverage.%d' % _ctr}
env = {}
args = [
'--verbose',
'--cov-append',
'--cov-report=',
'--cov', 'spyne',
'--tb=line',
'--junitxml=%s' % file_name
]
args.extend('--{0}={1}'.format(k, v) for k, v in kwargs.items())
return call_test(pytest.main, args, tests, env)
def call_tox_subprocess(env):
import tox.session
args = ['-e', env]
return call_test(tox.session.main, args, [])
def call_coverage():
import coverage.cmdline
# coverage.cmdline.main(['combine'])
# call_test(coverage.cmdline.main, ['combine'], [])
call_test(coverage.cmdline.main, ['xml', '-i'], [])
return 0
class ExtendedTestCommand(TestCommand):
"""TestCommand customized to project needs."""
user_options = TestCommand.user_options + [
('capture=', 'k', "py.test output capture control (see py.test "
"--capture)"),
]
def initialize_options(self):
TestCommand.initialize_options(self)
self.capture = 'fd'
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
class RunTests(ExtendedTestCommand):
def run_tests(self):
cfn = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),
'tox.ini')
from collections import OrderedDict
djenvs = tuple(OrderedDict(((k, None) for k in
re.findall('py%s-dj[0-9]+' % PYVER,
open(cfn, 'rb').read().decode('utf8')))).keys())
ret = 0
tests = [
'interface', 'model', 'multipython', 'protocol', 'util',
'interop/test_pyramid.py',
'interop/test_soap_client_http_twisted.py',
'transport/test_msgpack.py'
'test_null_server.py',
'test_service.py',
'test_soft_validation.py',
'test_sqlalchemy.py',
'test_sqlalchemy_deprecated.py',
]
print("Test stage 1: Unit tests")
ret = call_pytest_subprocess(*tests, capture=self.capture) or ret
print("\nTest stage 2: End-to-end tests")
ret = call_pytest_subprocess('interop/test_httprpc.py',
capture=self.capture) or ret
ret = call_pytest_subprocess('interop/test_soap_client_http.py',
capture=self.capture) or ret
ret = call_pytest_subprocess('interop/test_soap_client_zeromq.py',
capture=self.capture) or ret
# excluding PyPy as it chokes here on LXML
if not IS_PYPY:
ret = call_pytest_subprocess('interop/test_suds.py',
capture=self.capture) or ret
ret = call_pytest_subprocess('interop/test_zeep.py',
capture=self.capture) or ret
print("\nTest stage 3: Tox-managed tests")
for djenv in djenvs:
ret = call_tox_subprocess(djenv) or ret
if ret == 0:
print(GREEN + "All that glisters is not gold." + RESET)
else:
print(RED + "Something is rotten in the state of Denmark." + RESET)
print ("Generating coverage.xml")
call_coverage()
raise SystemExit(ret)
# Testing stuff ends here.
###############################
setup(
name='spyne',
packages=find_packages(),
version=VERSION,
description=SHORT_DESC,
long_description=LONG_DESC,
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
#'Programming Language :: Python :: Implementation :: Jython',
'Programming Language :: Python :: Implementation :: PyPy',
'Operating System :: OS Independent',
'Natural Language :: English',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
keywords='soap wsdl wsgi zeromq rest rpc json http msgpack xml'
' django pyramid postgresql sqlalchemy twisted yaml'.split(),
author='Burak Arslan',
author_email='[email protected]',
maintainer='Burak Arslan',
maintainer_email='[email protected]',
url='http://spyne.io',
license='LGPL-2.1-or-later',
zip_safe=False,
install_requires=[
'pytz',
],
entry_points={
'console_scripts': [
'sort_wsdl=spyne.test.sort_wsdl:main',
]
},
cmdclass={
'test': RunTests,
},
)