-
Notifications
You must be signed in to change notification settings - Fork 15
/
setup.py
202 lines (156 loc) · 6.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
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
from __future__ import print_function
try:
from setuptools import setup, Extension, Feature
except ImportError:
sys.exit('ERROR: setuptools is required.\nTry using "pip install setuptools".')
import sys
import os
import fnmatch
import string
import numpy
# use README.rst for the long description
with open('README.rst') as fh:
long_description = fh.read()
# scan the script for the version string
version_file = 'ripyl/__init__.py'
version = None
with open(version_file) as fh:
try:
version = [line.split('=')[1].strip().strip("'") for line in fh if line.startswith('__version__')][0]
except IndexError:
pass
if version is None:
raise RuntimeError('Unable to find version string in file: {0}'.format(version_file))
cython_exists = False
cmdclass = {}
try:
from Cython.Distutils import build_ext
from Cython.Compiler.Version import version as cy_version
from pkg_resources import parse_version
# Check cython version
min_cy_version = '0.17'
if parse_version(cy_version) < parse_version(min_cy_version):
print('Older Cython version {} found. Need at least {}.'.format(cy_version, min_cy_version))
else:
print('Cython version {} found. Build enabled.'.format(cy_version))
cython_exists = True
cmdclass = {'build_ext': build_ext }
except ImportError:
pass
use_cython = False if '--without-cython' in sys.argv else True
cython_prebuild = False
def find_files(pattern, path):
''''Recursively search for files that match a specified pattern'''
result = []
for root, dirs, files in os.walk(path):
for name in files:
if fnmatch.fnmatch(name, pattern):
result.append(os.path.join(root, name))
return result
def find_cy_modules():
'''Find Cython modules'''
# Strip extensions from module names
cy_root = os.getcwd()
cy_files = [os.path.splitext(fn)[0] for fn in find_files('*.pyx', cy_root)]
#print('### cy_files:', cy_files)
# Convert slashes to dotted module notation
trans = string.maketrans('/\\', '..')
cy_modules = [f.translate(trans) for f in cy_files]
# Remove the leading porton of the paths up to "cython"
cy_modules = ['.'.join(m[m.find('cython'):].split('.')[1:]) for m in cy_modules]
return cy_modules
features = {}
if cython_exists:
# Find all cython modules
cy_module_names = find_cy_modules()
ext_modules = []
cy_root = ['ripyl', 'cython']
for mname in cy_module_names:
full_mname = '.'.join([e for x in [cy_root, [mname]] for e in x])
#mfile = '{}.pyx'.format(os.path.join(*[e for x in [cy_root, mname.split('.')] for e in x]))
mfile = '{}.pyx'.format(os.path.join(*full_mname.split('.')))
#print '### create extension', mname, full_name, mfile
ext_modules.append(Extension(full_mname, [mfile], extra_compile_args=['-O3']))
cython_prebuild = True if use_cython else False
features = {
'cython': Feature('Optional Cython modules', standard=True, ext_modules=ext_modules)
}
#print '$$$ use_cython', use_cython, cython_prebuild
#if 'install' in sys.argv:
# write_config(os.path.join('ripyl', 'ripyl.cfg'), use_cython, cython_prebuild)
# Subclass build_py command to add our own hook to write a config file
from setuptools.command.build_py import build_py as _build_py
class build_py(_build_py):
#user_options = _build_py.user_options
#boolean_options = _build_py.boolean_options
def initialize_options(self):
_build_py.initialize_options(self)
def finalize_options(self):
_build_py.finalize_options(self)
def run(self):
cfg_path = os.path.join(self.build_lib, 'ripyl', 'ripyl.cfg')
#print('$$$$ mkpath:', os.path.dirname(cfg_path))
self.mkpath(os.path.dirname(cfg_path))
print('Writing Ripyl configuration file: {}'.format(cfg_path))
self.write_config(cfg_path, use_cython, cython_prebuild)
# Read back the config file for verification
with open(cfg_path, 'r') as f:
for line in f:
print(' >', line.rstrip())
# Write additional config file into source directory to support
# in place testing from Jenkins.
#self.write_config(os.path.join('ripyl', 'ripyl.cfg'), use_cython, cython_prebuild)
return _build_py.run(self)
#def get_module_outfile(self, build_dir, package, module):
#print('$$$$ get outfile:', build_dir, package, module)
#return _build_py.get_module_outfile(self, build_dir, package, module)
def write_config(self, cfg_path, use_cython, cython_prebuild):
if sys.hexversion < 0x3000000:
import ConfigParser as cp
else:
import configparser as cp
config = cp.ConfigParser()
config.add_section('setup')
config.set('setup', 'use_cython', str(use_cython))
config.set('setup', 'cython_prebuild', str(cython_prebuild))
with open(cfg_path, 'w') as fh:
config.write(fh)
cmdclass['build_py'] = build_py
setup(name='ripyl',
version=version,
author='Kevin Thibedeau',
author_email='kevin.thibedeau@gmail.com',
url='http://kevinpt.github.io/ripyl',
download_url='http://kevinpt.github.io/ripyl',
description='A library for decoding serial data captured from oscilloscopes and logic analyzers',
long_description=long_description,
install_requires = ['scipy >= 0.11.0', 'numpy >= 1.7.0'],
packages = ['ripyl', 'ripyl.protocol', 'ripyl.protocol.infrared', 'ripyl.util',
'ripyl.cython', 'ripyl.cython.util'],
py_modules = ['ripyl_demo'],
cmdclass = cmdclass,
#ext_modules = extensions,
features = features,
entry_points = {
'console_scripts': ['ripyl_demo = ripyl_demo:main']
},
include_package_data = True,
package_data = {
'': ['*.cfg']
},
include_dirs = [numpy.get_include()],
use_2to3 = True,
test_suite = 'test',
keywords='serial decode oscilloscope logic analyzer',
license='LGPLv3',
classifiers=['Development Status :: 5 - Production/Stable',
'Operating System :: OS Independent',
'Intended Audience :: Science/Research',
'Natural Language :: English',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Software Development :: Libraries :: Python Modules'
]
)