Skip to content

Commit d7e3351

Browse files
committed
Modify setup.py to build protos on Windows
Also change yaml library to one that builds on Windows Also add some setup instructions for Windows
1 parent cea0dbe commit d7e3351

File tree

2 files changed

+51
-23
lines changed

2 files changed

+51
-23
lines changed

CONTRIBUTING.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ when there are changes upstream after your PR was created.
5858
We generally tend toward squashing commits on merge rather than filling our git
5959
log with merge commits. Sometimes, however, especially for large, sweeping
6060
changes, it makes sense to preserve multiple commits in the history. If you're
61-
authoring such a PR, consider using a rebase with squashes and fixups to reduce
61+
authoring such a PR, consider using a rebase with squashes and fixups to reduce
6262
the commit history down to a commit per salient change.
6363

6464

6565
### Code Standards
6666
For a smooth code review, it helps to make sure your code adheres to standards,
67-
conventions, and design goals for OpenHTF. A best-effort attempt to understand
67+
conventions, and design goals for OpenHTF. A best-effort attempt to understand
6868
and meet these standards before requesting code review can go a long way towards
6969
making the review process as fast and painless as possible.
7070

@@ -73,7 +73,7 @@ making the review process as fast and painless as possible.
7373
OpenHTF's Python code follows the
7474
[Google Python Style Guide](https://google.github.io/styleguide/pyguide.html).
7575
We provide a `pylintrc` file at the top level of our repo that you can use with
76-
[pylint](https://www.pylint.org/) to lint your Python code. We expect the
76+
[pylint](https://www.pylint.org/) to lint your Python code. We expect the
7777
codebase to produce zero pylint warnings, and we allow the use of explicit
7878
`pylint: disable=...` comments in certain cases where it makes sense.
7979

@@ -173,10 +173,10 @@ fits in based on what it does.
173173
| |
174174
| |
175175
| '-> util
176-
|
176+
|
177177
| Generic utility functions and miscellaneous tools.
178-
| The contents of this submodule should be general enough to be
179-
| useable outside of OpenHTF, meaning it should not be dependent
178+
| The contents of this submodule should be general enough to be
179+
| useable outside of OpenHTF, meaning it should not be dependent
180180
| on other code in the OpenHTF package.
181181
|
182182
|
@@ -239,7 +239,7 @@ python setup.py develop
239239
```
240240

241241
### MacOS
242-
We will use [Homebrew](https://brew.sh/) to install our dependencies and Pip to set up the virtualenv. We recommend installing [Xcode](https://developer.apple.com/xcode/) first as the GCC compiler will be needed for both; however, other GCC compilers not associated with Xcode may work just as well.
242+
We will use [Homebrew](https://brew.sh/) to install our dependencies and Pip to set up the virtualenv. We recommend installing [Xcode](https://developer.apple.com/xcode/) first as the GCC compiler will be needed for both; however, other GCC compilers not associated with Xcode may work just as well.
243243

244244
```bash
245245
# Install dependencies.
@@ -271,7 +271,32 @@ virtualenv venv
271271
python setup.py develop
272272
```
273273

274-
If you're having issues with the python setup, it's possible that the problem is due to El Capitan not including ssl headers. This [link](http://adarsh.io/bundler-failing-on-el-capitan/) may help you in that regard.
274+
If you're having issues with the python setup, it's possible that the problem is due to El Capitan not including ssl headers. This [link](http://adarsh.io/bundler-failing-on-el-capitan/) may help you in that regard.
275+
276+
### Windows
277+
278+
Windows is similar to other platforms. It requires Pip to set up the virutalenv and protoc to be in the path. A pre-built binary can be downloaded from
279+
[link](https://github.com/google/protobuf/releases).
280+
281+
```
282+
# Clone into the repo.
283+
git clone https://github.com/google/openhtf.git
284+
285+
# Install virtualenv via pip.
286+
pip install virtualenv
287+
288+
# Change to the openhtf directory.
289+
cd openhtf
290+
291+
# Create a new virtualenv.
292+
virtualenv venv
293+
294+
# Activate the new virtualenv.
295+
venv/Scripts/activate
296+
297+
# Install openhtf into the virtualenv in dev mode.
298+
python setup.py develop
299+
```
275300

276301
## Web Frontend Development
277302
OpenHTF ships with a built-in web gui found in the `openhtf.output.web_gui` module.

setup.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from distutils.command.build import build
2424
from distutils.command.clean import clean
2525
from distutils.cmd import Command
26+
from distutils.spawn import find_executable
2627
from setuptools import find_packages
2728
from setuptools import setup
2829
from setuptools.command.test import test
@@ -51,7 +52,6 @@ class BuildProtoCommand(Command):
5152
('outdir=', 'o', 'Where to output .py files.')]
5253

5354
def initialize_options(self):
54-
self.skip_proto = False
5555
try:
5656
prefix = subprocess.check_output(
5757
'pkg-config --variable prefix protobuf'.split()).strip().decode('utf-8')
@@ -63,30 +63,29 @@ def initialize_options(self):
6363
# Default to /usr/local for Homebrew
6464
prefix = '/usr/local'
6565
else:
66-
print('Warning: mfg-inspector output is not fully implemented for '
67-
'Windows. OpenHTF will be installed without it.')
68-
self.skip_proto = True
66+
prefix = None
6967

70-
maybe_protoc = os.path.join(prefix, 'bin', 'protoc')
71-
if os.path.isfile(maybe_protoc) and os.access(maybe_protoc, os.X_OK):
68+
self.protoc = None
69+
if prefix:
70+
maybe_protoc = os.path.join(prefix, 'bin', 'protoc')
71+
if os.path.isfile(maybe_protoc) and os.access(maybe_protoc, os.X_OK):
7272
self.protoc = maybe_protoc
73-
else:
73+
else:
7474
print('Warning: protoc not found at %s' % maybe_protoc)
7575
print('setup will attempt to run protoc with no prefix.')
76-
self.protoc = 'protoc'
77-
78-
self.protodir = os.path.join(prefix, 'include')
76+
if not self.protoc:
77+
self.protoc = find_executable('protoc')
78+
pc_path = os.path.dirname(find_executable('protoc'))
79+
self.protodir = os.path.abspath(os.path.join(os.path.dirname(pc_path), '../lib'))
80+
else:
81+
self.protodir = os.path.join(prefix, 'include')
7982
self.indir = os.getcwd()
8083
self.outdir = os.getcwd()
8184

8285
def finalize_options(self):
8386
pass
8487

8588
def run(self):
86-
if self.skip_proto:
87-
print('Skipping building protocol buffers.')
88-
return
89-
9089
# Build regular proto files.
9190
protos = glob.glob(
9291
os.path.join(self.indir, 'openhtf', 'output', 'proto', '*.proto'))
@@ -109,6 +108,10 @@ def run(self):
109108
'"protobuf-compiler" and "libprotobuf-dev" packages.')
110109
elif sys.platform == 'darwin':
111110
print('On Mac, protobuf is often installed via homebrew.')
111+
else:
112+
print('On Windows, protoc should be installed and added '
113+
'to the path. Pre-built binaries can be found at '
114+
'https://github.com/google/protobuf/releases')
112115
raise
113116
except subprocess.CalledProcessError:
114117
print('Could not build proto files.')
@@ -130,7 +133,7 @@ def run(self):
130133
'mutablerecords>=0.4.1,<2.0',
131134
'oauth2client>=1.5.2,<2.0',
132135
'protobuf>=3.0.0,<4.0',
133-
'pyaml>=15.3.1,<16.0',
136+
'PyYAML>=3.10,<4.0',
134137
'pyOpenSSL>=17.1.0,<18.0',
135138
'sockjs-tornado>=1.0.3,<2.0',
136139
'tornado>=4.3,<5.0',

0 commit comments

Comments
 (0)