Commit 5f35cab5 authored by Denis Bilenko's avatar Denis Bilenko

setup.py: run cython if core.c is out of date

parent b1e8b4a5
......@@ -46,13 +46,31 @@ libraries = []
extra_objects = []
# hack: create a symlink from build/../core.so to gevent/core.so to prevent "ImportError: cannot import name core" failures
cmdclass = {}
try:
from distutils.command import build_ext
class my_build_ext(build_ext.build_ext):
class my_build_ext(build_ext.build_ext):
def compile_cython(self):
sources = glob.glob('gevent/*.pyx') + sorted(glob.glob('gevent/*.pxi'))
if not sources:
print >> sys.stderr, 'Could not find gevent.core sources'
return
core_c_mtime = os.stat('gevent/core.c').st_mtime
changed = [filename for filename in sources if os.stat(filename).st_mtime >= core_c_mtime]
if changed:
print >> sys.stderr, 'Running cython (changed: %s)' % ', '.join(changed)
cython_result = os.system('cython gevent/core.pyx')
if cython_result:
if os.system('cython -V 2> %s' % os.devnull):
# there's no cython in the system
print >> sys.stderr, 'No cython found, cannot rebuild core.c'
return
sys.exit(1)
def build_extension(self, ext):
self.compile_cython()
result = build_ext.build_ext.build_extension(self, ext)
# hack: create a symlink from build/../core.so to gevent/core.so
# to prevent "ImportError: cannot import name core" failures
try:
fullname = self.get_ext_fullname(ext.name)
modpath = fullname.split('.')
......@@ -63,22 +81,22 @@ try:
path_to_build_core_so = abspath(os.path.join(self.build_lib, filename))
path_to_core_so = abspath(join('gevent', basename(path_to_build_core_so)))
if path_to_build_core_so != path_to_core_so:
print 'Linking %s to %s' % (path_to_build_core_so, path_to_core_so)
try:
os.unlink(path_to_core_so)
except OSError:
pass
if hasattr(os, 'symlink'):
print 'Linking %s to %s' % (path_to_build_core_so, path_to_core_so)
os.symlink(path_to_build_core_so, path_to_core_so)
else:
print 'Copying %s to %s' % (path_to_build_core_so, path_to_core_so)
import shutil
shutil.copyfile(path_to_build_core_so, path_to_core_so)
except Exception:
traceback.print_exc()
return result
cmdclass = {'build_ext': my_build_ext}
except Exception:
traceback.print_exc()
cmdclass = {'build_ext': my_build_ext}
def check_dir(path, must_exist):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment