forked from AFDudley/equanimity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·100 lines (87 loc) · 3.22 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
#!/usr/bin/env python
from __future__ import print_function
import subprocess
import shlex
import os
import sys
from setuptools import setup, Command
pypy = False
if 'pypy' in sys.version.lower():
pypy = True
class Test(Command):
''' Test Equanimity application with the following:
pep8 conformance (style)
pyflakes validation (static analysis)
nosetests (code tests) [--with-integration] [--run-failed]
'''
description = 'Test Equanimity source code'
user_options = [('run-failed', None,
'Run only the previously failed tests.'),
('nose-only', None, 'Run only the nose tests.')]
boolean_options = ['run-failed', 'nose-only']
def initialize_options(self):
self.run_failed = False
# Disable the flake8 tests in pypy due to bug in pep8 module
self.nose_only = pypy
#self.with_integration = False
self.flake8 = 'flake8 server/ equanimity/ tests/ setup.py'
def finalize_options(self):
pass
def _no_print_statements(self):
cmd = 'grep -rnw print server/ equanimity/'
p = subprocess.Popen(shlex.split(cmd), close_fds=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
err = p.stderr.read().strip()
if err:
msg = 'ERROR: stderr not empty for print statement grep: {0}'
print(msg.format(err))
raise SystemExit(-1)
output = p.stdout.read().strip()
if output:
print('ERROR: Found print statements in source code:')
print(output)
raise SystemExit(-1)
def _get_py_files(self, basepath, subpath=''):
files = []
badchars = ['.', '_', '~']
path = os.path.join(basepath, subpath)
for f in os.listdir(path):
if (not f.endswith('.py') or
any(map(lambda c: f.startswith(c), badchars))):
continue
files.append(os.path.join(subpath, f))
return files
def _get_nose_command(self):
nosecmd = ('nosetests -v -w tests/ --all-modules '
'--with-coverage --cover-package=server '
'--cover-package=equanimity --cover-package=tools.client '
'--disable-docstring ')
if self.run_failed:
nosecmd += ' --failed'
nose = ' '.join(shlex.split(nosecmd))
return nose
def _remove_coverage(self):
fn = '.coverage'
if os.path.exists(fn):
os.remove(fn)
def run(self):
# TODO -- check that flake8, nosetests are installed
cmds = [self._get_nose_command()]
if not self.nose_only:
#self._no_print_statements()
self._remove_coverage()
cmds = [self.flake8] + cmds
cmds = filter(bool, cmds)
if not cmds:
print('No action taken.')
SystemExit(-2)
try:
list(map(subprocess.check_call, map(shlex.split, cmds)))
except subprocess.CalledProcessError:
raise SystemExit(-1)
raise SystemExit(0)
setup(name='equanimity',
platforms='any',
packages=['server', 'equanimity', 'config'],
install_requires=[],
cmdclass=dict(test=Test))