Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame^] | 1 | # Copyright 2015 gRPC authors. |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -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 | d65632a | 2015-07-27 14:30:09 -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 | d65632a | 2015-07-27 14:30:09 -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 | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 14 | """Provides distutils command classes for the GRPC Python setup process.""" |
| 15 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 16 | import distutils |
Masood Malekghassemi | 154b0ee | 2016-01-25 16:45:29 -0800 | [diff] [blame] | 17 | import glob |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 18 | import os |
| 19 | import os.path |
Masood Malekghassemi | 154b0ee | 2016-01-25 16:45:29 -0800 | [diff] [blame] | 20 | import platform |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 21 | import re |
Masood Malekghassemi | 154b0ee | 2016-01-25 16:45:29 -0800 | [diff] [blame] | 22 | import shutil |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 23 | import subprocess |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 24 | import sys |
Masood Malekghassemi | 154b0ee | 2016-01-25 16:45:29 -0800 | [diff] [blame] | 25 | import traceback |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 26 | |
| 27 | import setuptools |
Masood Malekghassemi | 58a1dc2 | 2016-01-21 14:23:55 -0800 | [diff] [blame] | 28 | from setuptools.command import build_ext |
Masood Malekghassemi | 5c14763 | 2015-07-31 14:08:19 -0700 | [diff] [blame] | 29 | from setuptools.command import build_py |
Masood Malekghassemi | 154b0ee | 2016-01-25 16:45:29 -0800 | [diff] [blame] | 30 | from setuptools.command import easy_install |
| 31 | from setuptools.command import install |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 32 | from setuptools.command import test |
Masood Malekghassemi | 1d17781 | 2016-01-12 09:21:57 -0800 | [diff] [blame] | 33 | |
Masood Malekghassemi | 5fec8b3 | 2016-01-25 16:16:50 -0800 | [diff] [blame] | 34 | import support |
| 35 | |
Masood Malekghassemi | 116982e | 2015-12-11 15:53:38 -0800 | [diff] [blame] | 36 | PYTHON_STEM = os.path.dirname(os.path.abspath(__file__)) |
Ken Payson | 707c9e2 | 2016-04-20 09:42:19 -0700 | [diff] [blame] | 37 | GRPC_STEM = os.path.abspath(PYTHON_STEM + '../../../../') |
| 38 | PROTO_STEM = os.path.join(GRPC_STEM, 'src', 'proto') |
| 39 | PROTO_GEN_STEM = os.path.join(GRPC_STEM, 'src', 'python', 'gens') |
Ken Payson | 7722245 | 2016-09-11 22:06:05 -0700 | [diff] [blame] | 40 | CYTHON_STEM = os.path.join(PYTHON_STEM, 'grpc', '_cython') |
Masood Malekghassemi | 116982e | 2015-12-11 15:53:38 -0800 | [diff] [blame] | 41 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 42 | CONF_PY_ADDENDUM = """ |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 43 | extensions.append('sphinx.ext.napoleon') |
| 44 | napoleon_google_docstring = True |
| 45 | napoleon_numpy_docstring = True |
Masood Malekghassemi | 48d07c6 | 2016-07-12 15:47:05 -0700 | [diff] [blame] | 46 | napoleon_include_special_with_doc = True |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 47 | |
| 48 | html_theme = 'sphinx_rtd_theme' |
Masood Malekghassemi | 25186ae | 2016-12-27 09:05:13 -0800 | [diff] [blame] | 49 | copyright = "2016, The gRPC Authors" |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 50 | """ |
| 51 | |
Ken Payson | f7f47a6 | 2016-07-11 11:09:27 -0700 | [diff] [blame] | 52 | API_GLOSSARY = """ |
| 53 | |
| 54 | Glossary |
| 55 | ================ |
| 56 | |
| 57 | .. glossary:: |
| 58 | |
| 59 | metadatum |
| 60 | A key-value pair included in the HTTP header. It is a |
| 61 | 2-tuple where the first entry is the key and the |
| 62 | second is the value, i.e. (key, value). The metadata key is an ASCII str, |
| 63 | and must be a valid HTTP header name. The metadata value can be |
| 64 | either a valid HTTP ASCII str, or bytes. If bytes are provided, |
| 65 | the key must end with '-bin', i.e. |
| 66 | ``('binary-metadata-bin', b'\\x00\\xFF')`` |
| 67 | |
| 68 | metadata |
| 69 | A sequence of metadatum. |
| 70 | """ |
| 71 | |
Masood Malekghassemi | fe8dc88 | 2015-07-27 15:30:33 -0700 | [diff] [blame] | 72 | |
Masood Malekghassemi | 59994bc | 2016-01-12 08:49:26 -0800 | [diff] [blame] | 73 | class CommandError(Exception): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 74 | """Simple exception class for GRPC custom commands.""" |
Masood Malekghassemi | 59994bc | 2016-01-12 08:49:26 -0800 | [diff] [blame] | 75 | |
| 76 | |
Masood Malekghassemi | 154b0ee | 2016-01-25 16:45:29 -0800 | [diff] [blame] | 77 | # TODO(atash): Remove this once PyPI has better Linux bdist support. See |
| 78 | # https://bitbucket.org/pypa/pypi/issues/120/binary-wheels-for-linux-are-not-supported |
Masood Malekghassemi | 334e9e6 | 2016-02-10 20:12:59 -0800 | [diff] [blame] | 79 | def _get_grpc_custom_bdist(decorated_basename, target_bdist_basename): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 80 | """Returns a string path to a bdist file for Linux to install. |
Masood Malekghassemi | 154b0ee | 2016-01-25 16:45:29 -0800 | [diff] [blame] | 81 | |
Masood Malekghassemi | 334e9e6 | 2016-02-10 20:12:59 -0800 | [diff] [blame] | 82 | If we can retrieve a pre-compiled bdist from online, uses it. Else, emits a |
Masood Malekghassemi | 154b0ee | 2016-01-25 16:45:29 -0800 | [diff] [blame] | 83 | warning and builds from source. |
| 84 | """ |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 85 | # TODO(atash): somehow the name that's returned from `wheel` is different |
| 86 | # between different versions of 'wheel' (but from a compatibility standpoint, |
| 87 | # the names are compatible); we should have some way of determining name |
| 88 | # compatibility in the same way `wheel` does to avoid having to rename all of |
| 89 | # the custom wheels that we build/upload to GCS. |
Masood Malekghassemi | 334e9e6 | 2016-02-10 20:12:59 -0800 | [diff] [blame] | 90 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 91 | # Break import style to ensure that setup.py has had a chance to install the |
| 92 | # relevant package. |
| 93 | from six.moves.urllib import request |
| 94 | decorated_path = decorated_basename + GRPC_CUSTOM_BDIST_EXT |
| 95 | try: |
| 96 | url = BINARIES_REPOSITORY + '/{target}'.format(target=decorated_path) |
| 97 | bdist_data = request.urlopen(url).read() |
| 98 | except IOError as error: |
| 99 | raise CommandError('{}\n\nCould not find the bdist {}: {}'.format( |
| 100 | traceback.format_exc(), decorated_path, error.message)) |
| 101 | # Our chosen local bdist path. |
| 102 | bdist_path = target_bdist_basename + GRPC_CUSTOM_BDIST_EXT |
| 103 | try: |
| 104 | with open(bdist_path, 'w') as bdist_file: |
| 105 | bdist_file.write(bdist_data) |
| 106 | except IOError as error: |
| 107 | raise CommandError('{}\n\nCould not write grpcio bdist: {}' |
| 108 | .format(traceback.format_exc(), error.message)) |
| 109 | return bdist_path |
Masood Malekghassemi | 154b0ee | 2016-01-25 16:45:29 -0800 | [diff] [blame] | 110 | |
| 111 | |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 112 | class SphinxDocumentation(setuptools.Command): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 113 | """Command to generate documentation via sphinx.""" |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 114 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 115 | description = 'generate sphinx documentation' |
| 116 | user_options = [] |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 117 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 118 | def initialize_options(self): |
| 119 | pass |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 120 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 121 | def finalize_options(self): |
| 122 | pass |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 123 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 124 | def run(self): |
| 125 | # We import here to ensure that setup.py has had a chance to install the |
| 126 | # relevant package eggs first. |
| 127 | import sphinx |
| 128 | import sphinx.apidoc |
| 129 | metadata = self.distribution.metadata |
| 130 | src_dir = os.path.join(PYTHON_STEM, 'grpc') |
| 131 | sys.path.append(src_dir) |
| 132 | sphinx.apidoc.main([ |
| 133 | '', '--force', '--full', '-H', metadata.name, '-A', metadata.author, |
| 134 | '-V', metadata.version, '-R', metadata.version, '-o', |
| 135 | os.path.join('doc', 'src'), src_dir |
| 136 | ]) |
| 137 | conf_filepath = os.path.join('doc', 'src', 'conf.py') |
| 138 | with open(conf_filepath, 'a') as conf_file: |
| 139 | conf_file.write(CONF_PY_ADDENDUM) |
| 140 | glossary_filepath = os.path.join('doc', 'src', 'grpc.rst') |
| 141 | with open(glossary_filepath, 'a') as glossary_filepath: |
| 142 | glossary_filepath.write(API_GLOSSARY) |
| 143 | sphinx.main( |
| 144 | ['', os.path.join('doc', 'src'), os.path.join('doc', 'build')]) |
Masood Malekghassemi | d65632a | 2015-07-27 14:30:09 -0700 | [diff] [blame] | 145 | |
Masood Malekghassemi | 5c14763 | 2015-07-31 14:08:19 -0700 | [diff] [blame] | 146 | |
| 147 | class BuildProjectMetadata(setuptools.Command): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 148 | """Command to generate project metadata in a module.""" |
Masood Malekghassemi | 5c14763 | 2015-07-31 14:08:19 -0700 | [diff] [blame] | 149 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 150 | description = 'build grpcio project metadata files' |
| 151 | user_options = [] |
Masood Malekghassemi | 5c14763 | 2015-07-31 14:08:19 -0700 | [diff] [blame] | 152 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 153 | def initialize_options(self): |
| 154 | pass |
Masood Malekghassemi | 5c14763 | 2015-07-31 14:08:19 -0700 | [diff] [blame] | 155 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 156 | def finalize_options(self): |
| 157 | pass |
Masood Malekghassemi | 5c14763 | 2015-07-31 14:08:19 -0700 | [diff] [blame] | 158 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 159 | def run(self): |
| 160 | with open(os.path.join(PYTHON_STEM, 'grpc/_grpcio_metadata.py'), |
| 161 | 'w') as module_file: |
| 162 | module_file.write('__version__ = """{}"""'.format( |
| 163 | self.distribution.get_version())) |
Masood Malekghassemi | 5c14763 | 2015-07-31 14:08:19 -0700 | [diff] [blame] | 164 | |
| 165 | |
| 166 | class BuildPy(build_py.build_py): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 167 | """Custom project build command.""" |
Masood Malekghassemi | 5c14763 | 2015-07-31 14:08:19 -0700 | [diff] [blame] | 168 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 169 | def run(self): |
| 170 | self.run_command('build_project_metadata') |
| 171 | build_py.build_py.run(self) |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 172 | |
| 173 | |
Masood Malekghassemi | fd9cc10 | 2016-07-21 14:20:43 -0700 | [diff] [blame] | 174 | def _poison_extensions(extensions, message): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 175 | """Includes a file that will always fail to compile in all extensions.""" |
| 176 | poison_filename = os.path.join(PYTHON_STEM, 'poison.c') |
| 177 | with open(poison_filename, 'w') as poison: |
| 178 | poison.write('#error {}'.format(message)) |
| 179 | for extension in extensions: |
| 180 | extension.sources = [poison_filename] |
| 181 | |
Masood Malekghassemi | fd9cc10 | 2016-07-21 14:20:43 -0700 | [diff] [blame] | 182 | |
| 183 | def check_and_update_cythonization(extensions): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 184 | """Replace .pyx files with their generated counterparts and return whether or |
Masood Malekghassemi | fd9cc10 | 2016-07-21 14:20:43 -0700 | [diff] [blame] | 185 | not cythonization still needs to occur.""" |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 186 | for extension in extensions: |
| 187 | generated_pyx_sources = [] |
| 188 | other_sources = [] |
| 189 | for source in extension.sources: |
| 190 | base, file_ext = os.path.splitext(source) |
| 191 | if file_ext == '.pyx': |
| 192 | generated_pyx_source = next((base + gen_ext |
Ken Payson | 2fa5f2f | 2017-02-06 10:27:09 -0800 | [diff] [blame] | 193 | for gen_ext in ('.c', '.cpp',) |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 194 | if os.path.isfile(base + gen_ext)), |
| 195 | None) |
| 196 | if generated_pyx_source: |
| 197 | generated_pyx_sources.append(generated_pyx_source) |
| 198 | else: |
| 199 | sys.stderr.write('Cython-generated files are missing...\n') |
| 200 | return False |
| 201 | else: |
| 202 | other_sources.append(source) |
| 203 | extension.sources = generated_pyx_sources + other_sources |
| 204 | sys.stderr.write('Found cython-generated files...\n') |
| 205 | return True |
| 206 | |
Masood Malekghassemi | fd9cc10 | 2016-07-21 14:20:43 -0700 | [diff] [blame] | 207 | |
| 208 | def try_cythonize(extensions, linetracing=False, mandatory=True): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 209 | """Attempt to cythonize the extensions. |
Masood Malekghassemi | fd9cc10 | 2016-07-21 14:20:43 -0700 | [diff] [blame] | 210 | |
| 211 | Args: |
| 212 | extensions: A list of `distutils.extension.Extension`. |
| 213 | linetracing: A bool indicating whether or not to enable linetracing. |
| 214 | mandatory: Whether or not having Cython-generated files is mandatory. If it |
| 215 | is, extensions will be poisoned when they can't be fully generated. |
| 216 | """ |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 217 | try: |
| 218 | # Break import style to ensure we have access to Cython post-setup_requires |
| 219 | import Cython.Build |
| 220 | except ImportError: |
| 221 | if mandatory: |
| 222 | sys.stderr.write( |
| 223 | "This package needs to generate C files with Cython but it cannot. " |
| 224 | "Poisoning extension sources to disallow extension commands...") |
| 225 | _poison_extensions( |
| 226 | extensions, |
| 227 | "Extensions have been poisoned due to missing Cython-generated code." |
| 228 | ) |
| 229 | return extensions |
| 230 | cython_compiler_directives = {} |
| 231 | if linetracing: |
| 232 | additional_define_macros = [('CYTHON_TRACE_NOGIL', '1')] |
| 233 | cython_compiler_directives['linetrace'] = True |
| 234 | return Cython.Build.cythonize( |
| 235 | extensions, |
| 236 | include_path=[ |
| 237 | include_dir |
| 238 | for extension in extensions |
| 239 | for include_dir in extension.include_dirs |
| 240 | ] + [CYTHON_STEM], |
| 241 | compiler_directives=cython_compiler_directives) |
Masood Malekghassemi | fd9cc10 | 2016-07-21 14:20:43 -0700 | [diff] [blame] | 242 | |
| 243 | |
Masood Malekghassemi | 14a0a93 | 2016-01-21 20:13:22 -0800 | [diff] [blame] | 244 | class BuildExt(build_ext.build_ext): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 245 | """Custom build_ext command to enable compiler-specific flags.""" |
Masood Malekghassemi | 1d17781 | 2016-01-12 09:21:57 -0800 | [diff] [blame] | 246 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 247 | C_OPTIONS = { |
Ken Payson | 3b90055 | 2017-04-10 15:53:17 -0700 | [diff] [blame] | 248 | 'unix': ('-pthread',), |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 249 | 'msvc': (), |
| 250 | } |
| 251 | LINK_OPTIONS = {} |
Masood Malekghassemi | 1d17781 | 2016-01-12 09:21:57 -0800 | [diff] [blame] | 252 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 253 | def build_extensions(self): |
Ken Payson | 571c75a | 2017-04-13 16:39:37 -0700 | [diff] [blame] | 254 | if "darwin" in sys.platform: |
Ken Payson | 63b0d11 | 2017-04-17 00:03:40 -0700 | [diff] [blame] | 255 | config = os.environ.get('CONFIG', 'opt') |
Ken Payson | 571c75a | 2017-04-13 16:39:37 -0700 | [diff] [blame] | 256 | target_path = os.path.abspath( |
Ken Payson | 0eac8aa | 2017-04-17 01:58:15 -0700 | [diff] [blame] | 257 | os.path.join( |
| 258 | os.path.dirname(os.path.realpath(__file__)), '..', '..', |
| 259 | '..', 'libs', config)) |
| 260 | targets = [ |
| 261 | os.path.join(target_path, 'libboringssl.a'), |
| 262 | os.path.join(target_path, 'libares.a'), |
| 263 | os.path.join(target_path, 'libgpr.a'), |
| 264 | os.path.join(target_path, 'libgrpc.a') |
| 265 | ] |
| 266 | make_process = subprocess.Popen( |
| 267 | ['make'] + targets, |
| 268 | stdout=subprocess.PIPE, |
| 269 | stderr=subprocess.PIPE) |
Ken Payson | 571c75a | 2017-04-13 16:39:37 -0700 | [diff] [blame] | 270 | make_out, make_err = make_process.communicate() |
| 271 | if make_out and make_process.returncode != 0: |
Ken Payson | b91c5fb | 2017-05-09 13:28:32 -0700 | [diff] [blame] | 272 | sys.stdout.write(str(make_out) + '\n') |
Ken Payson | 571c75a | 2017-04-13 16:39:37 -0700 | [diff] [blame] | 273 | if make_err: |
Ken Payson | b91c5fb | 2017-05-09 13:28:32 -0700 | [diff] [blame] | 274 | sys.stderr.write(str(make_err) + '\n') |
Ken Payson | 571c75a | 2017-04-13 16:39:37 -0700 | [diff] [blame] | 275 | if make_process.returncode != 0: |
Ken Payson | 0eac8aa | 2017-04-17 01:58:15 -0700 | [diff] [blame] | 276 | raise Exception("make command failed!") |
Ken Payson | 571c75a | 2017-04-13 16:39:37 -0700 | [diff] [blame] | 277 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 278 | compiler = self.compiler.compiler_type |
| 279 | if compiler in BuildExt.C_OPTIONS: |
| 280 | for extension in self.extensions: |
Masood Malekghassemi | 6b890d1 | 2017-01-23 12:02:08 -0500 | [diff] [blame] | 281 | extension.extra_compile_args += list( |
| 282 | BuildExt.C_OPTIONS[compiler]) |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 283 | if compiler in BuildExt.LINK_OPTIONS: |
| 284 | for extension in self.extensions: |
Masood Malekghassemi | 6b890d1 | 2017-01-23 12:02:08 -0500 | [diff] [blame] | 285 | extension.extra_link_args += list( |
| 286 | BuildExt.LINK_OPTIONS[compiler]) |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 287 | if not check_and_update_cythonization(self.extensions): |
| 288 | self.extensions = try_cythonize(self.extensions) |
| 289 | try: |
| 290 | build_ext.build_ext.build_extensions(self) |
| 291 | except Exception as error: |
| 292 | formatted_exception = traceback.format_exc() |
| 293 | support.diagnose_build_ext_error(self, error, formatted_exception) |
Masood Malekghassemi | 6b890d1 | 2017-01-23 12:02:08 -0500 | [diff] [blame] | 294 | raise CommandError( |
| 295 | "Failed `build_ext` step:\n{}".format(formatted_exception)) |
Masood Malekghassemi | 1d17781 | 2016-01-12 09:21:57 -0800 | [diff] [blame] | 296 | |
| 297 | |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 298 | class Gather(setuptools.Command): |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 299 | """Command to gather project dependencies.""" |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 300 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 301 | description = 'gather dependencies for grpcio' |
| 302 | user_options = [ |
| 303 | ('test', 't', 'flag indicating to gather test dependencies'), |
| 304 | ('install', 'i', 'flag indicating to gather install dependencies') |
| 305 | ] |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 306 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 307 | def initialize_options(self): |
| 308 | self.test = False |
| 309 | self.install = False |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 310 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 311 | def finalize_options(self): |
| 312 | # distutils requires this override. |
| 313 | pass |
Masood Malekghassemi | 7566c9a | 2015-10-21 20:29:23 -0700 | [diff] [blame] | 314 | |
Masood Malekghassemi | cc79370 | 2017-01-13 19:20:10 -0800 | [diff] [blame] | 315 | def run(self): |
| 316 | if self.install and self.distribution.install_requires: |
| 317 | self.distribution.fetch_build_eggs( |
| 318 | self.distribution.install_requires) |
| 319 | if self.test and self.distribution.tests_require: |
| 320 | self.distribution.fetch_build_eggs(self.distribution.tests_require) |