cython_cache.py 1.1 KB

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