blob: 14375a74c0e8da64a66b31d07da33cdafe88fd67 [file] [log] [blame]
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -07001# 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 Malekghassemi12dadaf2015-08-05 13:30:17 -070029"""Provides distutils command classes for the GRPC Python setup process."""
30
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070031import os
Ken Payson4df96472016-05-04 17:39:28 -070032import shutil
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070033
34import setuptools
Ken Payson4df96472016-05-04 17:39:28 -070035
36ROOT_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
37HEALTH_PROTO = os.path.join(ROOT_DIR, '../../proto/grpc/health/v1/health.proto')
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070038
39
Masood Malekghassemi1ff429d2016-06-02 16:39:20 -070040class CopyProtoModules(setuptools.Command):
Masood Malekghassemicc793702017-01-13 19:20:10 -080041 """Command to copy proto modules from grpc/src/proto."""
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070042
Masood Malekghassemicc793702017-01-13 19:20:10 -080043 description = ''
44 user_options = []
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070045
Masood Malekghassemicc793702017-01-13 19:20:10 -080046 def initialize_options(self):
47 pass
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070048
Masood Malekghassemicc793702017-01-13 19:20:10 -080049 def finalize_options(self):
50 pass
Ken Payson4df96472016-05-04 17:39:28 -070051
Masood Malekghassemicc793702017-01-13 19:20:10 -080052 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 Payson4df96472016-05-04 17:39:28 -070057
58
Ken Paysondd24c1e2016-07-13 14:18:33 -070059class BuildPackageProtos(setuptools.Command):
Masood Malekghassemicc793702017-01-13 19:20:10 -080060 """Command to generate project *_pb2.py modules from proto files."""
Ken Paysondd24c1e2016-07-13 14:18:33 -070061
Masood Malekghassemicc793702017-01-13 19:20:10 -080062 description = 'build grpc protobuf modules'
63 user_options = []
Ken Paysondd24c1e2016-07-13 14:18:33 -070064
Masood Malekghassemicc793702017-01-13 19:20:10 -080065 def initialize_options(self):
66 pass
Ken Paysondd24c1e2016-07-13 14:18:33 -070067
Masood Malekghassemicc793702017-01-13 19:20:10 -080068 def finalize_options(self):
69 pass
Masood Malekghassemi12dadaf2015-08-05 13:30:17 -070070
Masood Malekghassemicc793702017-01-13 19:20:10 -080071 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[''])