Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
257 lines (196 loc) · 7.16 KB
/
Copy pathsetup.py
File metadata and controls
257 lines (196 loc) · 7.16 KB
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
#!/usr/bin/env python
import setuptools
import os
import sys
import subprocess
_rootdir = os.path.dirname(os.path.abspath(__file__))
_plugindir = '{}/plugin'.format(_rootdir)
sys.path.insert(0, _plugindir)
import taskmage2
__version__ = taskmage2.__version__
class VimRequirements(object):
requirements = [
'https://github.com/junegunn/vader.vim',
'https://github.com/nanotech/jellybeans.vim',
]
def install(self):
""" Installs vim requirements defined in :py:attr:`requirements` .
"""
self._create_testdeps_dir()
for url in self.requirements:
self._clone_requirement(url)
def _create_testdeps_dir(self):
# create test_deps dir
if not os.path.isdir('.test_deps'):
os.makedirs('.test_deps')
def _clone_requirement(self, url):
# clone repo
basename = os.path.basename(url)
rootdir = '.test_deps/{}'.format(basename)
gitdir = '.test_deps/{}/.git'.format(basename)
if not os.path.exists(gitdir):
cmds = ['git', 'clone', url, rootdir]
subprocess.call(cmds, universal_newlines=True)
# =============
# Test Commands
# =============
class VimTest(setuptools.Command):
""" ``python setup.py vimtest`` installs vader/jellybeans vim plugins and executes tests.
"""
description = 'run vimfile tests (using Vader.vim)'
user_options = [
('interactive', 'i', 'instead of printing to stdout, runs vader interactively in vim')
]
requirements = VimRequirements()
def initialize_options(self):
self.interactive = False
def finalize_options(self):
pass
def run(self):
sys.exit(self.run_static(self.interactive))
@classmethod
def run_static(cls, interactive=False):
cls.requirements.install()
if interactive:
cmds = ['nvim', '-Nu', 'tests/resources/vimrc', '+Vader', 'tests/viml/*']
else:
cmds = ['nvim', '-Nu', 'tests/resources/vimrc', '-c', 'Vader! tests/viml/*'] # output to console
returncode = subprocess.call(cmds, universal_newlines=True)
return returncode
class TotalTest(setuptools.Command):
description = 'run tests for both vim and python'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# run python tests
cmds = [sys.executable, 'setup.py', 'test_python']
py_returncode = subprocess.call(cmds, universal_newlines=True)
# run vim tests
vim_returncode = VimTest.run_static()
# return fail if any of the above failed.
if any([x != 0 for x in (py_returncode, vim_returncode)]):
sys.exit(1)
sys.exit(0)
# ======================
# Test-Coverage Commands
# ======================
class VimCoverage(setuptools.Command):
""" ``python setup.py vimtest`` installs vader/jellybeans vim plugins and executes tests.
Notes:
Requires that you have installed covimerage:
Example:
.. code-block:: bash
python setup.py vim-coverage # print coverage to stdout
python setup.py vim-coverage --action=run # print coverage to stdout
"""
description = 'print vimfile test-coverage (using covimerage)'
user_options = []
requirements = VimRequirements()
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
sys.exit(self.run_static())
@classmethod
def run_static(cls):
cls.requirements.install()
cls._check_path_for_covimerage()
returncode = cls._run_coverage()
return returncode
@classmethod
def _check_path_for_covimerage(cls):
try:
import covimerage
except(ImportError):
print('WARNING: covimerage is not installed, command may fail\n'
'run: pip install covimerage')
@classmethod
def _run_coverage(cls):
cmds = ['covimerage', 'run',
'--source', 'autoload',
'--source', 'plugin',
'vim', '-Nu', 'tests/resources/vimrc', '-c', 'Vader! tests/viml/*']
returncode = subprocess.call(cmds, universal_newlines=True)
return returncode
def _run_xml(self):
cmds = ['covimerage', 'xml']
subprocess.call(cmds, universal_newlines=True)
class PythonCoverage(setuptools.Command):
""" ``python setup.py py-coverage`` prints python-core coverage.
Notes:
Requires that you have installed covimerage:
Example:
.. code-block:: bash
python setup.py py-coverage # print coverage to stdout
"""
description = 'print python-file test-coverage (using pytest-cov)'
user_options = []
def __init__(self, *args, **kwargs):
setuptools.Command.__init__(self, *args, **kwargs)
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
sys.exit(self.run_static())
@staticmethod
def run_static():
cmds = [sys.executable, 'setup.py', 'test_python',
'--addopts', '--cov=plugin/taskmage2']
returncode = subprocess.call(cmds, universal_newlines=True)
return returncode
class TotalCoverage(setuptools.Command):
description = 'get combined coverage of both python AND vim files'
user_options = [
('xml', None, 'in addition to measuring both source-coverage types, produces coverage.xml file'),
('html', None, 'in addition to measuring both source-coverage types, produces htmlcov directory'),
]
def initialize_options(self):
self.xml = False
self.html = False
def finalize_options(self):
self.xml = '--xml' in sys.argv
def run(self):
VimCoverage.run_static()
PythonCoverage.run_static()
# combine both coverage files into one
cmds = ['coverage', 'combine', '.coverage', '.coverage_covimerage']
returncode = subprocess.call(cmds, universal_newlines=True)
if returncode != 0:
print('ERROR: covarage command failed: {}'.format(repr(cmds)))
# (optionally) render xml file
if self.xml:
cmds = ['coverage', 'xml']
sys.exit(subprocess.call(cmds, universal_newlines=True))
if self.html:
cmds = ['coverage', 'html']
sys.exit(subprocess.call(cmds, universal_newlines=True))
def read_requirements(filepath):
""" Reads a requirements.txt file into a list suitable for ``setuptools.setup(requires=)``
"""
with open(filepath, 'r') as fd:
return fd.read().split('\n')
# see python setup.py --help-commands for all commands
setuptools.setup(
name='taskmage',
version=__version__,
author='Will Pittman',
license='BSD',
install_requires=[],
setup_requires=[
'pytest-runner',
],
tests_require=read_requirements('tests/requirements.txt'),
cmdclass={
# test_python (configured in setup.cfg)
'test_vim': VimTest,
'test': TotalTest,
'coverage_vim': VimCoverage,
'coverage_python': PythonCoverage,
'coverage': TotalCoverage,
}
)