blob: e0b0bf7622dfe5789c19e48df5778456f91281b6 [file] [log] [blame]
Nathaniel Manistab68f3d12015-01-23 21:32:47 +00001# 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
Nathaniel Manistab8b0adf2015-01-29 00:30:51 +000030"""A setup module for the GRPC Python package."""
Nathaniel Manistab68f3d12015-01-23 21:32:47 +000031
Masood Malekghassemi743c10c2015-06-16 18:05:27 -070032import os
Masood Malekghassemid65632a2015-07-27 14:30:09 -070033import os.path
Alexander Staubo8eac91e2015-04-06 12:06:22 -040034import sys
Nathaniel Manistab68f3d12015-01-23 21:32:47 +000035
Masood Malekghassemi743c10c2015-06-16 18:05:27 -070036from distutils import core as _core
Masood Malekghassemi5a65bcd2015-09-25 11:27:10 -070037from distutils import extension as _extension
Masood Malekghassemi743c10c2015-06-16 18:05:27 -070038import setuptools
39
Masood Malekghassemi116982e2015-12-11 15:53:38 -080040PYTHON_STEM = './src/python/grpcio/'
41CORE_INCLUDE = ('./include', './',)
42
Masood Malekghassemid65632a2015-07-27 14:30:09 -070043# Ensure we're in the proper directory whether or not we're being used by pip.
44os.chdir(os.path.dirname(os.path.abspath(__file__)))
Masood Malekghassemi116982e2015-12-11 15:53:38 -080045sys.path.insert(0, PYTHON_STEM)
Masood Malekghassemid65632a2015-07-27 14:30:09 -070046
Masood Malekghassemi116982e2015-12-11 15:53:38 -080047# Break import-style to ensure we can actually find our in-repo dependencies.
Masood Malekghassemid65632a2015-07-27 14:30:09 -070048import commands
Masood Malekghassemi116982e2015-12-11 15:53:38 -080049import grpc_core_dependencies
Masood Malekghassemi743c10c2015-06-16 18:05:27 -070050
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -070051# Environment variable to determine whether or not the Cython extension should
52# *use* Cython or use the generated C files. Note that this requires the C files
53# to have been generated by building first *with* Cython support.
54BUILD_WITH_CYTHON = os.environ.get('GRPC_PYTHON_BUILD_WITH_CYTHON', False)
Masood Malekghassemi743c10c2015-06-16 18:05:27 -070055
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -070056# Environment variable to determine whether or not to enable coverage analysis
57# in Cython modules.
58ENABLE_CYTHON_TRACING = os.environ.get(
59 'GRPC_PYTHON_ENABLE_CYTHON_TRACING', False)
60
61# Environment variable to determine whether or not to include the test files in
62# the installation.
63INSTALL_TESTS = os.environ.get('GRPC_PYTHON_INSTALL_TESTS', False)
64
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -070065CYTHON_EXTENSION_PACKAGE_NAMES = ()
Masood Malekghassemi5a65bcd2015-09-25 11:27:10 -070066
Masood Malekghassemi116982e2015-12-11 15:53:38 -080067CYTHON_EXTENSION_MODULE_NAMES = ('grpc._cython.cygrpc',)
Masood Malekghassemi5a65bcd2015-09-25 11:27:10 -070068
Masood Malekghassemi116982e2015-12-11 15:53:38 -080069EXTENSION_INCLUDE_DIRECTORIES = (PYTHON_STEM,) + CORE_INCLUDE
Nathaniel Manistaa4ead5d2015-01-31 01:33:27 +000070
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -070071EXTENSION_LIBRARIES = (
Masood Malekghassemi116982e2015-12-11 15:53:38 -080072 'ssl',
73 'crypto',
Nathaniel Manistaa4ead5d2015-01-31 01:33:27 +000074)
Alexander Staubo8eac91e2015-04-06 12:06:22 -040075if not "darwin" in sys.platform:
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -070076 EXTENSION_LIBRARIES += ('rt',)
Nathaniel Manistaa4ead5d2015-01-31 01:33:27 +000077
Masood Malekghassemi743c10c2015-06-16 18:05:27 -070078
Masood Malekghassemi5a65bcd2015-09-25 11:27:10 -070079def cython_extensions(package_names, module_names, include_dirs, libraries,
80 build_with_cython=False):
81 file_extension = 'pyx' if build_with_cython else 'c'
Masood Malekghassemi116982e2015-12-11 15:53:38 -080082 module_files = [os.path.join(PYTHON_STEM,
83 name.replace('.', '/') + '.' + file_extension)
Masood Malekghassemi5a65bcd2015-09-25 11:27:10 -070084 for name in module_names]
85 extensions = [
86 _extension.Extension(
Masood Malekghassemi116982e2015-12-11 15:53:38 -080087 name=module_name,
88 sources=[module_file] + grpc_core_dependencies.CORE_SOURCE_FILES,
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -070089 include_dirs=include_dirs, libraries=libraries,
90 define_macros=[('CYTHON_TRACE_NOGIL', 1)] if ENABLE_CYTHON_TRACING else []
Masood Malekghassemi5a65bcd2015-09-25 11:27:10 -070091 ) for (module_name, module_file) in zip(module_names, module_files)
92 ]
93 if build_with_cython:
94 import Cython.Build
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -070095 return Cython.Build.cythonize(
96 extensions,
Masood Malekghassemi116982e2015-12-11 15:53:38 -080097 include_path=include_dirs,
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -070098 compiler_directives={'linetrace': bool(ENABLE_CYTHON_TRACING)})
Masood Malekghassemi5a65bcd2015-09-25 11:27:10 -070099 else:
100 return extensions
101
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700102CYTHON_EXTENSION_MODULES = cython_extensions(
103 list(CYTHON_EXTENSION_PACKAGE_NAMES), list(CYTHON_EXTENSION_MODULE_NAMES),
104 list(EXTENSION_INCLUDE_DIRECTORIES), list(EXTENSION_LIBRARIES),
105 bool(BUILD_WITH_CYTHON))
Masood Malekghassemi5a65bcd2015-09-25 11:27:10 -0700106
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700107PACKAGE_DIRECTORIES = {
Masood Malekghassemi116982e2015-12-11 15:53:38 -0800108 '': PYTHON_STEM,
Nathaniel Manistab8b0adf2015-01-29 00:30:51 +0000109}
110
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700111INSTALL_REQUIRES = (
Nathaniel Manistaa1880222015-09-10 22:16:04 +0000112 'enum34>=1.0.4',
113 'futures>=2.2.0',
Masood Malekghassemid65632a2015-07-27 14:30:09 -0700114)
115
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700116SETUP_REQUIRES = (
Masood Malekghassemid65632a2015-07-27 14:30:09 -0700117 'sphinx>=1.3',
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700118) + INSTALL_REQUIRES
Masood Malekghassemid65632a2015-07-27 14:30:09 -0700119
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700120COMMAND_CLASS = {
Masood Malekghassemi791cc312015-07-27 14:22:33 -0700121 'doc': commands.SphinxDocumentation,
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700122 'build_proto_modules': commands.BuildProtoModules,
Masood Malekghassemi5c147632015-07-31 14:08:19 -0700123 'build_project_metadata': commands.BuildProjectMetadata,
124 'build_py': commands.BuildPy,
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700125 'gather': commands.Gather,
126 'run_interop': commands.RunInterop,
Masood Malekghassemid65632a2015-07-27 14:30:09 -0700127}
128
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700129TEST_PACKAGE_DATA = {
130 'tests.interop': [
131 'credentials/ca.pem',
132 'credentials/server1.key',
133 'credentials/server1.pem',
134 ],
135 'tests.protoc_plugin': [
136 'protoc_plugin_test.proto',
137 ],
138 'tests.unit': [
139 'credentials/ca.pem',
140 'credentials/server1.key',
141 'credentials/server1.pem',
142 ],
143}
144
145TESTS_REQUIRE = (
146 'oauth2client>=1.4.7',
Nathaniel Manista27f62432016-01-04 19:12:29 +0000147 'protobuf>=3.0.0a3',
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700148 'coverage>=4.0',
149) + INSTALL_REQUIRES
150
151TEST_SUITE = 'tests'
152TEST_LOADER = 'tests:Loader'
153TEST_RUNNER = 'tests:Runner'
154
155PACKAGE_DATA = {}
156if INSTALL_TESTS:
157 PACKAGE_DATA = dict(PACKAGE_DATA, **TEST_PACKAGE_DATA)
Masood Malekghassemi116982e2015-12-11 15:53:38 -0800158 PACKAGES = setuptools.find_packages(PYTHON_STEM)
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700159else:
Masood Malekghassemi116982e2015-12-11 15:53:38 -0800160 PACKAGES = setuptools.find_packages(
161 PYTHON_STEM, exclude=['tests', 'tests.*'])
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700162
Masood Malekghassemi451887b2015-03-30 17:44:19 -0700163setuptools.setup(
164 name='grpcio',
Masood Malekghassemi116982e2015-12-11 15:53:38 -0800165 version='0.12.0b1',
Masood Malekghassemif21dc7e2015-11-20 19:28:41 -0800166 ext_modules=CYTHON_EXTENSION_MODULES,
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700167 packages=list(PACKAGES),
168 package_dir=PACKAGE_DIRECTORIES,
Masood Malekghassemi116982e2015-12-11 15:53:38 -0800169 package_data=PACKAGE_DATA,
Masood Malekghassemi7566c9a2015-10-21 20:29:23 -0700170 install_requires=INSTALL_REQUIRES,
171 setup_requires=SETUP_REQUIRES,
172 cmdclass=COMMAND_CLASS,
173 tests_require=TESTS_REQUIRE,
174 test_suite=TEST_SUITE,
175 test_loader=TEST_LOADER,
176 test_runner=TEST_RUNNER,
Masood Malekghassemi451887b2015-03-30 17:44:19 -0700177)