Add automatic build of libcapnp if it's not detected
This commit is contained in:
38
setup.py
38
setup.py
@@ -1,4 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
|
||||
try:
|
||||
from Cython.Build import cythonize
|
||||
import Cython
|
||||
@@ -15,12 +17,18 @@ if setuptools_version < '0.8':
|
||||
|
||||
from distutils.core import setup
|
||||
import os
|
||||
from buildutils import test_build, fetch_libcapnp, build_libcapnp, info
|
||||
from distutils.errors import CompileError
|
||||
from distutils.extension import Extension
|
||||
from Cython.Distutils import build_ext as build_ext_c
|
||||
_this_dir = os.path.dirname(__file__)
|
||||
|
||||
MAJOR = 0
|
||||
MINOR = 4
|
||||
MICRO = 6
|
||||
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
|
||||
|
||||
# Write version info
|
||||
def write_version_py(filename=None):
|
||||
cnt = """\
|
||||
version = '%s'
|
||||
@@ -43,12 +51,14 @@ from .lib.capnp import _CAPNP_VERSION as LIBCAPNP_VERSION
|
||||
|
||||
write_version_py()
|
||||
|
||||
# Try to convert README using pandoc
|
||||
try:
|
||||
import pypandoc
|
||||
long_description = pypandoc.convert('README.md', 'rst')
|
||||
except (IOError, ImportError):
|
||||
long_description = ''
|
||||
|
||||
# Clean command, invoked with `python setup.py clean`
|
||||
from distutils.command.clean import clean as _clean
|
||||
class clean(_clean):
|
||||
def run(self):
|
||||
@@ -60,6 +70,31 @@ class clean(_clean):
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
class build_libcapnp_ext(build_ext_c):
|
||||
|
||||
def build_extension(self, ext):
|
||||
build_ext_c.build_extension(self, ext)
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
test_build()
|
||||
except CompileError:
|
||||
info("*WARNING* no libcapnp detected. Will download and build it from source now. If you have C++ Cap'n Proto installed, it may be out of date or is not being detected. Downloading and building libcapnp may take a while.")
|
||||
bundle_dir = os.path.join(_this_dir, "bundled")
|
||||
if not os.path.exists(bundle_dir):
|
||||
os.mkdir(bundle_dir)
|
||||
build_dir = os.path.join(_this_dir, "build")
|
||||
if not os.path.exists(build_dir):
|
||||
os.mkdir(build_dir)
|
||||
fetch_libcapnp(bundle_dir)
|
||||
|
||||
build_libcapnp(bundle_dir, build_dir)
|
||||
|
||||
self.include_dirs += [os.path.join(build_dir, 'include')]
|
||||
self.library_dirs += [os.path.join(build_dir, 'lib')]
|
||||
|
||||
return build_ext_c.run(self)
|
||||
setup(
|
||||
name="pycapnp",
|
||||
packages=["capnp"],
|
||||
@@ -67,7 +102,8 @@ setup(
|
||||
package_data={'capnp': ['*.pxd', '*.h', '*.capnp', 'helpers/*.pxd', 'helpers/*.h', 'includes/*.pxd', 'lib/*.pxd', 'lib/*.py', 'lib/*.pyx']},
|
||||
ext_modules=cythonize('capnp/lib/*.pyx'),
|
||||
cmdclass = {
|
||||
'clean': clean
|
||||
'clean': clean,
|
||||
'build_ext': build_libcapnp_ext
|
||||
},
|
||||
install_requires=[
|
||||
'cython >= 0.21',
|
||||
|
||||
Reference in New Issue
Block a user