OLD | NEW |
(Empty) | |
| 1 # Copyright 2015, Google Inc. |
| 2 # All rights reserved. |
| 3 # |
| 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are |
| 6 # met: |
| 7 # |
| 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. |
| 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
| 30 """Provides distutils command classes for the GRPC Python setup process.""" |
| 31 |
| 32 import distutils |
| 33 import glob |
| 34 import os |
| 35 import os.path |
| 36 import subprocess |
| 37 import sys |
| 38 |
| 39 import setuptools |
| 40 from setuptools.command import build_py |
| 41 |
| 42 |
| 43 class BuildProtoModules(setuptools.Command): |
| 44 """Command to generate project *_pb2.py modules from proto files.""" |
| 45 |
| 46 description = '' |
| 47 user_options = [] |
| 48 |
| 49 def initialize_options(self): |
| 50 pass |
| 51 |
| 52 def finalize_options(self): |
| 53 self.protoc_command = distutils.spawn.find_executable('protoc') |
| 54 self.grpc_python_plugin_command = distutils.spawn.find_executable( |
| 55 'grpc_python_plugin') |
| 56 |
| 57 def run(self): |
| 58 paths = [] |
| 59 root_directory = os.getcwd() |
| 60 for walk_root, directories, filenames in os.walk(root_directory): |
| 61 for filename in filenames: |
| 62 if filename.endswith('.proto'): |
| 63 paths.append(os.path.join(walk_root, filename)) |
| 64 command = [ |
| 65 self.protoc_command, |
| 66 '--plugin=protoc-gen-python-grpc={}'.format( |
| 67 self.grpc_python_plugin_command), |
| 68 '-I {}'.format(root_directory), |
| 69 '--python_out={}'.format(root_directory), |
| 70 '--python-grpc_out={}'.format(root_directory), |
| 71 ] + paths |
| 72 try: |
| 73 subprocess.check_output(' '.join(command), cwd=root_directory, shell=True, |
| 74 stderr=subprocess.STDOUT) |
| 75 except subprocess.CalledProcessError as e: |
| 76 raise Exception('{}\nOutput:\n{}'.format(e.message, e.output)) |
| 77 |
| 78 |
| 79 class BuildPy(build_py.build_py): |
| 80 """Custom project build command.""" |
| 81 |
| 82 def run(self): |
| 83 self.run_command('build_proto_modules') |
| 84 build_py.build_py.run(self) |
OLD | NEW |