Commit 232bc505 authored by Denis Bilenko's avatar Denis Bilenko

add 'cython' command to setup.py

parent 397e7b77
...@@ -40,15 +40,7 @@ sources = ['gevent/core.c'] ...@@ -40,15 +40,7 @@ sources = ['gevent/core.c']
libraries = [] libraries = []
class my_build_ext(build_ext.build_ext): def run_cython(cython_command='cython'):
user_options = (build_ext.build_ext.user_options
+ [("cython=", None, "path to the cython executable")])
def initialize_options(self):
build_ext.build_ext.initialize_options(self)
self.cython = "cython"
def compile_cython(self):
sources = glob.glob('gevent/*.pyx') + glob.glob('gevent/*.pxi') sources = glob.glob('gevent/*.pyx') + glob.glob('gevent/*.pxi')
if not sources: if not sources:
if not os.path.exists('gevent/core.c'): if not os.path.exists('gevent/core.c'):
...@@ -58,21 +50,30 @@ class my_build_ext(build_ext.build_ext): ...@@ -58,21 +50,30 @@ class my_build_ext(build_ext.build_ext):
changed = [filename for filename in sources if (os.stat(filename).st_mtime - core_c_mtime) > 1] changed = [filename for filename in sources if (os.stat(filename).st_mtime - core_c_mtime) > 1]
if not changed: if not changed:
return return
print >> sys.stderr, 'Running %s (changed: %s)' % (self.cython, ', '.join(changed)) print >> sys.stderr, 'Running %s (changed: %s)' % (cython_command, ', '.join(changed))
else: else:
print >> sys.stderr, 'Running %s' % self.cython print >> sys.stderr, 'Running %s' % cython_command
cython_result = os.system('%s gevent/core.pyx' % self.cython) cython_result = os.system('%s gevent/core.pyx' % cython_command)
if cython_result: if cython_result:
if os.system('%s -V 2> %s' % (self.cython, os.devnull)): if os.system('%s -V 2> %s' % (cython_command, os.devnull)):
# there's no cython in the system # there's no cython in the system
print >> sys.stderr, 'No cython found, cannot rebuild core.c' print >> sys.stderr, 'No cython found, cannot rebuild core.c'
return return
sys.exit(1) sys.exit(1)
class my_build_ext(build_ext.build_ext):
user_options = (build_ext.build_ext.user_options
+ [("cython=", None, "path to the cython executable")])
def initialize_options(self):
build_ext.build_ext.initialize_options(self)
self.cython = "cython"
def build_extension(self, ext): def build_extension(self, ext):
compile_libevent(self) compile_libevent(self)
if self.cython: if self.cython:
self.compile_cython() run_cython(self.cython)
result = build_ext.build_ext.build_extension(self, ext) result = build_ext.build_ext.build_extension(self, ext)
# hack: create a symlink from build/../core.so to gevent/core.so # hack: create a symlink from build/../core.so to gevent/core.so
# to prevent "ImportError: cannot import name core" failures # to prevent "ImportError: cannot import name core" failures
...@@ -295,6 +296,9 @@ def read(name): ...@@ -295,6 +296,9 @@ def read(name):
if __name__ == '__main__': if __name__ == '__main__':
if sys.argv[1:] == ['cython']:
run_cython()
else:
setup( setup(
name='gevent', name='gevent',
version=__version__, version=__version__,
......
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