2013-06-18 18:36:18 -07:00
|
|
|
#!/usr/bin/env python
|
2019-09-26 22:18:28 -07:00
|
|
|
'''
|
2019-10-14 11:19:33 -07:00
|
|
|
pycapnp-async distutils setup.py
|
2019-09-26 22:18:28 -07:00
|
|
|
'''
|
2014-12-11 22:04:34 -08:00
|
|
|
|
2019-09-26 22:18:28 -07:00
|
|
|
from __future__ import print_function
|
2013-08-26 10:08:34 -07:00
|
|
|
|
2013-07-07 00:12:15 -07:00
|
|
|
import os
|
2014-12-12 15:15:18 -08:00
|
|
|
import sys
|
2019-09-26 22:18:28 -07:00
|
|
|
|
|
|
|
from distutils.command.clean import clean as _clean
|
2014-12-11 22:04:34 -08:00
|
|
|
from distutils.errors import CompileError
|
|
|
|
from distutils.extension import Extension
|
2017-05-18 11:47:51 +02:00
|
|
|
from distutils.spawn import find_executable
|
2014-12-28 00:02:57 -08:00
|
|
|
|
2019-09-26 22:18:28 -07:00
|
|
|
from setuptools import setup
|
|
|
|
|
|
|
|
from buildutils import test_build, fetch_libcapnp, build_libcapnp, info
|
|
|
|
|
2014-12-11 22:04:34 -08:00
|
|
|
_this_dir = os.path.dirname(__file__)
|
2013-07-06 23:41:19 -07:00
|
|
|
|
|
|
|
MAJOR = 0
|
2019-10-14 11:19:33 -07:00
|
|
|
MINOR = 7
|
|
|
|
MICRO = 0
|
2013-12-12 11:56:31 -08:00
|
|
|
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
|
2013-07-06 23:41:19 -07:00
|
|
|
|
2014-12-28 00:02:57 -08:00
|
|
|
|
2014-12-11 22:04:34 -08:00
|
|
|
# Write version info
|
2013-07-06 23:41:19 -07:00
|
|
|
def write_version_py(filename=None):
|
2019-09-26 22:18:28 -07:00
|
|
|
'''
|
2019-10-14 11:19:33 -07:00
|
|
|
Generate pycapnp-async version
|
2019-09-26 22:18:28 -07:00
|
|
|
'''
|
2013-07-06 23:41:19 -07:00
|
|
|
cnt = """\
|
|
|
|
version = '%s'
|
|
|
|
short_version = '%s'
|
2014-02-18 17:33:17 -08:00
|
|
|
|
2019-09-26 22:18:28 -07:00
|
|
|
# flake8: noqa E402 F401
|
2014-02-18 17:33:17 -08:00
|
|
|
from .lib.capnp import _CAPNP_VERSION_MAJOR as LIBCAPNP_VERSION_MAJOR
|
|
|
|
from .lib.capnp import _CAPNP_VERSION_MINOR as LIBCAPNP_VERSION_MINOR
|
|
|
|
from .lib.capnp import _CAPNP_VERSION_MICRO as LIBCAPNP_VERSION_MICRO
|
|
|
|
from .lib.capnp import _CAPNP_VERSION as LIBCAPNP_VERSION
|
2013-07-06 23:41:19 -07:00
|
|
|
"""
|
|
|
|
if not filename:
|
|
|
|
filename = os.path.join(
|
|
|
|
os.path.dirname(__file__), 'capnp', 'version.py')
|
|
|
|
|
|
|
|
a = open(filename, 'w')
|
|
|
|
try:
|
|
|
|
a.write(cnt % (VERSION, VERSION))
|
|
|
|
finally:
|
|
|
|
a.close()
|
|
|
|
|
2019-09-26 22:18:28 -07:00
|
|
|
|
2013-07-07 00:12:15 -07:00
|
|
|
write_version_py()
|
|
|
|
|
2014-12-11 22:04:34 -08:00
|
|
|
# Try to convert README using pandoc
|
2013-08-12 12:39:35 -07:00
|
|
|
try:
|
|
|
|
import pypandoc
|
2019-07-13 16:44:42 +01:00
|
|
|
long_description = pypandoc.convert_file('README.md', 'rst')
|
|
|
|
changelog = pypandoc.convert_file('CHANGELOG.md', 'rst')
|
2015-03-05 12:51:56 -08:00
|
|
|
changelog = '\nChangelog\n=============\n' + changelog
|
|
|
|
long_description += changelog
|
2013-08-12 12:39:35 -07:00
|
|
|
except (IOError, ImportError):
|
2019-09-26 22:18:28 -07:00
|
|
|
if sys.argv and sys.argv[-1] == 'sdist':
|
2019-01-31 01:03:21 -08:00
|
|
|
raise
|
2013-08-12 12:39:35 -07:00
|
|
|
long_description = ''
|
|
|
|
|
2014-07-12 19:11:03 -04:00
|
|
|
class clean(_clean):
|
2019-09-26 22:18:28 -07:00
|
|
|
'''
|
|
|
|
Clean command, invoked with `python setup.py clean`
|
|
|
|
'''
|
2014-07-12 19:11:03 -04:00
|
|
|
def run(self):
|
|
|
|
_clean.run(self)
|
|
|
|
for x in [ 'capnp/lib/capnp.cpp', 'capnp/lib/capnp.h', 'capnp/version.py' ]:
|
|
|
|
print('removing %s' % x)
|
|
|
|
try:
|
|
|
|
os.remove(x)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
2019-09-26 22:18:28 -07:00
|
|
|
|
2014-12-12 15:15:18 -08:00
|
|
|
# hack to parse commandline arguments
|
|
|
|
force_bundled_libcapnp = "--force-bundled-libcapnp" in sys.argv
|
|
|
|
if force_bundled_libcapnp:
|
|
|
|
sys.argv.remove("--force-bundled-libcapnp")
|
|
|
|
force_system_libcapnp = "--force-system-libcapnp" in sys.argv
|
|
|
|
if force_system_libcapnp:
|
|
|
|
sys.argv.remove("--force-system-libcapnp")
|
2015-02-03 08:35:04 -08:00
|
|
|
force_cython = "--force-cython" in sys.argv
|
|
|
|
if force_cython:
|
|
|
|
sys.argv.remove("--force-cython")
|
2019-09-27 00:30:08 -07:00
|
|
|
# Always use cython, ignoring option
|
2016-02-17 17:23:04 -08:00
|
|
|
libcapnp_url = None
|
|
|
|
try:
|
|
|
|
libcapnp_url_index = sys.argv.index("--libcapnp-url")
|
|
|
|
libcapnp_url = sys.argv[libcapnp_url_index + 1]
|
|
|
|
sys.argv.remove("--libcapnp-url")
|
|
|
|
sys.argv.remove(libcapnp_url)
|
2019-09-26 22:18:28 -07:00
|
|
|
except Exception:
|
2016-02-17 17:23:04 -08:00
|
|
|
pass
|
2014-12-11 22:04:34 -08:00
|
|
|
|
2019-09-27 00:30:08 -07:00
|
|
|
from Cython.Distutils import build_ext as build_ext_c
|
2014-12-11 22:04:34 -08:00
|
|
|
|
2014-12-28 00:02:57 -08:00
|
|
|
class build_libcapnp_ext(build_ext_c):
|
2019-09-26 22:18:28 -07:00
|
|
|
'''
|
|
|
|
Build capnproto library
|
|
|
|
'''
|
2014-12-11 22:04:34 -08:00
|
|
|
def build_extension(self, ext):
|
|
|
|
build_ext_c.build_extension(self, ext)
|
|
|
|
|
|
|
|
def run(self):
|
2017-01-09 13:07:08 +11:00
|
|
|
if force_bundled_libcapnp:
|
|
|
|
need_build = True
|
|
|
|
elif force_system_libcapnp:
|
|
|
|
need_build = False
|
|
|
|
else:
|
2017-05-18 11:47:51 +02:00
|
|
|
# Try to use capnp executable to find include and lib path
|
|
|
|
capnp_executable = find_executable("capnp")
|
|
|
|
if capnp_executable:
|
|
|
|
self.include_dirs += [os.path.join(os.path.dirname(capnp_executable), '..', 'include')]
|
|
|
|
self.library_dirs += [os.path.join(os.path.dirname(capnp_executable), '..', 'lib')]
|
|
|
|
|
2017-01-09 13:07:08 +11:00
|
|
|
# Try to autodetect presence of library. Requires compile/run
|
|
|
|
# step so only works for host (non-cross) compliation
|
|
|
|
try:
|
2017-05-18 11:47:51 +02:00
|
|
|
test_build(include_dirs=self.include_dirs, library_dirs=self.library_dirs)
|
2017-01-09 13:07:08 +11:00
|
|
|
need_build = False
|
|
|
|
except CompileError:
|
|
|
|
need_build = True
|
|
|
|
|
|
|
|
if need_build:
|
2019-09-26 22:18:28 -07:00
|
|
|
info(
|
|
|
|
"*WARNING* no libcapnp detected or rebuild forced. "
|
|
|
|
"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."
|
|
|
|
)
|
2014-12-11 22:04:34 -08:00
|
|
|
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)
|
2016-02-17 17:23:04 -08:00
|
|
|
fetch_libcapnp(bundle_dir, libcapnp_url)
|
2014-12-11 22:04:34 -08:00
|
|
|
|
|
|
|
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)
|
2014-12-28 00:02:57 -08:00
|
|
|
|
2019-09-26 22:18:28 -07:00
|
|
|
|
2019-09-27 00:30:08 -07:00
|
|
|
from Cython.Build import cythonize
|
|
|
|
import Cython # noqa: F401
|
|
|
|
extensions = cythonize('capnp/lib/*.pyx')
|
2014-12-28 00:02:57 -08:00
|
|
|
|
2013-06-18 18:36:18 -07:00
|
|
|
setup(
|
2019-10-14 11:19:33 -07:00
|
|
|
name="pycapnp-async",
|
2013-07-06 23:41:19 -07:00
|
|
|
packages=["capnp"],
|
2013-08-12 11:56:44 -07:00
|
|
|
version=VERSION,
|
2019-09-26 22:18:28 -07:00
|
|
|
package_data={
|
|
|
|
'capnp': [
|
|
|
|
'*.pxd', '*.h', '*.capnp', 'helpers/*.pxd', 'helpers/*.h',
|
|
|
|
'includes/*.pxd', 'lib/*.pxd', 'lib/*.py', 'lib/*.pyx', 'templates/*'
|
|
|
|
]
|
|
|
|
},
|
2014-12-28 00:02:57 -08:00
|
|
|
ext_modules=extensions,
|
2019-09-26 22:18:28 -07:00
|
|
|
cmdclass={
|
2014-12-11 22:04:34 -08:00
|
|
|
'clean': clean,
|
|
|
|
'build_ext': build_libcapnp_ext
|
2014-07-12 19:11:03 -04:00
|
|
|
},
|
2014-12-28 00:02:57 -08:00
|
|
|
install_requires=[],
|
2014-09-04 14:21:27 -07:00
|
|
|
entry_points={
|
|
|
|
'console_scripts' : ['capnpc-cython = capnp._gen:main']
|
|
|
|
},
|
2013-08-12 11:56:44 -07:00
|
|
|
# PyPi info
|
2013-11-05 15:37:51 -08:00
|
|
|
description="A cython wrapping of the C++ Cap'n Proto library",
|
2013-08-12 12:39:35 -07:00
|
|
|
long_description=long_description,
|
2013-08-12 13:03:43 -07:00
|
|
|
license='BSD',
|
2019-10-14 11:19:33 -07:00
|
|
|
author="Jacob Alexander",
|
|
|
|
author_email="haata@kiibohd.com",
|
|
|
|
url='https://github.com/haata/pycapnp-async',
|
|
|
|
download_url='https://github.com/haata/pycapnp-async/archive/v%s.zip' % VERSION,
|
2019-09-26 22:18:28 -07:00
|
|
|
keywords=['capnp', 'capnproto', "Cap'n Proto"],
|
|
|
|
classifiers=[
|
2015-02-20 17:20:04 -08:00
|
|
|
'Development Status :: 4 - Beta',
|
2013-08-12 12:39:35 -07:00
|
|
|
'Intended Audience :: Developers',
|
|
|
|
'License :: OSI Approved :: BSD License',
|
|
|
|
'Operating System :: MacOS :: MacOS X',
|
|
|
|
'Operating System :: POSIX',
|
2013-08-12 13:03:43 -07:00
|
|
|
'Programming Language :: C++',
|
|
|
|
'Programming Language :: Cython',
|
2019-09-26 22:18:28 -07:00
|
|
|
'Programming Language :: Python :: 3.7',
|
2013-08-15 15:44:54 -07:00
|
|
|
'Programming Language :: Python :: Implementation :: PyPy',
|
2013-08-12 12:39:35 -07:00
|
|
|
'Topic :: Communications'],
|
2013-07-06 16:53:00 -07:00
|
|
|
)
|