blob: 933f965aa2da057ec65053a7f33cccdb18e23f4d [file] [log] [blame]
Jan Tattermusch7897ae92017-06-07 22:57:36 +02001# Copyright 2015 gRPC authors.
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -07002#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003# 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 Malekghassemi12dadaf2015-08-05 13:30:17 -07006#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02007# http://www.apache.org/licenses/LICENSE-2.0
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -07008#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009# 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 Malekghassemi12dadaf2015-08-05 13:30:17 -070014"""Provides distutils command classes for the GRPC Python setup process."""
15
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070016import os
Ken Payson4df96472016-05-04 17:39:28 -070017import shutil
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070018
19import setuptools
Ken Payson4df96472016-05-04 17:39:28 -070020
21ROOT_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
22HEALTH_PROTO = os.path.join(ROOT_DIR, '../../proto/grpc/health/v1/health.proto')
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070023
24
Masood Malekghassemi1ff429d2016-06-02 16:39:20 -070025class CopyProtoModules(setuptools.Command):
Masood Malekghassemicc793702017-01-13 19:20:10 -080026 """Command to copy proto modules from grpc/src/proto."""
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070027
Masood Malekghassemicc793702017-01-13 19:20:10 -080028 description = ''
29 user_options = []
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070030
Masood Malekghassemicc793702017-01-13 19:20:10 -080031 def initialize_options(self):
32 pass
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070033
Masood Malekghassemicc793702017-01-13 19:20:10 -080034 def finalize_options(self):
35 pass
Ken Payson4df96472016-05-04 17:39:28 -070036
Masood Malekghassemicc793702017-01-13 19:20:10 -080037 def run(self):
38 if os.path.isfile(HEALTH_PROTO):
Mehrdad Afshari87cd9942018-01-02 14:40:00 -080039 shutil.copyfile(HEALTH_PROTO,
40 os.path.join(ROOT_DIR,
41 'grpc_health/v1/health.proto'))
Ken Payson4df96472016-05-04 17:39:28 -070042
43
Ken Paysondd24c1e2016-07-13 14:18:33 -070044class BuildPackageProtos(setuptools.Command):
Masood Malekghassemicc793702017-01-13 19:20:10 -080045 """Command to generate project *_pb2.py modules from proto files."""
Ken Paysondd24c1e2016-07-13 14:18:33 -070046
Masood Malekghassemicc793702017-01-13 19:20:10 -080047 description = 'build grpc protobuf modules'
48 user_options = []
Ken Paysondd24c1e2016-07-13 14:18:33 -070049
Masood Malekghassemicc793702017-01-13 19:20:10 -080050 def initialize_options(self):
51 pass
Ken Paysondd24c1e2016-07-13 14:18:33 -070052
Masood Malekghassemicc793702017-01-13 19:20:10 -080053 def finalize_options(self):
54 pass
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070055
Masood Malekghassemicc793702017-01-13 19:20:10 -080056 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[''])