setup.py
Go to the documentation of this file.
1 # Copyright 2015 gRPC authors.
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 """A setup module for the GRPC Python package."""
15 
16 # NOTE(https://github.com/grpc/grpc/issues/24028): allow setuptools to monkey
17 # patch distutils
18 import setuptools # isort:skip
19 
20 # Monkey Patch the unix compiler to accept ASM
21 # files used by boring SSL.
22 from distutils.unixccompiler import UnixCCompiler
23 
24 UnixCCompiler.src_extensions.append('.S')
25 del UnixCCompiler
26 
27 from distutils import cygwinccompiler
28 from distutils import extension as _extension
29 from distutils import util
30 import os
31 import os.path
32 import pathlib
33 import platform
34 import re
35 import shlex
36 import shutil
37 import subprocess
38 from subprocess import PIPE
39 import sys
40 import sysconfig
41 
42 import _metadata
43 import pkg_resources
44 from setuptools.command import egg_info
45 
46 # Redirect the manifest template from MANIFEST.in to PYTHON-MANIFEST.in.
47 egg_info.manifest_maker.template = 'PYTHON-MANIFEST.in'
48 
49 PY3 = sys.version_info.major == 3
50 PYTHON_STEM = os.path.join('src', 'python', 'grpcio')
51 CORE_INCLUDE = (
52  'include',
53  '.',
54 )
55 ABSL_INCLUDE = (os.path.join('third_party', 'abseil-cpp'),)
56 ADDRESS_SORTING_INCLUDE = (os.path.join('third_party', 'address_sorting',
57  'include'),)
58 CARES_INCLUDE = (
59  os.path.join('third_party', 'cares', 'cares', 'include'),
60  os.path.join('third_party', 'cares'),
61  os.path.join('third_party', 'cares', 'cares'),
62 )
63 if 'darwin' in sys.platform:
64  CARES_INCLUDE += (os.path.join('third_party', 'cares', 'config_darwin'),)
65 if 'freebsd' in sys.platform:
66  CARES_INCLUDE += (os.path.join('third_party', 'cares', 'config_freebsd'),)
67 if 'linux' in sys.platform:
68  CARES_INCLUDE += (os.path.join('third_party', 'cares', 'config_linux'),)
69 if 'openbsd' in sys.platform:
70  CARES_INCLUDE += (os.path.join('third_party', 'cares', 'config_openbsd'),)
71 RE2_INCLUDE = (os.path.join('third_party', 're2'),)
72 SSL_INCLUDE = (os.path.join('third_party', 'boringssl-with-bazel', 'src',
73  'include'),)
74 UPB_INCLUDE = (os.path.join('third_party', 'upb'),)
75 UPB_GRPC_GENERATED_INCLUDE = (os.path.join('src', 'core', 'ext',
76  'upb-generated'),)
77 UPBDEFS_GRPC_GENERATED_INCLUDE = (os.path.join('src', 'core', 'ext',
78  'upbdefs-generated'),)
79 XXHASH_INCLUDE = (os.path.join('third_party', 'xxhash'),)
80 ZLIB_INCLUDE = (os.path.join('third_party', 'zlib'),)
81 README = os.path.join(PYTHON_STEM, 'README.rst')
82 
83 # Ensure we're in the proper directory whether or not we're being used by pip.
84 os.chdir(os.path.dirname(os.path.abspath(__file__)))
85 sys.path.insert(0, os.path.abspath(PYTHON_STEM))
86 
87 # Break import-style to ensure we can actually find our in-repo dependencies.
88 import _parallel_compile_patch
89 import _spawn_patch
90 import grpc_core_dependencies
91 
92 import commands
93 import grpc_version
94 
97 
98 LICENSE = 'Apache License 2.0'
99 
100 CLASSIFIERS = [
101  'Development Status :: 5 - Production/Stable',
102  'Programming Language :: Python',
103  'Programming Language :: Python :: 3',
104  'Programming Language :: Python :: 3.5',
105  'Programming Language :: Python :: 3.6',
106  'Programming Language :: Python :: 3.7',
107  'Programming Language :: Python :: 3.8',
108  'Programming Language :: Python :: 3.9',
109  'Programming Language :: Python :: 3.10',
110  'License :: OSI Approved :: Apache Software License',
111 ]
112 
113 
114 def _env_bool_value(env_name, default):
115  """Parses a bool option from an environment variable"""
116  return os.environ.get(env_name, default).upper() not in ['FALSE', '0', '']
117 
118 
119 BUILD_WITH_BORING_SSL_ASM = _env_bool_value('GRPC_BUILD_WITH_BORING_SSL_ASM',
120  'True')
121 
122 # Export this environment variable to override the platform variant that will
123 # be chosen for boringssl assembly optimizations. This option is useful when
124 # crosscompiling and the host platform as obtained by distutils.utils.get_platform()
125 # doesn't match the platform we are targetting.
126 # Example value: "linux-aarch64"
127 BUILD_OVERRIDE_BORING_SSL_ASM_PLATFORM = os.environ.get(
128  'GRPC_BUILD_OVERRIDE_BORING_SSL_ASM_PLATFORM', '')
129 
130 # Environment variable to determine whether or not the Cython extension should
131 # *use* Cython or use the generated C files. Note that this requires the C files
132 # to have been generated by building first *with* Cython support. Even if this
133 # is set to false, if the script detects that the generated `.c` file isn't
134 # present, then it will still attempt to use Cython.
135 BUILD_WITH_CYTHON = _env_bool_value('GRPC_PYTHON_BUILD_WITH_CYTHON', 'False')
136 
137 # Export this variable to use the system installation of openssl. You need to
138 # have the header files installed (in /usr/include/openssl) and during
139 # runtime, the shared library must be installed
140 BUILD_WITH_SYSTEM_OPENSSL = _env_bool_value('GRPC_PYTHON_BUILD_SYSTEM_OPENSSL',
141  'False')
142 
143 # Export this variable to use the system installation of zlib. You need to
144 # have the header files installed (in /usr/include/) and during
145 # runtime, the shared library must be installed
146 BUILD_WITH_SYSTEM_ZLIB = _env_bool_value('GRPC_PYTHON_BUILD_SYSTEM_ZLIB',
147  'False')
148 
149 # Export this variable to use the system installation of cares. You need to
150 # have the header files installed (in /usr/include/) and during
151 # runtime, the shared library must be installed
152 BUILD_WITH_SYSTEM_CARES = _env_bool_value('GRPC_PYTHON_BUILD_SYSTEM_CARES',
153  'False')
154 
155 # Export this variable to use the system installation of re2. You need to
156 # have the header files installed (in /usr/include/re2) and during
157 # runtime, the shared library must be installed
158 BUILD_WITH_SYSTEM_RE2 = _env_bool_value('GRPC_PYTHON_BUILD_SYSTEM_RE2', 'False')
159 
160 # Export this variable to use the system installation of abseil. You need to
161 # have the header files installed (in /usr/include/absl) and during
162 # runtime, the shared library must be installed
163 BUILD_WITH_SYSTEM_ABSL = os.environ.get('GRPC_PYTHON_BUILD_SYSTEM_ABSL', False)
164 
165 # Export this variable to force building the python extension with a statically linked libstdc++.
166 # At least on linux, this is normally not needed as we can build manylinux-compatible wheels on linux just fine
167 # without statically linking libstdc++ (which leads to a slight increase in the wheel size).
168 # This option is useful when crosscompiling wheels for aarch64 where
169 # it's difficult to ensure that the crosscompilation toolchain has a high-enough version
170 # of GCC (we require >=5.1) but still uses old-enough libstdc++ symbols.
171 # TODO(jtattermusch): remove this workaround once issues with crosscompiler version are resolved.
172 BUILD_WITH_STATIC_LIBSTDCXX = _env_bool_value(
173  'GRPC_PYTHON_BUILD_WITH_STATIC_LIBSTDCXX', 'False')
174 
175 # For local development use only: This skips building gRPC Core and its
176 # dependencies, including protobuf and boringssl. This allows "incremental"
177 # compilation by first building gRPC Core using make, then building only the
178 # Python/Cython layers here.
179 #
180 # Note that this requires libboringssl.a in the libs/{dbg,opt}/ directory, which
181 # may require configuring make to not use the system openssl implementation:
182 #
183 # make HAS_SYSTEM_OPENSSL_ALPN=0
184 #
185 # TODO(ericgribkoff) Respect the BUILD_WITH_SYSTEM_* flags alongside this option
186 USE_PREBUILT_GRPC_CORE = _env_bool_value('GRPC_PYTHON_USE_PREBUILT_GRPC_CORE',
187  'False')
188 
189 # If this environmental variable is set, GRPC will not try to be compatible with
190 # libc versions old than the one it was compiled against.
191 DISABLE_LIBC_COMPATIBILITY = _env_bool_value(
192  'GRPC_PYTHON_DISABLE_LIBC_COMPATIBILITY', 'False')
193 
194 # Environment variable to determine whether or not to enable coverage analysis
195 # in Cython modules.
196 ENABLE_CYTHON_TRACING = _env_bool_value('GRPC_PYTHON_ENABLE_CYTHON_TRACING',
197  'False')
198 
199 # Environment variable specifying whether or not there's interest in setting up
200 # documentation building.
201 ENABLE_DOCUMENTATION_BUILD = _env_bool_value(
202  'GRPC_PYTHON_ENABLE_DOCUMENTATION_BUILD', 'False')
203 
204 
206  """Test if linker on system needs libatomic."""
207  code_test = (b'#include <atomic>\n' +
208  b'int main() { return std::atomic<int64_t>{}; }')
209  cxx = shlex.split(os.environ.get('CXX', 'c++'))
210  cpp_test = subprocess.Popen(cxx + ['-x', 'c++', '-std=c++14', '-'],
211  stdin=PIPE,
212  stdout=PIPE,
213  stderr=PIPE)
214  cpp_test.communicate(input=code_test)
215  if cpp_test.returncode == 0:
216  return False
217  # Double-check to see if -latomic actually can solve the problem.
218  # https://github.com/grpc/grpc/issues/22491
219  cpp_test = subprocess.Popen(
220  [cxx, '-x', 'c++', '-std=c++14', '-', '-latomic'],
221  stdin=PIPE,
222  stdout=PIPE,
223  stderr=PIPE)
224  cpp_test.communicate(input=code_test)
225  return cpp_test.returncode == 0
226 
227 
228 # There are some situations (like on Windows) where CC, CFLAGS, and LDFLAGS are
229 # entirely ignored/dropped/forgotten by distutils and its Cygwin/MinGW support.
230 # We use these environment variables to thus get around that without locking
231 # ourselves in w.r.t. the multitude of operating systems this ought to build on.
232 # We can also use these variables as a way to inject environment-specific
233 # compiler/linker flags. We assume GCC-like compilers and/or MinGW as a
234 # reasonable default.
235 EXTRA_ENV_COMPILE_ARGS = os.environ.get('GRPC_PYTHON_CFLAGS', None)
236 EXTRA_ENV_LINK_ARGS = os.environ.get('GRPC_PYTHON_LDFLAGS', None)
237 if EXTRA_ENV_COMPILE_ARGS is None:
238  EXTRA_ENV_COMPILE_ARGS = ' -std=c++14'
239  if 'win32' in sys.platform:
240  if sys.version_info < (3, 5):
241  EXTRA_ENV_COMPILE_ARGS += ' -D_hypot=hypot'
242  # We use define flags here and don't directly add to DEFINE_MACROS below to
243  # ensure that the expert user/builder has a way of turning it off (via the
244  # envvars) without adding yet more GRPC-specific envvars.
245  # See https://sourceforge.net/p/mingw-w64/bugs/363/
246  if '32' in platform.architecture()[0]:
247  EXTRA_ENV_COMPILE_ARGS += ' -D_ftime=_ftime32 -D_timeb=__timeb32 -D_ftime_s=_ftime32_s'
248  else:
249  EXTRA_ENV_COMPILE_ARGS += ' -D_ftime=_ftime64 -D_timeb=__timeb64'
250  else:
251  # We need to statically link the C++ Runtime, only the C runtime is
252  # available dynamically
253  EXTRA_ENV_COMPILE_ARGS += ' /MT'
254  elif "linux" in sys.platform:
255  EXTRA_ENV_COMPILE_ARGS += ' -fvisibility=hidden -fno-wrapv -fno-exceptions'
256  elif "darwin" in sys.platform:
257  EXTRA_ENV_COMPILE_ARGS += ' -stdlib=libc++ -fvisibility=hidden -fno-wrapv -fno-exceptions -DHAVE_UNISTD_H'
258 
259 if EXTRA_ENV_LINK_ARGS is None:
260  EXTRA_ENV_LINK_ARGS = ''
261  if "linux" in sys.platform or "darwin" in sys.platform:
262  EXTRA_ENV_LINK_ARGS += ' -lpthread'
264  EXTRA_ENV_LINK_ARGS += ' -latomic'
265  elif "win32" in sys.platform and sys.version_info < (3, 5):
266  msvcr = cygwinccompiler.get_msvcr()[0]
267  EXTRA_ENV_LINK_ARGS += (
268  ' -static-libgcc -static-libstdc++ -mcrtdll={msvcr}'
269  ' -static -lshlwapi'.format(msvcr=msvcr))
270  if "linux" in sys.platform:
271  EXTRA_ENV_LINK_ARGS += ' -static-libgcc'
272 
273 EXTRA_COMPILE_ARGS = shlex.split(EXTRA_ENV_COMPILE_ARGS)
274 EXTRA_LINK_ARGS = shlex.split(EXTRA_ENV_LINK_ARGS)
275 
276 if BUILD_WITH_STATIC_LIBSTDCXX:
277  EXTRA_LINK_ARGS.append('-static-libstdc++')
278 
279 CYTHON_EXTENSION_PACKAGE_NAMES = ()
280 
281 CYTHON_EXTENSION_MODULE_NAMES = ('grpc._cython.cygrpc',)
282 
283 CYTHON_HELPER_C_FILES = ()
284 
285 CORE_C_FILES = tuple(grpc_core_dependencies.CORE_SOURCE_FILES)
286 if "win32" in sys.platform:
287  CORE_C_FILES = filter(lambda x: 'third_party/cares' not in x, CORE_C_FILES)
288 
289 if BUILD_WITH_SYSTEM_OPENSSL:
290  CORE_C_FILES = filter(lambda x: 'third_party/boringssl' not in x,
291  CORE_C_FILES)
292  CORE_C_FILES = filter(lambda x: 'src/boringssl' not in x, CORE_C_FILES)
293  SSL_INCLUDE = (os.path.join('/usr', 'include', 'openssl'),)
294 
295 if BUILD_WITH_SYSTEM_ZLIB:
296  CORE_C_FILES = filter(lambda x: 'third_party/zlib' not in x, CORE_C_FILES)
297  ZLIB_INCLUDE = (os.path.join('/usr', 'include'),)
298 
299 if BUILD_WITH_SYSTEM_CARES:
300  CORE_C_FILES = filter(lambda x: 'third_party/cares' not in x, CORE_C_FILES)
301  CARES_INCLUDE = (os.path.join('/usr', 'include'),)
302 
303 if BUILD_WITH_SYSTEM_RE2:
304  CORE_C_FILES = filter(lambda x: 'third_party/re2' not in x, CORE_C_FILES)
305  RE2_INCLUDE = (os.path.join('/usr', 'include', 're2'),)
306 
307 if BUILD_WITH_SYSTEM_ABSL:
308  CORE_C_FILES = filter(lambda x: 'third_party/abseil-cpp' not in x,
309  CORE_C_FILES)
310  ABSL_INCLUDE = (os.path.join('/usr', 'include'),)
311 
312 EXTENSION_INCLUDE_DIRECTORIES = ((PYTHON_STEM,) + CORE_INCLUDE + ABSL_INCLUDE +
313  ADDRESS_SORTING_INCLUDE + CARES_INCLUDE +
314  RE2_INCLUDE + SSL_INCLUDE + UPB_INCLUDE +
315  UPB_GRPC_GENERATED_INCLUDE +
316  UPBDEFS_GRPC_GENERATED_INCLUDE +
317  XXHASH_INCLUDE + ZLIB_INCLUDE)
318 
319 EXTENSION_LIBRARIES = ()
320 if "linux" in sys.platform:
321  EXTENSION_LIBRARIES += ('rt',)
322 if not "win32" in sys.platform:
323  EXTENSION_LIBRARIES += ('m',)
324 if "win32" in sys.platform:
325  EXTENSION_LIBRARIES += (
326  'advapi32',
327  'bcrypt',
328  'dbghelp',
329  'ws2_32',
330  )
331 if BUILD_WITH_SYSTEM_OPENSSL:
332  EXTENSION_LIBRARIES += (
333  'ssl',
334  'crypto',
335  )
336 if BUILD_WITH_SYSTEM_ZLIB:
337  EXTENSION_LIBRARIES += ('z',)
338 if BUILD_WITH_SYSTEM_CARES:
339  EXTENSION_LIBRARIES += ('cares',)
340 if BUILD_WITH_SYSTEM_RE2:
341  EXTENSION_LIBRARIES += ('re2',)
342 if BUILD_WITH_SYSTEM_ABSL:
343  EXTENSION_LIBRARIES += tuple(
344  lib.stem[3:] for lib in pathlib.Path('/usr').glob('lib*/libabsl_*.so'))
345 
346 DEFINE_MACROS = (('_WIN32_WINNT', 0x600),)
347 asm_files = []
348 
349 
350 # Quotes on Windows build macros are evaluated differently from other platforms,
351 # so we must apply quotes asymmetrically in order to yield the proper result in
352 # the binary.
353 def _quote_build_define(argument):
354  if "win32" in sys.platform:
355  return '"\\\"{}\\\""'.format(argument)
356  return '"{}"'.format(argument)
357 
358 
359 DEFINE_MACROS += (
360  ("GRPC_XDS_USER_AGENT_NAME_SUFFIX", _quote_build_define("Python")),
361  ("GRPC_XDS_USER_AGENT_VERSION_SUFFIX",
362  _quote_build_define(_metadata.__version__)),
363 )
364 
365 asm_key = ''
366 if BUILD_WITH_BORING_SSL_ASM and not BUILD_WITH_SYSTEM_OPENSSL:
367  boringssl_asm_platform = BUILD_OVERRIDE_BORING_SSL_ASM_PLATFORM if BUILD_OVERRIDE_BORING_SSL_ASM_PLATFORM else util.get_platform(
368  )
369  LINUX_X86_64 = 'linux-x86_64'
370  LINUX_ARM = 'linux-arm'
371  LINUX_AARCH64 = 'linux-aarch64'
372  if LINUX_X86_64 == boringssl_asm_platform:
373  asm_key = 'crypto_linux_x86_64'
374  elif LINUX_ARM == boringssl_asm_platform:
375  asm_key = 'crypto_linux_arm'
376  elif LINUX_AARCH64 == boringssl_asm_platform:
377  asm_key = 'crypto_linux_aarch64'
378  elif "mac" in boringssl_asm_platform and "x86_64" in boringssl_asm_platform:
379  asm_key = 'crypto_mac_x86_64'
380  else:
381  print("ASM Builds for BoringSSL currently not supported on:",
382  boringssl_asm_platform)
383 if asm_key:
384  asm_files = grpc_core_dependencies.ASM_SOURCE_FILES[asm_key]
385 else:
386  DEFINE_MACROS += (('OPENSSL_NO_ASM', 1),)
387 
388 if not DISABLE_LIBC_COMPATIBILITY:
389  DEFINE_MACROS += (('GPR_BACKWARDS_COMPATIBILITY_MODE', 1),)
390 
391 if "win32" in sys.platform:
392  # TODO(zyc): Re-enable c-ares on x64 and x86 windows after fixing the
393  # ares_library_init compilation issue
394  DEFINE_MACROS += (
395  ('WIN32_LEAN_AND_MEAN', 1),
396  ('CARES_STATICLIB', 1),
397  ('GRPC_ARES', 0),
398  ('NTDDI_VERSION', 0x06000000),
399  ('NOMINMAX', 1),
400  )
401  if '64bit' in platform.architecture()[0]:
402  DEFINE_MACROS += (('MS_WIN64', 1),)
403  elif sys.version_info >= (3, 5):
404  # For some reason, this is needed to get access to inet_pton/inet_ntop
405  # on msvc, but only for 32 bits
406  DEFINE_MACROS += (('NTDDI_VERSION', 0x06000000),)
407 else:
408  DEFINE_MACROS += (
409  ('HAVE_CONFIG_H', 1),
410  ('GRPC_ENABLE_FORK_SUPPORT', 1),
411  )
412 
413 LDFLAGS = tuple(EXTRA_LINK_ARGS)
414 CFLAGS = tuple(EXTRA_COMPILE_ARGS)
415 if "linux" in sys.platform or "darwin" in sys.platform:
416  pymodinit_type = 'PyObject*' if PY3 else 'void'
417  pymodinit = 'extern "C" __attribute__((visibility ("default"))) {}'.format(
418  pymodinit_type)
419  DEFINE_MACROS += (('PyMODINIT_FUNC', pymodinit),)
420  DEFINE_MACROS += (('GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK', 1),)
421 
422 # By default, Python3 distutils enforces compatibility of
423 # c plugins (.so files) with the OSX version Python was built with.
424 # We need OSX 10.10, the oldest which supports C++ thread_local.
425 # Python 3.9: Mac OS Big Sur sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') returns int (11)
426 if 'darwin' in sys.platform:
427  mac_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
428  if mac_target:
429  mac_target = pkg_resources.parse_version(str(mac_target))
430  if mac_target < pkg_resources.parse_version('10.10.0'):
431  os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.10'
432  os.environ['_PYTHON_HOST_PLATFORM'] = re.sub(
433  r'macosx-[0-9]+\.[0-9]+-(.+)', r'macosx-10.10-\1',
434  util.get_platform())
435 
436 
438  cython_module_files = [
439  os.path.join(PYTHON_STEM,
440  name.replace('.', '/') + '.pyx')
441  for name in CYTHON_EXTENSION_MODULE_NAMES
442  ]
443  config = os.environ.get('CONFIG', 'opt')
444  prefix = 'libs/' + config + '/'
445  if USE_PREBUILT_GRPC_CORE:
446  extra_objects = [
447  prefix + 'libares.a', prefix + 'libboringssl.a',
448  prefix + 'libgpr.a', prefix + 'libgrpc.a'
449  ]
450  core_c_files = []
451  else:
452  core_c_files = list(CORE_C_FILES)
453  extra_objects = []
454  extensions = [
455  _extension.Extension(
456  name=module_name,
457  sources=([module_file] + list(CYTHON_HELPER_C_FILES) +
458  core_c_files + asm_files),
459  include_dirs=list(EXTENSION_INCLUDE_DIRECTORIES),
460  libraries=list(EXTENSION_LIBRARIES),
461  define_macros=list(DEFINE_MACROS),
462  extra_objects=extra_objects,
463  extra_compile_args=list(CFLAGS),
464  extra_link_args=list(LDFLAGS),
465  ) for (module_name, module_file
466  ) in zip(list(CYTHON_EXTENSION_MODULE_NAMES), cython_module_files)
467  ]
468  need_cython = BUILD_WITH_CYTHON
469  if not BUILD_WITH_CYTHON:
470  need_cython = need_cython or not commands.check_and_update_cythonization(
471  extensions)
472  # TODO: the strategy for conditional compiling and exposing the aio Cython
473  # dependencies will be revisited by https://github.com/grpc/grpc/issues/19728
474  return commands.try_cythonize(extensions,
475  linetracing=ENABLE_CYTHON_TRACING,
476  mandatory=BUILD_WITH_CYTHON), need_cython
477 
478 
479 CYTHON_EXTENSION_MODULES, need_cython = cython_extensions_and_necessity()
480 
481 PACKAGE_DIRECTORIES = {
482  '': PYTHON_STEM,
483 }
484 
485 INSTALL_REQUIRES = (
486  "six>=1.5.2",
487  "futures>=2.2.0; python_version<'3.2'",
488  "enum34>=1.0.4; python_version<'3.4'",
489 )
490 EXTRAS_REQUIRES = {
491  'protobuf': 'grpcio-tools>={version}'.format(version=grpc_version.VERSION),
492 }
493 
494 SETUP_REQUIRES = INSTALL_REQUIRES + (
495  'Sphinx~=1.8.1',
496  'six>=1.10',
497 ) if ENABLE_DOCUMENTATION_BUILD else ()
498 
499 try:
500  import Cython
501 except ImportError:
502  if BUILD_WITH_CYTHON:
503  sys.stderr.write(
504  "You requested a Cython build via GRPC_PYTHON_BUILD_WITH_CYTHON, "
505  "but do not have Cython installed. We won't stop you from using "
506  "other commands, but the extension files will fail to build.\n")
507  elif need_cython:
508  sys.stderr.write(
509  'We could not find Cython. Setup may take 10-20 minutes.\n')
510  SETUP_REQUIRES += ('cython>=0.23',)
511 
512 COMMAND_CLASS = {
514  'build_project_metadata': commands.BuildProjectMetadata,
515  'build_py': commands.BuildPy,
516  'build_ext': commands.BuildExt,
517  'gather': commands.Gather,
518  'clean': commands.Clean,
519 }
520 
521 # Ensure that package data is copied over before any commands have been run:
522 credentials_dir = os.path.join(PYTHON_STEM, 'grpc', '_cython', '_credentials')
523 try:
524  os.mkdir(credentials_dir)
525 except OSError:
526  pass
527 shutil.copyfile(os.path.join('etc', 'roots.pem'),
528  os.path.join(credentials_dir, 'roots.pem'))
529 
530 PACKAGE_DATA = {
531  # Binaries that may or may not be present in the final installation, but are
532  # mentioned here for completeness.
533  'grpc._cython': [
534  '_credentials/roots.pem',
535  '_windows/grpc_c.32.python',
536  '_windows/grpc_c.64.python',
537  ],
538 }
539 PACKAGES = setuptools.find_packages(PYTHON_STEM)
540 
541 setuptools.setup(
542  name='grpcio',
543  version=grpc_version.VERSION,
544  description='HTTP/2-based RPC framework',
545  author='The gRPC Authors',
546  author_email='grpc-io@googlegroups.com',
547  url='https://grpc.io',
548  license=LICENSE,
549  classifiers=CLASSIFIERS,
550  long_description=open(README).read(),
551  ext_modules=CYTHON_EXTENSION_MODULES,
552  packages=list(PACKAGES),
553  package_dir=PACKAGE_DIRECTORIES,
554  package_data=PACKAGE_DATA,
555  python_requires='>=3.6',
556  install_requires=INSTALL_REQUIRES,
557  extras_require=EXTRAS_REQUIRES,
558  setup_requires=SETUP_REQUIRES,
559  cmdclass=COMMAND_CLASS,
560 )
xds_interop_client.str
str
Definition: xds_interop_client.py:487
commands.try_cythonize
def try_cythonize(extensions, linetracing=False, mandatory=True)
Definition: commands.py:165
http2_test_server.format
format
Definition: http2_test_server.py:118
commands.SphinxDocumentation
Definition: commands.py:79
commands.BuildPy
Definition: commands.py:123
commands.BuildExt
Definition: commands.py:200
setup.check_linker_need_libatomic
def check_linker_need_libatomic()
Definition: setup.py:205
commands.check_and_update_cythonization
def check_and_update_cythonization(extensions)
Definition: commands.py:140
setup.cython_extensions_and_necessity
def cython_extensions_and_necessity()
Definition: setup.py:437
setup._env_bool_value
def _env_bool_value(env_name, default)
Definition: setup.py:114
_parallel_compile_patch.monkeypatch_compile_maybe
def monkeypatch_compile_maybe()
Definition: src/python/grpcio/_parallel_compile_patch.py:63
_spawn_patch.monkeypatch_spawn
def monkeypatch_spawn()
Definition: _spawn_patch.py:57
commands.Gather
Definition: commands.py:288
read
int read(izstream &zs, T *x, Items items)
Definition: bloaty/third_party/zlib/contrib/iostream2/zstream.h:115
commands.BuildProjectMetadata
Definition: commands.py:104
open
#define open
Definition: test-fs.c:46
commands.Clean
Definition: commands.py:313
setup._quote_build_define
def _quote_build_define(argument)
Definition: setup.py:353


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:18