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
()
| 206 | CONFIG_H_UNCERTAIN = "uncertain" |
| 207 | |
| 208 | def 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 | |
| 251 | RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)') |
| 252 |