Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 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. |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 29 | """Provides distutils command classes for the GRPC Python setup process.""" |
| 30 | |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 31 | import os |
Ken Payson | 4df9647 | 2016-05-04 17:39:28 -0700 | [diff] [blame] | 32 | import shutil |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 33 | |
| 34 | import setuptools |
Ken Payson | 4df9647 | 2016-05-04 17:39:28 -0700 | [diff] [blame] | 35 | |
| 36 | ROOT_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__))) |
| 37 | HEALTH_PROTO = os.path.join(ROOT_DIR, '../../proto/grpc/health/v1/health.proto') |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 38 | |
| 39 | |
Masood Malekghassemi | 1ff429d | 2016-06-02 16:39:20 -0700 | [diff] [blame] | 40 | class CopyProtoModules(setuptools.Command): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 41 | """Command to copy proto modules from grpc/src/proto.""" |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 42 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 43 | description = '' |
| 44 | user_options = [] |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 45 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 46 | def initialize_options(self): |
| 47 | pass |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 48 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 49 | def finalize_options(self): |
| 50 | pass |
Ken Payson | 4df9647 | 2016-05-04 17:39:28 -0700 | [diff] [blame] | 51 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 52 | def run(self): |
| 53 | if os.path.isfile(HEALTH_PROTO): |
| 54 | shutil.copyfile( |
| 55 | HEALTH_PROTO, |
| 56 | os.path.join(ROOT_DIR, 'grpc_health/v1/health.proto')) |
Ken Payson | 4df9647 | 2016-05-04 17:39:28 -0700 | [diff] [blame] | 57 | |
| 58 | |
Ken Payson | dd24c1e | 2016-07-13 14:18:33 -0700 | [diff] [blame] | 59 | class BuildPackageProtos(setuptools.Command): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 60 | """Command to generate project *_pb2.py modules from proto files.""" |
Ken Payson | dd24c1e | 2016-07-13 14:18:33 -0700 | [diff] [blame] | 61 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 62 | description = 'build grpc protobuf modules' |
| 63 | user_options = [] |
Ken Payson | dd24c1e | 2016-07-13 14:18:33 -0700 | [diff] [blame] | 64 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 65 | def initialize_options(self): |
| 66 | pass |
Ken Payson | dd24c1e | 2016-07-13 14:18:33 -0700 | [diff] [blame] | 67 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 68 | def finalize_options(self): |
| 69 | pass |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 70 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 71 | def run(self): |
| 72 | # due to limitations of the proto generator, we require that only *one* |
| 73 | # directory is provided as an 'include' directory. We assume it's the '' key |
| 74 | # to `self.distribution.package_dir` (and get a key error if it's not |
| 75 | # there). |
| 76 | from grpc_tools import command |
| 77 | command.build_package_protos(self.distribution.package_dir['']) |