Commit b2dac472 authored by Ralf Schmitt's avatar Ralf Schmitt

setup.py: add "build_ext --cython=" option, which allows users to specify the...

setup.py: add "build_ext --cython=" option, which allows users to specify the path to the cython executable.

this also allows users to skip automatic cython compilation completely
by specifying an empty cython executable, e.g. by providing the
following setup.cfg:

,----[ setup.cfg ]
| [build_ext]
| cython=
`----

I use this to manage a copy of gevent inside another git repository
while at the same time making sure that core.c doesn't get
regenerated.
parent 01ec94d2
...@@ -41,6 +41,12 @@ libraries = [] ...@@ -41,6 +41,12 @@ libraries = []
class my_build_ext(build_ext.build_ext): 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 compile_cython(self): def compile_cython(self):
sources = glob.glob('gevent/*.pyx') + glob.glob('gevent/*.pxi') sources = glob.glob('gevent/*.pyx') + glob.glob('gevent/*.pxi')
...@@ -52,12 +58,12 @@ class my_build_ext(build_ext.build_ext): ...@@ -52,12 +58,12 @@ 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 cython (changed: %s)' % ', '.join(changed) print >> sys.stderr, 'Running %s (changed: %s)' % (self.cython, ', '.join(changed))
else: else:
print >> sys.stderr, 'Running cython' print >> sys.stderr, 'Running %s' % self.cython
cython_result = os.system('cython gevent/core.pyx') cython_result = os.system('%s gevent/core.pyx' % self.cython)
if cython_result: if cython_result:
if os.system('cython -V 2> %s' % os.devnull): if os.system('%s -V 2> %s' % (self.cython, 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
...@@ -65,8 +71,8 @@ class my_build_ext(build_ext.build_ext): ...@@ -65,8 +71,8 @@ class my_build_ext(build_ext.build_ext):
def build_extension(self, ext): def build_extension(self, ext):
compile_libevent(self) compile_libevent(self)
if self.cython:
self.compile_cython() self.compile_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
......
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