15 from distutils
import errors
26 int main(int argc, char **argv) { return 0; }
28 C_PYTHON_DEV_ERROR_MESSAGE =
"""
29 Could not find <Python.h>. This could mean the following:
30 * You're on Ubuntu and haven't run `apt-get install <PY_REPR>-dev`.
31 * You're on RHEL/Fedora and haven't run `yum install <PY_REPR>-devel` or
32 `dnf install <PY_REPR>-devel` (make sure you also have redhat-rpm-config
34 * You're on Mac OS X and the usual Python framework was somehow corrupted
35 (check your environment variables or try re-installing?)
36 * You're on Windows and your Python installation was somehow corrupted
37 (check your environment variables or try re-installing?)
39 if sys.version_info[0] == 2:
40 PYTHON_REPRESENTATION =
'python'
41 elif sys.version_info[0] == 3:
42 PYTHON_REPRESENTATION =
'python3'
44 raise NotImplementedError(
'Unsupported Python version: %s' % sys.version)
48 C_PYTHON_DEV_ERROR_MESSAGE.replace(
'<PY_REPR>', PYTHON_REPRESENTATION),
53 tempdir = tempfile.mkdtemp()
54 cpath = os.path.join(tempdir,
'a.c')
55 with open(cpath,
'w')
as cfile:
56 cfile.write(source_string)
58 compiler.compile([cpath])
59 except errors.CompileError
as error:
62 shutil.rmtree(tempdir)
66 if _compile(compiler, source_string)
is not None:
67 sys.stderr.write(error_message)
69 "Diagnostics found a compilation environment issue:\n{}".
format(
74 """Attempt to diagnose an error during compilation."""
75 for c_check, message
in C_CHECKS.items():
78 source
for source
in build_ext.get_source_files()
79 if source.startswith(
'./src/python')
and source.endswith(
'c')
81 for source
in python_sources:
82 if not os.path.isfile(source):
84 "Diagnostics found a missing Python extension source file:\n{}\n\n"
85 "This is usually because the Cython sources haven't been transpiled "
86 "into C yet and you're building from source.\n"
87 "Try setting the environment variable "
88 "`GRPC_PYTHON_BUILD_WITH_CYTHON=1` when invoking `setup.py` or "
89 "when using `pip`, e.g.:\n\n"
90 "pip install -rrequirements.txt\n"
91 "GRPC_PYTHON_BUILD_WITH_CYTHON=1 pip install .").
format(source))
95 if any(
'_needs_stub' in arg
for arg
in error.args):
97 "We expect a missing `_needs_stub` attribute from older versions of "
98 "setuptools. Consider upgrading setuptools.")
102 errors.CompileError: diagnose_compile_error,
103 AttributeError: diagnose_attribute_error,
108 diagnostic = _ERROR_DIAGNOSES.get(
type(error))
109 if diagnostic
is None:
111 "\n\nWe could not diagnose your build failure. If you are unable to "
112 "proceed, please file an issue at http://www.github.com/grpc/grpc "
113 "with `[Python install]` in the title; please attach the whole log "
114 "(including everything that may have appeared above the Python "
115 "backtrace).\n\n{}".
format(formatted))
117 diagnostic(build_ext, error)