aboutsummaryrefslogtreecommitdiffhomepage
path: root/setup.py
diff options
context:
space:
mode:
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py100
1 files changed, 43 insertions, 57 deletions
diff --git a/setup.py b/setup.py
index 6dbc169053..cad300c144 100644
--- a/setup.py
+++ b/setup.py
@@ -29,17 +29,18 @@
"""A setup module for the GRPC Python package."""
+from distutils import extension as _extension
+from distutils import util
import os
import os.path
+import pkg_resources
import platform
+import re
import shlex
import shutil
import sys
import sysconfig
-from distutils import core as _core
-from distutils import extension as _extension
-import pkg_resources
import setuptools
from setuptools.command import egg_info
@@ -47,10 +48,10 @@ from setuptools.command import egg_info
egg_info.manifest_maker.template = 'PYTHON-MANIFEST.in'
PY3 = sys.version_info.major == 3
-PYTHON_STEM = './src/python/grpcio'
-CORE_INCLUDE = ('./include', '.',)
-BORINGSSL_INCLUDE = ('./third_party/boringssl/include',)
-ZLIB_INCLUDE = ('./third_party/zlib',)
+PYTHON_STEM = os.path.join('src', 'python', 'grpcio')
+CORE_INCLUDE = ('include', '.',)
+BORINGSSL_INCLUDE = (os.path.join('third_party', 'boringssl', 'include'),)
+ZLIB_INCLUDE = (os.path.join('third_party', 'zlib'),)
# Ensure we're in the proper directory whether or not we're being used by pip.
os.chdir(os.path.dirname(os.path.abspath(__file__)))
@@ -123,10 +124,7 @@ CYTHON_EXTENSION_PACKAGE_NAMES = ()
CYTHON_EXTENSION_MODULE_NAMES = ('grpc._cython.cygrpc',)
-CYTHON_HELPER_C_FILES = (
- os.path.join(PYTHON_STEM, 'grpc/_cython/loader.c'),
- os.path.join(PYTHON_STEM, 'grpc/_cython/imports.generated.c'),
-)
+CYTHON_HELPER_C_FILES = ()
CORE_C_FILES = tuple(grpc_core_dependencies.CORE_SOURCE_FILES)
@@ -141,7 +139,9 @@ if not "win32" in sys.platform:
if "win32" in sys.platform:
EXTENSION_LIBRARIES += ('ws2_32',)
-DEFINE_MACROS = (('OPENSSL_NO_ASM', 1), ('_WIN32_WINNT', 0x600), ('GPR_BACKWARDS_COMPATIBILITY_MODE', 1),)
+DEFINE_MACROS = (
+ ('OPENSSL_NO_ASM', 1), ('_WIN32_WINNT', 0x600),
+ ('GPR_BACKWARDS_COMPATIBILITY_MODE', 1),)
if "win32" in sys.platform:
DEFINE_MACROS += (('OPENSSL_WINDOWS', 1), ('WIN32_LEAN_AND_MEAN', 1),)
if '64bit' in platform.architecture()[0]:
@@ -163,56 +163,32 @@ if 'darwin' in sys.platform and PY3:
if mac_target and (pkg_resources.parse_version(mac_target) <
pkg_resources.parse_version('10.7.0')):
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.7'
-
-
-def cython_extensions():
- module_names = list(CYTHON_EXTENSION_MODULE_NAMES)
- extra_sources = list(CYTHON_HELPER_C_FILES) + list(CORE_C_FILES)
- include_dirs = list(EXTENSION_INCLUDE_DIRECTORIES)
- libraries = list(EXTENSION_LIBRARIES)
- define_macros = list(DEFINE_MACROS)
- build_with_cython = bool(BUILD_WITH_CYTHON)
- # Set compiler directives linetrace argument only if we care about tracing;
- # this is due to Cython having different behavior between linetrace being
- # False and linetrace being unset. See issue #5689.
- cython_compiler_directives = {}
- if ENABLE_CYTHON_TRACING:
- define_macros = define_macros + [('CYTHON_TRACE_NOGIL', 1)]
- cython_compiler_directives['linetrace'] = True
- pyx_module_files = [os.path.join(PYTHON_STEM,
- name.replace('.', '/') + '.pyx')
- for name in module_names]
- c_module_files = [os.path.join(PYTHON_STEM,
- name.replace('.', '/') + '.c')
- for name in module_names]
- if not build_with_cython:
- for module_file in c_module_files:
- if not os.path.isfile(module_file):
- sys.stderr.write('Cython-generated files are missing; '
- 'forcing Cython build...\n')
- build_with_cython = True
- break
- module_files = pyx_module_files if build_with_cython else c_module_files
+ os.environ['_PYTHON_HOST_PLATFORM'] = re.sub(
+ r'macosx-[0-9]+\.[0-9]+-(.+)',
+ r'macosx-10.7-\1',
+ util.get_platform())
+
+def cython_extensions_and_necessity():
+ cython_module_files = [os.path.join(PYTHON_STEM,
+ name.replace('.', '/') + '.pyx')
+ for name in CYTHON_EXTENSION_MODULE_NAMES]
extensions = [
_extension.Extension(
name=module_name,
- sources=[module_file] + extra_sources,
- include_dirs=include_dirs, libraries=libraries,
- define_macros=define_macros,
+ sources=[module_file] + list(CYTHON_HELPER_C_FILES) + list(CORE_C_FILES),
+ include_dirs=list(EXTENSION_INCLUDE_DIRECTORIES),
+ libraries=list(EXTENSION_LIBRARIES),
+ define_macros=list(DEFINE_MACROS),
extra_compile_args=list(CFLAGS),
extra_link_args=list(LDFLAGS),
- ) for (module_name, module_file) in zip(module_names, module_files)
+ ) for (module_name, module_file) in zip(list(CYTHON_EXTENSION_MODULE_NAMES), cython_module_files)
]
- if build_with_cython:
- import Cython.Build
- return Cython.Build.cythonize(
- extensions,
- include_path=include_dirs,
- compiler_directives=cython_compiler_directives)
- else:
- return extensions
+ need_cython = BUILD_WITH_CYTHON
+ if not BUILD_WITH_CYTHON:
+ need_cython = need_cython or not commands.check_and_update_cythonization(extensions)
+ return commands.try_cythonize(extensions, linetracing=ENABLE_CYTHON_TRACING, mandatory=BUILD_WITH_CYTHON), need_cython
-CYTHON_EXTENSION_MODULES = cython_extensions()
+CYTHON_EXTENSION_MODULES, need_cython = cython_extensions_and_necessity()
PACKAGE_DIRECTORIES = {
'': PYTHON_STEM,
@@ -232,6 +208,15 @@ SETUP_REQUIRES = INSTALL_REQUIRES + (
'sphinx_rtd_theme>=0.1.8',
'six>=1.10',
)
+if BUILD_WITH_CYTHON:
+ sys.stderr.write(
+ "You requested a Cython build via GRPC_PYTHON_BUILD_WITH_CYTHON, "
+ "but do not have Cython installed. We won't stop you from using "
+ "other commands, but the extension files will fail to build.\n")
+elif need_cython:
+ sys.stderr.write(
+ 'We could not find Cython. Setup may take 10-20 minutes.\n')
+ SETUP_REQUIRES += ('cython>=0.23',)
COMMAND_CLASS = {
'doc': commands.SphinxDocumentation,
@@ -242,12 +227,13 @@ COMMAND_CLASS = {
}
# Ensure that package data is copied over before any commands have been run:
-credentials_dir = os.path.join(PYTHON_STEM, 'grpc/_cython/_credentials')
+credentials_dir = os.path.join(PYTHON_STEM, 'grpc', '_cython', '_credentials')
try:
os.mkdir(credentials_dir)
except OSError:
pass
-shutil.copyfile('etc/roots.pem', os.path.join(credentials_dir, 'roots.pem'))
+shutil.copyfile(os.path.join('etc', 'roots.pem'),
+ os.path.join(credentials_dir, 'roots.pem'))
PACKAGE_DATA = {
# Binaries that may or may not be present in the final installation, but are