cython_cache.py (1135B)
1 #! /usr/bin/env python 2 # encoding: utf-8 3 # Thomas Nagy, 2012 4 5 """ 6 A simple cache layer to enable the redistribution of precompiled cython files 7 """ 8 9 from waflib.Task import ASK_LATER 10 from waflib.extras.cython import cython as cython_base 11 12 class cython(cython_base): 13 14 def runnable_status(self): 15 ret = cython_base.runnable_status(self) 16 if ret != ASK_LATER: 17 # we can create Node objects since we are in the main thread 18 bld = self.generator.bld 19 cache = bld.srcnode.make_node('cython_cache') 20 if self.env.CYTHON: # write to the cache directory 21 self.cython_cache_outputs = [cache.make_node(x.path_from(bld.bldnode)) for x in self.outputs] 22 else: # use the files in the cache directory 23 self.cython_cache_outputs = [cache.find_node(x.path_from(bld.bldnode)) for x in self.outputs] 24 return ret 25 26 def run(self): 27 if self.env.CYTHON: 28 ret = cython_base.run(self) 29 if not ret: 30 for (x, y) in zip(self.outputs, self.cython_cache_outputs): 31 y.parent.mkdir() 32 y.write(x.read('rb'), 'wb') 33 return ret 34 else: 35 for (x, y) in zip(self.outputs, self.cython_cache_outputs): 36 x.write(y.read('rb'), 'wb') 37