forked from google/openhtf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
184 lines (157 loc) · 5.48 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
# 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/io/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):
try:
prefix = subprocess.check_output(
'pkg-config --variable prefix protobuf'.split()).strip()
except (subprocess.CalledProcessError, OSError):
if platform.system() == 'Linux':
# Default to /usr?
prefix = '/usr'
elif platform.system() == 'Mac':
# Default to /usr/local for Homebrew
prefix = '/usr/local'
else:
raise NotImplementedError(
'Windows support in-progress. Help us by submitting an issue! '
'https://github.com/google/openhtf/issues/new')
self.protoc = os.path.join(prefix, 'bin', 'protoc')
self.protodir = os.path.join(prefix, 'include')
self.indir = os.path.join(os.getcwd(), 'openhtf', 'io', 'proto')
self.outdir = os.path.join(os.getcwd(), 'openhtf', 'io', 'proto')
def finalize_options(self):
pass
def run(self):
# Build regular proto files.
protos = glob.glob(os.path.join(self.indir, '*.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
print ('On many Linux systems, this is fixed by installing the '
'"protobuf-compiler" and "libprotobuf-dev" packages.')
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 = [
'contextlib2==0.5.1',
'enum34==1.1.2',
'mutablerecords==0.2.9',
'oauth2client==1.5.2',
'protobuf==2.6.1',
'pyaml==15.3.1',
'pyOpenSSL==0.15.1',
'tornado==4.3',
]
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 = ' '.join('--cov-report %s' % output
for output in self.pytest_cov.split(','))
cov = ' --cov openhtf ' + outputs
sys.argv = [sys.argv[0]]
sys.exit(pytest.main(self.pytest_args + cov))
setup(
name='openhtf',
version='0.9',
description='OpenHTF, the open hardware testing framework.',
author='John Hawley',
author_email='madsci@google.com',
maintainer='Joe Ethier',
maintainer_email='jethier@google.com',
packages=find_packages(exclude='examples'),
cmdclass={
'build_proto': BuildProtoCommand,
'clean': CleanCommand,
'test': PyTestCommand,
},
install_requires=INSTALL_REQUIRES,
extras_require={
'usb_plugs': [
'libusb1==1.3.0',
'M2Crypto==0.22.3',
'python-gflags==2.0',
],
},
setup_requires=[
'wheel==0.29.0',
],
tests_require=[
'mock>=2.0.0',
'pytest==2.8.7',
],
)