aboutsummaryrefslogtreecommitdiffhomepage
path: root/setup.py
diff options
context:
space:
mode:
authorGravatar Masood Malekghassemi <atash@google.com>2016-07-08 12:07:49 -0700
committerGravatar Masood Malekghassemi <atash@google.com>2016-07-08 12:07:49 -0700
commitf17f0f6b071fe42f0d57e6b2f08d797bcbcad88a (patch)
tree1f4175a04b30a3d70374a8ec881c0dbe235f2e29 /setup.py
parentf5d5ad823d02a64b3aa6606652e869de21ea4c09 (diff)
Fallback to generating files if not generated
Even if GRPC_PYTHON_BUILD_WITH_CYTHON is not specified, if the files are not present then we will fall back to generating with Cython. This relegates GRPC_PYTHON_BUILD_WITH_CYTHON to providing a regeneration option rather than being a necessary build environment variable.
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/setup.py b/setup.py
index d9c46ba77a..2eeb37db83 100644
--- a/setup.py
+++ b/setup.py
@@ -64,7 +64,9 @@ LICENSE = '3-clause BSD'
# Environment variable to determine whether or not the Cython extension should
# *use* Cython or use the generated C files. Note that this requires the C files
-# to have been generated by building first *with* Cython support.
+# to have been generated by building first *with* Cython support. Even if this
+# is set to false, if the script detects that the generated `.c` file isn't
+# present, then it will still attempt to use Cython.
BUILD_WITH_CYTHON = os.environ.get('GRPC_PYTHON_BUILD_WITH_CYTHON', False)
# Environment variable to determine whether or not to enable coverage analysis
@@ -129,10 +131,20 @@ def cython_extensions(module_names, extra_sources, include_dirs,
if ENABLE_CYTHON_TRACING:
define_macros = define_macros + [('CYTHON_TRACE_NOGIL', 1)]
cython_compiler_directives['linetrace'] = True
- file_extension = 'pyx' if build_with_cython else 'c'
- module_files = [os.path.join(PYTHON_STEM,
- name.replace('.', '/') + '.' + file_extension)
- for name in module_names]
+ 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
extensions = [
_extension.Extension(
name=module_name,