OLD | NEW |
(Empty) | |
| 1 # Copyright 2015-2016, 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 |
| 30 """A setup module for the GRPC Python package.""" |
| 31 |
| 32 import os |
| 33 import os.path |
| 34 import shutil |
| 35 import sys |
| 36 |
| 37 from distutils import core as _core |
| 38 from distutils import extension as _extension |
| 39 import setuptools |
| 40 from setuptools.command import egg_info |
| 41 |
| 42 # Redirect the manifest template from MANIFEST.in to PYTHON-MANIFEST.in. |
| 43 egg_info.manifest_maker.template = 'PYTHON-MANIFEST.in' |
| 44 |
| 45 PYTHON_STEM = './src/python/grpcio' |
| 46 CORE_INCLUDE = ('./include', '.',) |
| 47 BORINGSSL_INCLUDE = ('./third_party/boringssl/include',) |
| 48 ZLIB_INCLUDE = ('./third_party/zlib',) |
| 49 |
| 50 # Ensure we're in the proper directory whether or not we're being used by pip. |
| 51 os.chdir(os.path.dirname(os.path.abspath(__file__))) |
| 52 sys.path.insert(0, os.path.abspath(PYTHON_STEM)) |
| 53 |
| 54 # Break import-style to ensure we can actually find our in-repo dependencies. |
| 55 import commands |
| 56 import precompiled |
| 57 import grpc_core_dependencies |
| 58 import grpc_version |
| 59 |
| 60 LICENSE = '3-clause BSD' |
| 61 |
| 62 # Environment variable to determine whether or not the Cython extension should |
| 63 # *use* Cython or use the generated C files. Note that this requires the C files |
| 64 # to have been generated by building first *with* Cython support. |
| 65 BUILD_WITH_CYTHON = os.environ.get('GRPC_PYTHON_BUILD_WITH_CYTHON', False) |
| 66 |
| 67 # Environment variable to determine whether or not to enable coverage analysis |
| 68 # in Cython modules. |
| 69 ENABLE_CYTHON_TRACING = os.environ.get( |
| 70 'GRPC_PYTHON_ENABLE_CYTHON_TRACING', False) |
| 71 |
| 72 # Environment variable to determine whether or not to include the test files in |
| 73 # the installation. |
| 74 INSTALL_TESTS = os.environ.get('GRPC_PYTHON_INSTALL_TESTS', False) |
| 75 |
| 76 CYTHON_EXTENSION_PACKAGE_NAMES = () |
| 77 |
| 78 CYTHON_EXTENSION_MODULE_NAMES = ('grpc._cython.cygrpc',) |
| 79 |
| 80 CYTHON_HELPER_C_FILES = ( |
| 81 os.path.join(PYTHON_STEM, 'grpc/_cython/loader.c'), |
| 82 os.path.join(PYTHON_STEM, 'grpc/_cython/imports.generated.c'), |
| 83 ) |
| 84 |
| 85 CORE_C_FILES = () |
| 86 if not "win32" in sys.platform: |
| 87 CORE_C_FILES += tuple(grpc_core_dependencies.CORE_SOURCE_FILES) |
| 88 |
| 89 EXTENSION_INCLUDE_DIRECTORIES = ( |
| 90 (PYTHON_STEM,) + CORE_INCLUDE + BORINGSSL_INCLUDE + ZLIB_INCLUDE) |
| 91 |
| 92 EXTENSION_LIBRARIES = () |
| 93 if "linux" in sys.platform: |
| 94 EXTENSION_LIBRARIES += ('rt',) |
| 95 if not "win32" in sys.platform: |
| 96 EXTENSION_LIBRARIES += ('m',) |
| 97 |
| 98 DEFINE_MACROS = (('OPENSSL_NO_ASM', 1), ('_WIN32_WINNT', 0x600), ('GPR_BACKWARDS
_COMPATIBILITY_MODE', 1),) |
| 99 |
| 100 LDFLAGS = () |
| 101 CFLAGS = () |
| 102 if "linux" in sys.platform: |
| 103 LDFLAGS += ('-Wl,-wrap,memcpy',) |
| 104 if "linux" in sys.platform or "darwin" in sys.platform: |
| 105 CFLAGS += ('-fvisibility=hidden',) |
| 106 DEFINE_MACROS += (('PyMODINIT_FUNC', '__attribute__((visibility ("default")))
void'),) |
| 107 |
| 108 |
| 109 def cython_extensions(package_names, module_names, extra_sources, include_dirs, |
| 110 libraries, define_macros, build_with_cython=False): |
| 111 # Set compiler directives linetrace argument only if we care about tracing; |
| 112 # this is due to Cython having different behavior between linetrace being |
| 113 # False and linetrace being unset. See issue #5689. |
| 114 cython_compiler_directives = {} |
| 115 if ENABLE_CYTHON_TRACING: |
| 116 define_macros = define_macros + [('CYTHON_TRACE_NOGIL', 1)] |
| 117 cython_compiler_directives['linetrace'] = True |
| 118 file_extension = 'pyx' if build_with_cython else 'c' |
| 119 module_files = [os.path.join(PYTHON_STEM, |
| 120 name.replace('.', '/') + '.' + file_extension) |
| 121 for name in module_names] |
| 122 extensions = [ |
| 123 _extension.Extension( |
| 124 name=module_name, |
| 125 sources=[module_file] + extra_sources, |
| 126 include_dirs=include_dirs, libraries=libraries, |
| 127 define_macros=define_macros, |
| 128 extra_compile_args=list(CFLAGS), |
| 129 extra_link_args=list(LDFLAGS), |
| 130 ) for (module_name, module_file) in zip(module_names, module_files) |
| 131 ] |
| 132 if build_with_cython: |
| 133 import Cython.Build |
| 134 return Cython.Build.cythonize( |
| 135 extensions, |
| 136 include_path=include_dirs, |
| 137 compiler_directives=cython_compiler_directives) |
| 138 else: |
| 139 return extensions |
| 140 |
| 141 CYTHON_EXTENSION_MODULES = cython_extensions( |
| 142 list(CYTHON_EXTENSION_PACKAGE_NAMES), list(CYTHON_EXTENSION_MODULE_NAMES), |
| 143 list(CYTHON_HELPER_C_FILES) + list(CORE_C_FILES), |
| 144 list(EXTENSION_INCLUDE_DIRECTORIES), list(EXTENSION_LIBRARIES), |
| 145 list(DEFINE_MACROS), bool(BUILD_WITH_CYTHON)) |
| 146 |
| 147 PACKAGE_DIRECTORIES = { |
| 148 '': PYTHON_STEM, |
| 149 } |
| 150 |
| 151 INSTALL_REQUIRES = ( |
| 152 'six>=1.10', |
| 153 'enum34>=1.0.4', |
| 154 'futures>=2.2.0', |
| 155 # TODO(atash): eventually split the grpcio package into a metapackage |
| 156 # depending on protobuf and the runtime component (independent of protobuf) |
| 157 'protobuf>=3.0.0a3', |
| 158 ) |
| 159 |
| 160 SETUP_REQUIRES = ( |
| 161 'sphinx>=1.3', |
| 162 'sphinx_rtd_theme>=0.1.8' |
| 163 ) + INSTALL_REQUIRES |
| 164 |
| 165 COMMAND_CLASS = { |
| 166 'doc': commands.SphinxDocumentation, |
| 167 'build_proto_modules': commands.BuildProtoModules, |
| 168 'build_project_metadata': commands.BuildProjectMetadata, |
| 169 'build_py': commands.BuildPy, |
| 170 'build_ext': commands.BuildExt, |
| 171 'build_tagged_ext': precompiled.BuildTaggedExt, |
| 172 'gather': commands.Gather, |
| 173 'run_interop': commands.RunInterop, |
| 174 'test_lite': commands.TestLite |
| 175 } |
| 176 |
| 177 # Ensure that package data is copied over before any commands have been run: |
| 178 credentials_dir = os.path.join(PYTHON_STEM, 'grpc/_cython/_credentials') |
| 179 try: |
| 180 os.mkdir(credentials_dir) |
| 181 except OSError: |
| 182 pass |
| 183 shutil.copyfile('etc/roots.pem', os.path.join(credentials_dir, 'roots.pem')) |
| 184 |
| 185 TEST_PACKAGE_DATA = { |
| 186 'tests.interop': [ |
| 187 'credentials/ca.pem', |
| 188 'credentials/server1.key', |
| 189 'credentials/server1.pem', |
| 190 ], |
| 191 'tests.protoc_plugin': [ |
| 192 'protoc_plugin_test.proto', |
| 193 ], |
| 194 'tests.unit': [ |
| 195 'credentials/ca.pem', |
| 196 'credentials/server1.key', |
| 197 'credentials/server1.pem', |
| 198 ], |
| 199 } |
| 200 |
| 201 TESTS_REQUIRE = ( |
| 202 'oauth2client>=1.4.7', |
| 203 'protobuf>=3.0.0a3', |
| 204 'coverage>=4.0', |
| 205 ) + INSTALL_REQUIRES |
| 206 |
| 207 TEST_SUITE = 'tests' |
| 208 TEST_LOADER = 'tests:Loader' |
| 209 TEST_RUNNER = 'tests:Runner' |
| 210 |
| 211 PACKAGE_DATA = { |
| 212 # Binaries that may or may not be present in the final installation, but are |
| 213 # mentioned here for completeness. |
| 214 'grpc._cython': [ |
| 215 '_credentials/roots.pem', |
| 216 '_windows/grpc_c.32.python', |
| 217 '_windows/grpc_c.64.python', |
| 218 ], |
| 219 } |
| 220 if INSTALL_TESTS: |
| 221 PACKAGE_DATA = dict(PACKAGE_DATA, **TEST_PACKAGE_DATA) |
| 222 PACKAGES = setuptools.find_packages(PYTHON_STEM) |
| 223 else: |
| 224 PACKAGES = setuptools.find_packages( |
| 225 PYTHON_STEM, exclude=['tests', 'tests.*']) |
| 226 |
| 227 setup_arguments = { |
| 228 'name': 'grpcio', |
| 229 'version': grpc_version.VERSION, |
| 230 'license': LICENSE, |
| 231 'ext_modules': CYTHON_EXTENSION_MODULES, |
| 232 'packages': list(PACKAGES), |
| 233 'package_dir': PACKAGE_DIRECTORIES, |
| 234 'package_data': PACKAGE_DATA, |
| 235 'install_requires': INSTALL_REQUIRES, |
| 236 'setup_requires': SETUP_REQUIRES, |
| 237 'cmdclass': COMMAND_CLASS, |
| 238 'tests_require': TESTS_REQUIRE, |
| 239 'test_suite': TEST_SUITE, |
| 240 'test_loader': TEST_LOADER, |
| 241 'test_runner': TEST_RUNNER, |
| 242 } |
| 243 |
| 244 precompiled.update_setup_arguments(setup_arguments) |
| 245 |
| 246 setuptools.setup(**setup_arguments) |
OLD | NEW |