Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 1 | # Copyright 2015 gRPC authors. |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 2 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 6 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 8 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 14 | """Provides distutils command classes for the GRPC Python setup process.""" |
| 15 | |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 16 | import os |
Ken Payson | 4df9647 | 2016-05-04 17:39:28 -0700 | [diff] [blame] | 17 | import shutil |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 18 | |
| 19 | import setuptools |
Ken Payson | 4df9647 | 2016-05-04 17:39:28 -0700 | [diff] [blame] | 20 | |
| 21 | ROOT_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__))) |
| 22 | 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] | 23 | |
| 24 | |
Masood Malekghassemi | 1ff429d | 2016-06-02 16:39:20 -0700 | [diff] [blame] | 25 | class CopyProtoModules(setuptools.Command): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 26 | """Command to copy proto modules from grpc/src/proto.""" |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 27 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 28 | description = '' |
| 29 | user_options = [] |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 30 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 31 | def initialize_options(self): |
| 32 | pass |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 33 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 34 | def finalize_options(self): |
| 35 | pass |
Ken Payson | 4df9647 | 2016-05-04 17:39:28 -0700 | [diff] [blame] | 36 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 37 | def run(self): |
| 38 | if os.path.isfile(HEALTH_PROTO): |
Mehrdad Afshari | 87cd994 | 2018-01-02 14:40:00 -0800 | [diff] [blame] | 39 | shutil.copyfile(HEALTH_PROTO, |
| 40 | os.path.join(ROOT_DIR, |
| 41 | 'grpc_health/v1/health.proto')) |
Ken Payson | 4df9647 | 2016-05-04 17:39:28 -0700 | [diff] [blame] | 42 | |
| 43 | |
Ken Payson | dd24c1e | 2016-07-13 14:18:33 -0700 | [diff] [blame] | 44 | class BuildPackageProtos(setuptools.Command): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 45 | """Command to generate project *_pb2.py modules from proto files.""" |
Ken Payson | dd24c1e | 2016-07-13 14:18:33 -0700 | [diff] [blame] | 46 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 47 | description = 'build grpc protobuf modules' |
| 48 | user_options = [] |
Ken Payson | dd24c1e | 2016-07-13 14:18:33 -0700 | [diff] [blame] | 49 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 50 | def initialize_options(self): |
| 51 | pass |
Ken Payson | dd24c1e | 2016-07-13 14:18:33 -0700 | [diff] [blame] | 52 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 53 | def finalize_options(self): |
| 54 | pass |
Masood Malekghassemi | 12dadaf | 2015-08-05 13:30:17 -0700 | [diff] [blame] | 55 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 56 | def run(self): |
| 57 | # due to limitations of the proto generator, we require that only *one* |
| 58 | # directory is provided as an 'include' directory. We assume it's the '' key |
| 59 | # to `self.distribution.package_dir` (and get a key error if it's not |
| 60 | # there). |
| 61 | from grpc_tools import command |
| 62 | command.build_package_protos(self.distribution.package_dir['']) |