Debian Codegraph @

setup.py

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