Change setup.py to only use cython if it's available
This commit is contained in:
33
setup.py
33
setup.py
@@ -1,19 +1,21 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
use_cython = True
|
||||||
try:
|
try:
|
||||||
from Cython.Build import cythonize
|
from Cython.Build import cythonize
|
||||||
import Cython
|
import Cython
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise RuntimeError('No cython installed. Please run `pip install cython`')
|
use_cython = False
|
||||||
|
|
||||||
if Cython.__version__ < '0.19.1':
|
if use_cython and Cython.__version__ < '0.19.1':
|
||||||
raise RuntimeError('Old cython installed (%s). Please run `pip install -U cython`' % Cython.__version__)
|
use_cython = False
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
setuptools_version = pkg_resources.get_distribution("setuptools").version
|
setuptools_version = pkg_resources.get_distribution("setuptools").version
|
||||||
if setuptools_version < '0.8':
|
if setuptools_version < '0.8':
|
||||||
raise RuntimeError('Old setuptools installed (%s). Please run `pip install -U setuptools`. Running `pip install pycapnp` will not work alone, since setuptools needs to be upgraded before installing anything else.' % setuptools_version)
|
# older versions of setuptools don't work with cython
|
||||||
|
use_cython = False
|
||||||
|
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
import os
|
import os
|
||||||
@@ -21,7 +23,11 @@ import sys
|
|||||||
from buildutils import test_build, fetch_libcapnp, build_libcapnp, info
|
from buildutils import test_build, fetch_libcapnp, build_libcapnp, info
|
||||||
from distutils.errors import CompileError
|
from distutils.errors import CompileError
|
||||||
from distutils.extension import Extension
|
from distutils.extension import Extension
|
||||||
|
if use_cython:
|
||||||
from Cython.Distutils import build_ext as build_ext_c
|
from Cython.Distutils import build_ext as build_ext_c
|
||||||
|
else:
|
||||||
|
from distutils.command.build_ext import build_ext as build_ext_c
|
||||||
|
|
||||||
_this_dir = os.path.dirname(__file__)
|
_this_dir = os.path.dirname(__file__)
|
||||||
|
|
||||||
MAJOR = 0
|
MAJOR = 0
|
||||||
@@ -29,6 +35,7 @@ MINOR = 5
|
|||||||
MICRO = 0
|
MICRO = 0
|
||||||
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
|
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
|
||||||
|
|
||||||
|
|
||||||
# Write version info
|
# Write version info
|
||||||
def write_version_py(filename=None):
|
def write_version_py(filename=None):
|
||||||
cnt = """\
|
cnt = """\
|
||||||
@@ -79,8 +86,8 @@ force_system_libcapnp = "--force-system-libcapnp" in sys.argv
|
|||||||
if force_system_libcapnp:
|
if force_system_libcapnp:
|
||||||
sys.argv.remove("--force-system-libcapnp")
|
sys.argv.remove("--force-system-libcapnp")
|
||||||
|
|
||||||
class build_libcapnp_ext(build_ext_c):
|
|
||||||
|
|
||||||
|
class build_libcapnp_ext(build_ext_c):
|
||||||
def build_extension(self, ext):
|
def build_extension(self, ext):
|
||||||
build_ext_c.build_extension(self, ext)
|
build_ext_c.build_extension(self, ext)
|
||||||
|
|
||||||
@@ -110,19 +117,27 @@ class build_libcapnp_ext(build_ext_c):
|
|||||||
self.library_dirs += [os.path.join(build_dir, 'lib')]
|
self.library_dirs += [os.path.join(build_dir, 'lib')]
|
||||||
|
|
||||||
return build_ext_c.run(self)
|
return build_ext_c.run(self)
|
||||||
|
|
||||||
|
if use_cython:
|
||||||
|
extensions = cythonize('capnp/lib/*.pyx')
|
||||||
|
else:
|
||||||
|
extensions = [Extension("capnp.lib.capnp", ["capnp/lib/capnp.cpp"],
|
||||||
|
include_dirs=["."],
|
||||||
|
language='c++',
|
||||||
|
extra_compile_args=['--std=c++11'],
|
||||||
|
libraries=['capnpc', 'capnp-rpc', 'capnp', 'kj-async', 'kj'])]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pycapnp",
|
name="pycapnp",
|
||||||
packages=["capnp"],
|
packages=["capnp"],
|
||||||
version=VERSION,
|
version=VERSION,
|
||||||
package_data={'capnp': ['*.pxd', '*.h', '*.capnp', 'helpers/*.pxd', 'helpers/*.h', 'includes/*.pxd', 'lib/*.pxd', 'lib/*.py', 'lib/*.pyx', 'templates/*']},
|
package_data={'capnp': ['*.pxd', '*.h', '*.capnp', 'helpers/*.pxd', 'helpers/*.h', 'includes/*.pxd', 'lib/*.pxd', 'lib/*.py', 'lib/*.pyx', 'templates/*']},
|
||||||
ext_modules=cythonize('capnp/lib/*.pyx'),
|
ext_modules=extensions,
|
||||||
cmdclass = {
|
cmdclass = {
|
||||||
'clean': clean,
|
'clean': clean,
|
||||||
'build_ext': build_libcapnp_ext
|
'build_ext': build_libcapnp_ext
|
||||||
},
|
},
|
||||||
install_requires=[
|
install_requires=[],
|
||||||
'cython >= 0.21',
|
|
||||||
'setuptools >= 0.8'],
|
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts' : ['capnpc-cython = capnp._gen:main']
|
'console_scripts' : ['capnpc-cython = capnp._gen:main']
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user