From d7e335145ace4dca0e261866081fe4ebe5e9da51 Mon Sep 17 00:00:00 2001 From: Daiwei Li Date: Thu, 15 Feb 2018 01:23:48 -0800 Subject: [PATCH 1/2] 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 --- CONTRIBUTING.md | 41 +++++++++++++++++++++++++++++++++-------- setup.py | 33 ++++++++++++++++++--------------- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 34be478ce..3a89e993a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,13 +58,13 @@ when there are changes upstream after your PR was created. We generally tend toward squashing commits on merge rather than filling our git log with merge commits. Sometimes, however, especially for large, sweeping changes, it makes sense to preserve multiple commits in the history. If you're -authoring such a PR, consider using a rebase with squashes and fixups to reduce +authoring such a PR, consider using a rebase with squashes and fixups to reduce the commit history down to a commit per salient change. ### Code Standards For a smooth code review, it helps to make sure your code adheres to standards, -conventions, and design goals for OpenHTF. A best-effort attempt to understand +conventions, and design goals for OpenHTF. A best-effort attempt to understand and meet these standards before requesting code review can go a long way towards making the review process as fast and painless as possible. @@ -73,7 +73,7 @@ making the review process as fast and painless as possible. OpenHTF's Python code follows the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html). We provide a `pylintrc` file at the top level of our repo that you can use with -[pylint](https://www.pylint.org/) to lint your Python code. We expect the +[pylint](https://www.pylint.org/) to lint your Python code. We expect the codebase to produce zero pylint warnings, and we allow the use of explicit `pylint: disable=...` comments in certain cases where it makes sense. @@ -173,10 +173,10 @@ fits in based on what it does. | | | | | '-> util - | + | | Generic utility functions and miscellaneous tools. - | The contents of this submodule should be general enough to be - | useable outside of OpenHTF, meaning it should not be dependent + | The contents of this submodule should be general enough to be + | useable outside of OpenHTF, meaning it should not be dependent | on other code in the OpenHTF package. | | @@ -239,7 +239,7 @@ python setup.py develop ``` ### MacOS -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. +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. ```bash # Install dependencies. @@ -271,7 +271,32 @@ virtualenv venv python setup.py develop ``` -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. +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. + +### Windows + +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 +[link](https://github.com/google/protobuf/releases). + +``` +# Clone into the repo. +git clone https://github.com/google/openhtf.git + +# Install virtualenv via pip. +pip install virtualenv + +# Change to the openhtf directory. +cd openhtf + +# Create a new virtualenv. +virtualenv venv + +# Activate the new virtualenv. +venv/Scripts/activate + +# Install openhtf into the virtualenv in dev mode. +python setup.py develop +``` ## Web Frontend Development OpenHTF ships with a built-in web gui found in the `openhtf.output.web_gui` module. diff --git a/setup.py b/setup.py index 4d2a46378..6852bf678 100644 --- a/setup.py +++ b/setup.py @@ -23,6 +23,7 @@ from distutils.command.build import build from distutils.command.clean import clean from distutils.cmd import Command +from distutils.spawn import find_executable from setuptools import find_packages from setuptools import setup from setuptools.command.test import test @@ -51,7 +52,6 @@ class BuildProtoCommand(Command): ('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') @@ -63,19 +63,22 @@ def initialize_options(self): # 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 + prefix = None - maybe_protoc = os.path.join(prefix, 'bin', 'protoc') - if os.path.isfile(maybe_protoc) and os.access(maybe_protoc, os.X_OK): + self.protoc = None + if prefix: + 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: + 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') + if not self.protoc: + self.protoc = find_executable('protoc') + pc_path = os.path.dirname(find_executable('protoc')) + self.protodir = os.path.abspath(os.path.join(os.path.dirname(pc_path), '../lib')) + else: + self.protodir = os.path.join(prefix, 'include') self.indir = os.getcwd() self.outdir = os.getcwd() @@ -83,10 +86,6 @@ 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')) @@ -109,6 +108,10 @@ def run(self): '"protobuf-compiler" and "libprotobuf-dev" packages.') elif sys.platform == 'darwin': print('On Mac, protobuf is often installed via homebrew.') + else: + print('On Windows, protoc should be installed and added ' + 'to the path. Pre-built binaries can be found at ' + 'https://github.com/google/protobuf/releases') raise except subprocess.CalledProcessError: print('Could not build proto files.') @@ -130,7 +133,7 @@ def run(self): 'mutablerecords>=0.4.1,<2.0', 'oauth2client>=1.5.2,<2.0', 'protobuf>=3.0.0,<4.0', - 'pyaml>=15.3.1,<16.0', + 'PyYAML>=3.10,<4.0', 'pyOpenSSL>=17.1.0,<18.0', 'sockjs-tornado>=1.0.3,<2.0', 'tornado>=4.3,<5.0', From 8756f1c175d590a6df12f5173f8eb4e78115ca7e Mon Sep 17 00:00:00 2001 From: Daiwei Li Date: Thu, 22 Feb 2018 23:25:31 -0800 Subject: [PATCH 2/2] Change .. to os.path.pardir --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6852bf678..bd5af8438 100644 --- a/setup.py +++ b/setup.py @@ -76,7 +76,7 @@ def initialize_options(self): if not self.protoc: self.protoc = find_executable('protoc') pc_path = os.path.dirname(find_executable('protoc')) - self.protodir = os.path.abspath(os.path.join(os.path.dirname(pc_path), '../lib')) + self.protodir = os.path.abspath(os.path.join(os.path.dirname(pc_path), os.path.pardir, 'lib')) else: self.protodir = os.path.join(prefix, 'include') self.indir = os.getcwd()