-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
157 lines (127 loc) · 4.49 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
"""
This package installs a pth file that enables the coveragepy process_startup
feature in this python prefix/virtualenv in subsequent runs.
See: http://nedbatchelder.com/code/coverage/subprocess.html
Demo::
$ virtualenv tmpenv
$ . tmpenv/bin/activate
$ pip install coverage-enable-subprocess
$ touch .coveragerc
$ export COVERAGE_PROCESS_START=$PWD/.coveragerc
$ echo 'print("oh, hi!")' > ohhi.py
$ python ohhi.py
oh, hi!
$ coverage report
Name Stmts Miss Cover
-----------------------------------------------------
/etc/python2.6/sitecustomize.py 5 1 80%
ohhi.py 1 0 100%
tmpenv/lib/python2.6/site.py 433 392 9%
-----------------------------------------------------
TOTAL 439 393 10%
For projects that need to cd during their test runs, and run many processes in parallel,
I ensure a ``$TOP`` variable is exported, and I use this .coveragerc::
[run]
parallel = True
branch = True
data_file = $TOP/.coverage
[report]
exclude_lines =
# Have to re-enable the standard pragma
\\#.*pragma:\\s*no.?cover
# we can't get coverage for functions that don't return:
\\#.*never returns
\\#.*doesn't return
# Don't complain if tests don't hit defensive assertion code:
^\\s*raise Impossible\\b
^\\s*raise AssertionError\\b
^\\s*raise NotImplementedError\\b
^\\s*return NotImplemented\\b
# Don't complain if tests don't hit re-raise of unexpected errors:
^\\s*raise$
# if main is covered, we're good:
^\\s*exit\\(main\\(\\)\\)$
show_missing = True
[html]
directory = $TOP/coverage-html
# vim:ft=dosini
"""
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
from distutils import log
from setuptools import setup
from setuptools.command.install import install as orig_install
PTH = '''\
try:
import coverage
# coverage throws OSError when $PWD does not exist
except (ImportError, OSError):
pass
else:
coverage.process_startup()
'''
DOC = __doc__
class Install(orig_install):
"""
default semantics for install.extra_path cause all installed modules to go
into a directory whose name is equal to the contents of the .pth file.
All that was necessary was to remove that one behavior to get what you'd
generally want.
"""
# pylint:disable=no-member,attribute-defined-outside-init,access-member-before-definition
def initialize_options(self):
orig_install.initialize_options(self)
name = self.distribution.metadata.name
contents = 'import sys; exec(%r)\n' % PTH
self.extra_path = (name, contents)
def finalize_options(self):
orig_install.finalize_options(self)
from os.path import relpath, join
install_suffix = relpath(self.install_lib, self.install_libbase)
if install_suffix == '.':
log.info('skipping install of .pth during easy-install')
elif install_suffix == self.extra_path[1]:
self.install_lib = self.install_libbase
log.info(
"will install .pth to '%s.pth'",
join(self.install_lib, self.extra_path[0]),
)
else:
raise AssertionError(
'unexpected install_suffix',
self.install_lib, self.install_libbase, install_suffix,
)
def main():
"""the entry point"""
setup(
name=str('coverage_enable_subprocess'),
version='1.0',
url="https://github.com/bukzor/coverage_enable_subprocess",
license="MIT",
author="Buck Evan",
author_email="[email protected]",
description="enable python coverage for subprocesses",
long_description=DOC,
zip_safe=False,
classifiers=[
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'License :: OSI Approved :: MIT License',
],
install_requires=[
'coverage',
],
cmdclass={
'install': Install,
},
options={
'bdist_wheel': {
'universal': 1,
},
},
)
if __name__ == '__main__':
exit(main())