MCPcopy Create free account
hub / github.com/python/cpython / check_config_h

Function check_config_h

Tools/c-analyzer/distutils/cygwinccompiler.py:208–249  ·  view source on GitHub ↗

Check if the current Python installation appears amenable to building extensions with GCC. Returns a tuple (status, details), where 'status' is one of the following constants: - CONFIG_H_OK: all is well, go ahead and compile - CONFIG_H_NOTOK: doesn't look good - CONFIG_H_UN

()

Source from the content-addressed store, hash-verified

206CONFIG_H_UNCERTAIN = "uncertain"
207
208def check_config_h():
209 """Check if the current Python installation appears amenable to building
210 extensions with GCC.
211
212 Returns a tuple (status, details), where 'status' is one of the following
213 constants:
214
215 - CONFIG_H_OK: all is well, go ahead and compile
216 - CONFIG_H_NOTOK: doesn't look good
217 - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h
218
219 'details' is a human-readable string explaining the situation.
220
221 Note there are two ways to conclude "OK": either 'sys.version' contains
222 the string "GCC" (implying that this Python was built with GCC), or the
223 installed "pyconfig.h" contains the string "__GNUC__".
224 """
225
226 # XXX since this function also checks sys.version, it's not strictly a
227 # "pyconfig.h" check -- should probably be renamed...
228
229 import sysconfig
230
231 # if sys.version contains GCC then python was compiled with GCC, and the
232 # pyconfig.h file should be OK
233 if "GCC" in sys.version:
234 return CONFIG_H_OK, "sys.version mentions 'GCC'"
235
236 # let's see if __GNUC__ is mentioned in python.h
237 fn = sysconfig.get_config_h_filename()
238 try:
239 config_h = open(fn)
240 try:
241 if "__GNUC__" in config_h.read():
242 return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn
243 else:
244 return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn
245 finally:
246 config_h.close()
247 except OSError as exc:
248 return (CONFIG_H_UNCERTAIN,
249 "couldn't read '%s': %s" % (fn, exc.strerror))
250
251RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)')
252

Callers 1

__init__Method · 0.85

Calls 3

openFunction · 0.50
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…