2013-06-18 18:36:18 -07:00
|
|
|
#!/usr/bin/env python
|
2019-09-26 22:18:28 -07:00
|
|
|
'''
|
2019-12-11 22:20:44 -08:00
|
|
|
pycapnp distutils setup.py
|
2019-09-26 22:18:28 -07:00
|
|
|
'''
|
2014-12-11 22:04:34 -08:00
|
|
|
|
2020-06-03 22:49:52 -07:00
|
|
|
import glob
|
2013-07-07 00:12:15 -07:00
|
|
|
import os
|
2020-06-03 22:49:52 -07:00
|
|
|
import shutil
|
2019-10-17 00:20:03 -07:00
|
|
|
import struct
|
2014-12-12 15:15:18 -08:00
|
|
|
import sys
|
2019-09-26 22:18:28 -07:00
|
|
|
|
2020-06-03 22:49:52 -07:00
|
|
|
import pkgconfig
|
|
|
|
|
2019-09-26 22:18:28 -07:00
|
|
|
from distutils.command.clean import clean as _clean
|
2014-12-28 00:02:57 -08:00
|
|
|
|
2020-06-08 23:51:07 -07:00
|
|
|
from setuptools import setup, Extension
|
2019-09-26 22:18:28 -07:00
|
|
|
|
2020-06-08 23:51:07 -07:00
|
|
|
from buildutils.build import build_libcapnp
|
|
|
|
from buildutils.bundle import fetch_libcapnp
|
2019-09-26 22:18:28 -07:00
|
|
|
|
2014-12-11 22:04:34 -08:00
|
|
|
_this_dir = os.path.dirname(__file__)
|
2013-07-06 23:41:19 -07:00
|
|
|
|
2019-12-26 22:49:07 -08:00
|
|
|
MAJOR = 1
|
|
|
|
MINOR = 0
|
2019-10-14 11:19:33 -07:00
|
|
|
MICRO = 0
|
2020-11-20 11:50:09 -08:00
|
|
|
TAG = ''
|
2019-12-26 22:49:07 -08:00
|
|
|
VERSION = '%d.%d.%d%s' % (MAJOR, MINOR, MICRO, TAG)
|
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-12-11 22:20:44 -08:00
|
|
|
Generate pycapnp 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()
|
|
|
|
|
2019-12-26 23:52:10 -08:00
|
|
|
# Try to use README.md and CHANGELOG.md as description and changelog
|
|
|
|
with open('README.md', encoding='utf-8') as f:
|
|
|
|
long_description = f.read()
|
|
|
|
with open('CHANGELOG.md', encoding='utf-8') as f:
|
|
|
|
changelog = f.read()
|
|
|
|
changelog = '\nChangelog\n=============\n' + changelog
|
|
|
|
long_description += changelog
|
2013-08-12 12:39:35 -07:00
|
|
|
|
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)
|
2020-06-03 22:49:52 -07:00
|
|
|
for x in [
|
|
|
|
os.path.join('capnp', 'lib', 'capnp.cpp'),
|
|
|
|
os.path.join('capnp', 'lib', 'capnp.h'),
|
|
|
|
os.path.join('capnp', 'version.py'),
|
|
|
|
'build',
|
|
|
|
'build32',
|
|
|
|
'build64',
|
|
|
|
'bundled'
|
|
|
|
] + glob.glob(os.path.join('capnp', '*.capnp')):
|
2014-07-12 19:11:03 -04:00
|
|
|
print('removing %s' % x)
|
|
|
|
try:
|
|
|
|
os.remove(x)
|
|
|
|
except OSError:
|
2020-06-03 22:49:52 -07:00
|
|
|
shutil.rmtree(x, ignore_errors=True)
|
2014-07-12 19:11:03 -04:00
|
|
|
|
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
|
2020-06-03 22:49:52 -07:00
|
|
|
capnp_executable = shutil.which("capnp")
|
2017-05-18 11:47:51 +02:00
|
|
|
if capnp_executable:
|
|
|
|
self.include_dirs += [os.path.join(os.path.dirname(capnp_executable), '..', 'include')]
|
2019-12-16 22:29:20 -08:00
|
|
|
self.library_dirs += [os.path.join(os.path.dirname(capnp_executable), '..', 'lib{}'.format(8 * struct.calcsize("P")))]
|
2017-05-18 11:47:51 +02:00
|
|
|
self.library_dirs += [os.path.join(os.path.dirname(capnp_executable), '..', 'lib')]
|
|
|
|
|
2020-06-03 22:49:52 -07:00
|
|
|
# Look for capnproto using pkg-config (and minimum version)
|
2017-01-09 13:07:08 +11:00
|
|
|
try:
|
2020-06-03 22:49:52 -07:00
|
|
|
if pkgconfig.installed('capnp', '>= 0.8.0'):
|
|
|
|
need_build = False
|
|
|
|
else:
|
|
|
|
need_build = True
|
|
|
|
except EnvironmentError:
|
|
|
|
# pkg-config not available in path
|
2017-01-09 13:07:08 +11:00
|
|
|
need_build = True
|
|
|
|
|
|
|
|
if need_build:
|
2020-06-08 23:51:07 -07:00
|
|
|
print(
|
2019-09-26 22:18:28 -07:00
|
|
|
"*WARNING* no libcapnp detected or rebuild forced. "
|
2020-06-08 23:51:07 -07:00
|
|
|
"Attempting to build it from source now. "
|
2019-09-26 22:18:28 -07:00
|
|
|
"If you have C++ Cap'n Proto installed, it may be out of date or is not being detected. "
|
2020-06-08 23:51:07 -07:00
|
|
|
"This may take a while..."
|
2019-09-26 22:18:28 -07:00
|
|
|
)
|
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)
|
2019-10-17 00:20:03 -07:00
|
|
|
build_dir = os.path.join(_this_dir, "build{}".format(8 * struct.calcsize("P")))
|
2014-12-11 22:04:34 -08:00
|
|
|
if not os.path.exists(build_dir):
|
|
|
|
os.mkdir(build_dir)
|
|
|
|
|
2019-10-15 09:05:01 -07:00
|
|
|
# Check if we've already built capnproto
|
|
|
|
capnp_bin = os.path.join(build_dir, 'bin', 'capnp')
|
|
|
|
if os.name == 'nt':
|
|
|
|
capnp_bin = os.path.join(build_dir, 'bin', 'capnp.exe')
|
|
|
|
|
|
|
|
if not os.path.exists(capnp_bin):
|
|
|
|
# Not built, fetch and build
|
|
|
|
fetch_libcapnp(bundle_dir, libcapnp_url)
|
|
|
|
build_libcapnp(bundle_dir, build_dir)
|
|
|
|
else:
|
2020-06-08 23:51:07 -07:00
|
|
|
print("capnproto already built at {}".format(build_dir))
|
2014-12-11 22:04:34 -08:00
|
|
|
|
|
|
|
self.include_dirs += [os.path.join(build_dir, 'include')]
|
2019-12-16 22:29:20 -08:00
|
|
|
self.library_dirs += [os.path.join(build_dir, 'lib{}'.format(8 * struct.calcsize("P")))]
|
2014-12-11 22:04:34 -08:00
|
|
|
self.library_dirs += [os.path.join(build_dir, 'lib')]
|
|
|
|
|
2020-06-03 22:49:52 -07:00
|
|
|
# Copy .capnp files from source
|
|
|
|
src_glob = glob.glob(os.path.join(build_dir, 'include', 'capnp', '*.capnp'))
|
|
|
|
dst_dir = os.path.join(self.build_lib, "capnp")
|
|
|
|
for file in src_glob:
|
2020-06-08 23:51:07 -07:00
|
|
|
print("copying {} -> {}".format(file, dst_dir))
|
2020-06-03 22:49:52 -07:00
|
|
|
shutil.copy(file, dst_dir)
|
|
|
|
|
2014-12-11 22:04:34 -08:00
|
|
|
return build_ext_c.run(self)
|
2014-12-28 00:02:57 -08:00
|
|
|
|
2019-10-17 00:20:03 -07:00
|
|
|
extra_compile_args = ['--std=c++14']
|
|
|
|
extra_link_args = []
|
|
|
|
if os.name == 'nt':
|
|
|
|
extra_compile_args = ['/std:c++14', '/MD']
|
|
|
|
extra_link_args = ['/MANIFEST']
|
2019-09-26 22:18:28 -07:00
|
|
|
|
2019-10-17 00:20:03 -07:00
|
|
|
import Cython.Build
|
2019-09-27 00:30:08 -07:00
|
|
|
import Cython # noqa: F401
|
2019-10-17 00:20:03 -07:00
|
|
|
extensions = [Extension(
|
2020-02-28 16:58:26 -08:00
|
|
|
'*', ['capnp/helpers/capabilityHelper.cpp', 'capnp/lib/*.pyx'],
|
2019-10-17 00:20:03 -07:00
|
|
|
extra_compile_args=extra_compile_args,
|
|
|
|
extra_link_args=extra_link_args,
|
|
|
|
language='c++',
|
|
|
|
)]
|
2014-12-28 00:02:57 -08:00
|
|
|
|
2013-06-18 18:36:18 -07:00
|
|
|
setup(
|
2019-12-11 22:20:44 -08:00
|
|
|
name="pycapnp",
|
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/*'
|
|
|
|
]
|
|
|
|
},
|
2019-10-17 00:20:03 -07:00
|
|
|
ext_modules=Cython.Build.cythonize(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
|
2019-12-11 22:20:44 -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,
|
2019-12-26 23:52:10 -08:00
|
|
|
long_description_content_type = 'text/markdown',
|
2013-08-12 13:03:43 -07:00
|
|
|
license='BSD',
|
2019-12-11 22:20:44 -08:00
|
|
|
author="Jacob Alexander", # <- Current maintainer; Original author -> Jason Paryani (setup.py only supports 1 author...)
|
2019-10-14 11:19:33 -07:00
|
|
|
author_email="haata@kiibohd.com",
|
2019-12-11 22:20:44 -08:00
|
|
|
url='https://github.com/capnproto/pycapnp',
|
|
|
|
download_url='https://github.com/haata/pycapnp/archive/v%s.zip' % VERSION,
|
|
|
|
keywords=['capnp', 'capnproto', "Cap'n Proto", 'pycapnp'],
|
2019-09-26 22:18:28 -07:00
|
|
|
classifiers=[
|
2020-11-20 13:55:19 -08:00
|
|
|
'Development Status :: 5 - Production/Stable',
|
2013-08-12 12:39:35 -07:00
|
|
|
'Intended Audience :: Developers',
|
|
|
|
'License :: OSI Approved :: BSD License',
|
|
|
|
'Operating System :: MacOS :: MacOS X',
|
2019-10-21 00:03:41 -07:00
|
|
|
'Operating System :: Microsoft :: Windows :: Windows 10',
|
2013-08-12 12:39:35 -07:00
|
|
|
'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',
|
2019-12-11 22:20:44 -08:00
|
|
|
'Programming Language :: Python :: 3.8',
|
2020-11-20 13:02:54 -08:00
|
|
|
'Programming Language :: Python :: 3.9',
|
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
|
|
|
)
|