-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
198 lines (170 loc) · 6.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
# vi:set ts=8 sts=4 sw=4 et tw=80:
"A Vim front-end to the gdb and pdb debuggers."
# Python 2-3 compatibility.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from io import open
import sys
import os
import subprocess
import importlib
from unittest import defaultTestLoader
try:
from setuptools import setup, Command
from setuptools.command.sdist import sdist as _sdist
SETUPTOOLS = True
except ImportError:
from distutils.core import setup, Command
from distutils.command.sdist import sdist as _sdist
SETUPTOOLS = False
from lib.clewn import __version__, PY3, PY33, PY34
with open('README.md') as f:
long_description = f.read()
cmdclass = {}
if not PY34:
import distutils
from distutils.util import byte_compile as _byte_compile
def byte_compile(files, *args, **kwds):
if 'dry_run' not in kwds or not kwds['dry_run']:
mapping = {
'import asyncio': 'import trollius as asyncio',
'yield from': 'yield asyncio.From',
}
for fname in files:
if fname[-3:] != '.py':
continue
substitute_in_file(fname, mapping)
return _byte_compile(files, *args, **kwds)
distutils.util.byte_compile = byte_compile
# When the wheel package is present, pip builds a wheel and, for some
# reason, this results in the byte compilation being done with the
# compileall module instead of distutils.util. Make bdist_wheel fail in
# order to prevent that.
try:
import wheel.bdist_wheel
except ImportError:
pass
else:
class bdist_wheel(wheel.bdist_wheel.bdist_wheel):
def run(self):
pass
cmdclass['bdist_wheel'] = bdist_wheel
def substitute_in_file(fname, mapping):
with open(fname, 'r+') as f:
updated = False
lines = []
for line in f:
for s in mapping:
idx = line.find(s)
if idx != -1:
updated = True
line = ''.join([line[:idx], mapping[s], line[idx+len(s):]])
lines.append(line)
if updated:
f.seek(0)
f.write(''.join(lines))
class sdist(_sdist):
"""Specialized sdister."""
def run(self):
import build_vimball
# Create the runtime_version.py module.
version = "2.3" #__version__ + '.' + subprocess.check_output(
#['g', 'id', '-i'], universal_newlines=True)
with open('lib/clewn/runtime_version.py', 'w') as f:
f.write('version = "%s"' % version.rstrip('+\n'))
if PY33:
build_vimball.main()
else:
# Do not rebuild the keymap files as this will fail on Python
# versions that do not support 'yield from'.
build_vimball.vimball()
_sdist.run(self)
NOTTESTS = ('test_support',)
class Test(Command):
"""Run the test suite.
"""
user_options = [(str(x), str(y), str(z)) for (x, y, z) in
(('test=', 't',
'run a comma separated list of tests, for example '
'"--test=simple,gdb", all the tests are run when this option'
' is not present'),
('prefix=', 'p', 'run only tests whose name starts with this prefix'),
('stop', 's', 'stop at the first test failure or error'),
('detail', 'd', 'detailed test output, each test case is printed'),
('pdb', 'b', 'debug a single test with pyclewn and pdb: start the'
' test with \'python setup.py test --test=gdb --pdb -p'
' test_021\''
' then start a Vim instance and run'
' \'Pyclewn pdb\''),)
]
def initialize_options(self):
self.test = None
self.prefix = None
self.stop = False
self.detail = False
self.pdb = False
def finalize_options(self):
self.test = self.test or 'pyclewn,simple,gdb,pdb'
def run (self):
"""Run the test suite."""
import testsuite.test_support as test_support
if self.pdb and self.test != ['test_gdb']:
print('One can only debug a gdb test case for now.')
return
testsuite = 'testsuite'
tests = ['test_' + t for t in self.test.split(',')]
if self.prefix:
defaultTestLoader.testMethodPrefix = self.prefix
for test in tests:
the_module = importlib.import_module('.%s' % test, testsuite)
suite = defaultTestLoader.loadTestsFromModule(the_module)
if self.pdb and (len(tests) > 1 or suite.countTestCases() > 1):
print('Only one test at a time can be debugged, use the'
' \'--test=\' and \'--prefix=\' options to set'
' this test.')
return
if test == 'test_gdb':
subprocess.check_call(['make', '-C', testsuite])
# run the test
print(the_module.__name__)
sys.stdout.flush()
test_support.run_suite(suite, self.detail, self.stop, self.pdb)
cmdclass.update(sdist=sdist, test=Test)
def main():
requirements = ['pdb-clone']
if not PY34:
requirements.append('trollius')
install_options = {
'cmdclass': cmdclass,
'packages': [str('clewn')],
'package_dir': {str(''): str('lib')},
'package_data': {str('clewn'):
['*.vim',
'runtime/pyclewn-%s.vmb' % __version__]},
# meta-data
'name': 'pyclewn',
'version': __version__,
'description': __doc__,
'long_description': long_description,
'platforms': 'all',
'license': 'GNU GENERAL PUBLIC LICENSE Version 2',
'author': 'Xavier de Gaye',
'author_email': 'xdegaye at users dot sourceforge dot net',
'url': 'http://pyclewn.sourceforge.net/',
'classifiers': [
'Topic :: Software Development :: Debuggers',
'Intended Audience :: Developers',
'Operating System :: Unix',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Development Status :: 6 - Mature',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
],
}
if SETUPTOOLS:
install_options['install_requires'] = requirements
setup(**install_options)
if __name__ == '__main__':
main()