forked from google/openhtf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
229 lines (198 loc) · 7.11 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
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
# Copyright 2014 Google Inc. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Setup script for OpenHTF."""
import errno
import glob
import os
import platform
import subprocess
import sys
from distutils.command.build import build
from distutils.command.clean import clean
from distutils.cmd import Command
from setuptools import find_packages
from setuptools import setup
from setuptools.command.test import test
class CleanCommand(clean):
"""Custom logic for the clean command."""
def run(self):
clean.run(self)
targets = [
'./dist',
'./*.egg-info',
'./openhtf/output/proto/*_pb2.py',
'./openhtf/**/*.pyc',
]
os.system('shopt -s globstar; rm -vrf %s' % ' '.join(targets))
class BuildProtoCommand(Command):
"""Custom setup command to build protocol buffers."""
description = 'Builds the proto files into python files.'
user_options = [('protoc=', None, 'Path to the protoc compiler.'),
('protodir=', None, 'Path to protobuf install.'),
('indir=', 'i', 'Directory containing input .proto files.'),
('outdir=', 'o', 'Where to output .py files.')]
def initialize_options(self):
self.skip_proto = False
try:
prefix = subprocess.check_output(
'pkg-config --variable prefix protobuf'.split()).strip().decode('utf-8')
except (subprocess.CalledProcessError, OSError):
if platform.system() == 'Linux':
# Default to /usr?
prefix = '/usr'
elif platform.system() in ['Mac', 'Darwin']:
# Default to /usr/local for Homebrew
prefix = '/usr/local'
else:
print('Warning: mfg-inspector output is not fully implemented for '
'Windows. OpenHTF will be installed without it.')
self.skip_proto = True
maybe_protoc = os.path.join(prefix, 'bin', 'protoc')
if os.path.isfile(maybe_protoc) and os.access(maybe_protoc, os.X_OK):
self.protoc = maybe_protoc
else:
print('Warning: protoc not found at %s' % maybe_protoc)
print('setup will attempt to run protoc with no prefix.')
self.protoc = 'protoc'
self.protodir = os.path.join(prefix, 'include')
self.indir = os.getcwd()
self.outdir = os.getcwd()
def finalize_options(self):
pass
def run(self):
if self.skip_proto:
print('Skipping building protocol buffers.')
return
# Build regular proto files.
protos = glob.glob(
os.path.join(self.indir, 'openhtf', 'output', 'proto', '*.proto'))
if protos:
print('Attempting to build proto files:\n%s' % '\n'.join(protos))
cmd = [
self.protoc,
'--proto_path', self.indir,
'--proto_path', self.protodir,
'--python_out', self.outdir,
] + protos
try:
subprocess.check_call(cmd)
except OSError as e:
if e.errno == errno.ENOENT:
print('Could not find the protobuf compiler at \'%s\'' % self.protoc)
if sys.platform.startswith('linux'):
print('On many Linux systems, this is fixed by installing the '
'"protobuf-compiler" and "libprotobuf-dev" packages.')
elif sys.platform == 'darwin':
print('On Mac, protobuf is often installed via homebrew.')
raise
except subprocess.CalledProcessError:
print('Could not build proto files.')
print('This could be due to missing helper files. On many Linux '
'systems, this is fixed by installing the '
'"libprotobuf-dev" package.')
raise
else:
print('Found no proto files to build.')
# Make building protos part of building overall.
build.sub_commands.insert(0, ('build_proto', None))
INSTALL_REQUIRES = [
'colorama>=0.3.9,<1.0',
'contextlib2>=0.5.1,<1.0',
'future>=0.16.0',
'mutablerecords>=0.4.1,<2.0',
'oauth2client>=1.5.2,<2.0',
'protobuf>=3.6.0,<4.0',
'PyYAML>=3.13,<4.0',
'pyOpenSSL>=17.1.0,<18.0',
'sockjs-tornado>=1.0.3,<2.0',
'tornado>=4.3,<5.0',
'six>=1.12.0',
]
# Not all versions of setuptools support semicolon syntax for specifying
# platform-specific dependencies, so we do it the old school way.
if sys.version_info < (3,4):
INSTALL_REQUIRES.append('enum34>=1.1.2,<2.0')
class PyTestCommand(test):
# Derived from
# https://github.com/chainreactionmfg/cara/blob/master/setup.py
user_options = [
('pytest-args=', None, 'Arguments to pass to py.test'),
('pytest-cov=', None, 'Enable coverage. Choose output type: '
'term, html, xml, annotate, or multiple with comma separation'),
]
def initialize_options(self):
test.initialize_options(self)
self.pytest_args = ['test']
self.pytest_cov = None
def finalize_options(self):
test.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
self.run_command('build_proto')
import pytest
cov = []
if self.pytest_cov is not None:
outputs = []
for output in self.pytest_cov.split(','):
outputs.extend(['--cov-report', output])
cov = ['--cov', 'openhtf'] + outputs
sys.argv = [sys.argv[0]]
print('invoking pytest.main with %s' % (self.pytest_args + cov))
sys.exit(pytest.main(self.pytest_args + cov))
setup(
name='openhtf',
version='1.4.4',
description='OpenHTF, the open hardware testing framework.',
author='John Hawley',
author_email='[email protected]',
maintainer='Joe Ethier',
maintainer_email='[email protected]',
packages=find_packages(exclude='examples'),
package_data={'openhtf': ['output/proto/*.proto',
'output/web_gui/dist/*.*',
'output/web_gui/dist/css/*',
'output/web_gui/dist/js/*',
'output/web_gui/dist/img/*',
'output/web_gui/*.*']},
cmdclass={
'build_proto': BuildProtoCommand,
'clean': CleanCommand,
'test': PyTestCommand,
},
install_requires=INSTALL_REQUIRES,
extras_require={
'usb_plugs': [
'libusb1>=1.3.0,<2.0',
'M2Crypto>=0.22.3,<1.0',
],
'update_units': [
'xlrd>=1.0.0,<2.0',
],
'serial_collection_plug': [
'pyserial>=3.3.0,<4.0',
],
'examples': [
'pandas>=0.22.0,<0.25.0',
],
},
setup_requires=[
'wheel>=0.29.0,<1.0',
],
tests_require=[
'mock>=2.0.0',
# Remove max version here after we drop Python 2 support.
'pandas>=0.22.0,<0.25.0',
'numpy<1.17.0',
'pytest>=2.9.2',
'pytest-cov>=2.2.1',
],
)