1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
# encoding: utf-8
# Extend waf cython tool features.
import re
from waflib import Configure
import subprocess
cython_ver_re = re.compile(b'Cython version ([0-9.]+)')
def check_cython_version(self, version=None, minver=None, maxver=None):
log_s = []
if version:
log_s.append("version=%r"%version)
minver=version
maxver=version
else:
if minver:
log_s.append("minver=%r"%minver)
if maxver:
log_s.append("maxver=%r"%maxver)
if isinstance(minver, str):
minver = minver.split('.')
if isinstance(maxver, str):
maxver = maxver.split('.')
if minver:
minver = tuple(map(int, minver))
if maxver:
maxver = tuple(map(int, maxver))
if isinstance(self.env.CYTHON, list):
cmdbin = " "
cmdbin = cmdbin.join(self.env.CYTHON)
else:
cmdbin = self.env.CYTHON
cmd = [cmdbin, '-V']
o = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
m = cython_ver_re.match(o)
self.start_msg('Checking for cython version')
if not m:
self.end_msg('Not found', 'YELLOW')
self.fatal("No version found")
else:
v = m.group(1)
ver = tuple(map(int, v.split(b'.')))
check = (not minver or minver <= ver) and (not maxver or maxver >= ver)
self.to_log(' cython %s\n -> %r\n' % (" ".join(log_s), v))
if check:
self.end_msg(v.decode("utf-8"))
self.env.CYTHON_VERSION = ver
else:
self.end_msg('wrong version %s' % v, 'YELLOW')
self.fatal("Bad cython version (%s)"%v)
return True
def configure(conf):
if not conf.env.CYTHON:
conf.fatal("cython_extra requires the tool 'cython' to be loaded first.")
Configure.conf(check_cython_version)
|