2013-06-18 18:36:18 -07:00
|
|
|
#!/usr/bin/env python
|
2021-10-01 11:00:22 -07:00
|
|
|
"""
|
2019-12-11 22:20:44 -08:00
|
|
|
pycapnp distutils setup.py
|
2021-10-01 11:00:22 -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
|
2022-08-29 01:13:39 -07:00
|
|
|
MINOR = 2
|
2022-09-11 23:07:40 -07:00
|
|
|
MICRO = 1
|
2021-10-01 11:00:22 -07:00
|
|
|
TAG = ""
|
|
|
|
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):
|
2021-10-01 11:00:22 -07:00
|
|
|
"""
|
2019-12-11 22:20:44 -08:00
|
|
|
Generate pycapnp version
|
2021-10-01 11:00:22 -07:00
|
|
|
"""
|
2013-07-06 23:41:19 -07:00
|
|
|
cnt = """\
|
2021-05-03 14:34:25 +08:00
|
|
|
from .lib.capnp import _CAPNP_VERSION_MAJOR as LIBCAPNP_VERSION_MAJOR # noqa: F401
|
|
|
|
from .lib.capnp import _CAPNP_VERSION_MINOR as LIBCAPNP_VERSION_MINOR # noqa: F401
|
|
|
|
from .lib.capnp import _CAPNP_VERSION_MICRO as LIBCAPNP_VERSION_MICRO # noqa: F401
|
|
|
|
from .lib.capnp import _CAPNP_VERSION as LIBCAPNP_VERSION # noqa: F401
|
|
|
|
|
2013-07-06 23:41:19 -07:00
|
|
|
version = '%s'
|
|
|
|
short_version = '%s'
|
|
|
|
"""
|
|
|
|
if not filename:
|
2021-10-01 11:00:22 -07:00
|
|
|
filename = os.path.join(os.path.dirname(__file__), "capnp", "version.py")
|
2013-07-06 23:41:19 -07:00
|
|
|
|
2021-10-01 11:00:22 -07:00
|
|
|
a = open(filename, "w")
|
2013-07-06 23:41:19 -07:00
|
|
|
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
|
2021-10-01 11:00:22 -07:00
|
|
|
with open("README.md", encoding="utf-8") as f:
|
2019-12-26 23:52:10 -08:00
|
|
|
long_description = f.read()
|
2021-10-01 11:00:22 -07:00
|
|
|
with open("CHANGELOG.md", encoding="utf-8") as f:
|
2019-12-26 23:52:10 -08:00
|
|
|
changelog = f.read()
|
2021-10-01 11:00:22 -07:00
|
|
|
changelog = "\nChangelog\n=============\n" + changelog
|
2019-12-26 23:52:10 -08:00
|
|
|
long_description += changelog
|
2013-08-12 12:39:35 -07:00
|
|
|
|
2021-05-03 14:34:25 +08:00
|
|
|
|
2014-07-12 19:11:03 -04:00
|
|
|
class clean(_clean):
|
2021-10-01 11:00:22 -07:00
|
|
|
"""
|
2019-09-26 22:18:28 -07:00
|
|
|
Clean command, invoked with `python setup.py clean`
|
2021-10-01 11:00:22 -07:00
|
|
|
"""
|
|
|
|
|
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 [
|
2021-10-01 11:00:22 -07:00
|
|
|
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")):
|
|
|
|
print("removing %s" % x)
|
2014-07-12 19:11:03 -04:00
|
|
|
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
|
|
|
|
2021-05-03 14:34:25 +08:00
|
|
|
from Cython.Distutils import build_ext as build_ext_c # noqa: E402
|
|
|
|
|
2014-12-11 22:04:34 -08:00
|
|
|
|
2014-12-28 00:02:57 -08:00
|
|
|
class build_libcapnp_ext(build_ext_c):
|
2021-10-01 11:00:22 -07:00
|
|
|
"""
|
2019-09-26 22:18:28 -07:00
|
|
|
Build capnproto library
|
2021-10-01 11:00:22 -07:00
|
|
|
"""
|
|
|
|
|
2014-12-11 22:04:34 -08:00
|
|
|
def build_extension(self, ext):
|
|
|
|
build_ext_c.build_extension(self, ext)
|
|
|
|
|
2021-05-03 14:34:25 +08:00
|
|
|
def run(self): # noqa: C901
|
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:
|
2021-05-03 14:34:25 +08:00
|
|
|
capnp_dir = os.path.dirname(capnp_executable)
|
|
|
|
self.include_dirs += [os.path.join(capnp_dir, "..", "include")]
|
2021-10-01 11:00:22 -07:00
|
|
|
self.library_dirs += [
|
|
|
|
os.path.join(
|
|
|
|
capnp_dir, "..", "lib{}".format(8 * struct.calcsize("P"))
|
|
|
|
)
|
|
|
|
]
|
2021-05-03 14:34:25 +08:00
|
|
|
self.library_dirs += [os.path.join(capnp_dir, "..", "lib")]
|
2017-05-18 11:47:51 +02:00
|
|
|
|
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:
|
2021-10-01 11:00:22 -07:00
|
|
|
if pkgconfig.installed("capnp", ">= 0.8.0"):
|
2020-06-03 22:49:52 -07:00
|
|
|
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)
|
2021-10-01 11:00:22 -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
|
2021-10-01 11:00:22 -07:00
|
|
|
capnp_bin = os.path.join(build_dir, "bin", "capnp")
|
|
|
|
if os.name == "nt":
|
|
|
|
capnp_bin = os.path.join(build_dir, "bin", "capnp.exe")
|
2019-10-15 09:05:01 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-10-01 11:00:22 -07:00
|
|
|
self.include_dirs += [os.path.join(build_dir, "include")]
|
|
|
|
self.library_dirs += [
|
|
|
|
os.path.join(build_dir, "lib{}".format(8 * struct.calcsize("P")))
|
|
|
|
]
|
|
|
|
self.library_dirs += [os.path.join(build_dir, "lib")]
|
2014-12-11 22:04:34 -08:00
|
|
|
|
2020-06-03 22:49:52 -07:00
|
|
|
# Copy .capnp files from source
|
2021-10-01 11:00:22 -07:00
|
|
|
src_glob = glob.glob(os.path.join(build_dir, "include", "capnp", "*.capnp"))
|
2020-06-03 22:49:52 -07:00
|
|
|
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
|
|
|
|
2021-05-03 14:34:25 +08:00
|
|
|
|
2021-10-01 11:00:22 -07:00
|
|
|
extra_compile_args = ["--std=c++14"]
|
2019-10-17 00:20:03 -07:00
|
|
|
extra_link_args = []
|
2021-10-01 11:00:22 -07:00
|
|
|
if os.name == "nt":
|
|
|
|
extra_compile_args = ["/std:c++14", "/MD"]
|
|
|
|
extra_link_args = ["/MANIFEST"]
|
2019-09-26 22:18:28 -07:00
|
|
|
|
2021-05-03 14:34:25 +08:00
|
|
|
import Cython.Build # noqa: E402
|
|
|
|
import Cython # noqa: E402
|
|
|
|
|
2021-10-01 11:00:22 -07:00
|
|
|
extensions = [
|
|
|
|
Extension(
|
|
|
|
"*",
|
|
|
|
["capnp/helpers/capabilityHelper.cpp", "capnp/lib/*.pyx"],
|
|
|
|
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={
|
2021-10-01 11:00:22 -07:00
|
|
|
"capnp": [
|
|
|
|
"*.pxd",
|
|
|
|
"*.h",
|
|
|
|
"*.capnp",
|
|
|
|
"helpers/*.pxd",
|
|
|
|
"helpers/*.h",
|
|
|
|
"includes/*.pxd",
|
|
|
|
"lib/*.pxd",
|
|
|
|
"lib/*.py",
|
|
|
|
"lib/*.pyx",
|
|
|
|
"templates/*",
|
2019-09-26 22:18:28 -07:00
|
|
|
]
|
|
|
|
},
|
2019-10-17 00:20:03 -07:00
|
|
|
ext_modules=Cython.Build.cythonize(extensions),
|
2021-10-01 11:00:22 -07:00
|
|
|
cmdclass={"clean": clean, "build_ext": build_libcapnp_ext},
|
2014-12-28 00:02:57 -08:00
|
|
|
install_requires=[],
|
2021-10-01 11:00:22 -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,
|
2021-05-03 14:34:25 +08:00
|
|
|
long_description_content_type="text/markdown",
|
2021-10-01 11:00:22 -07:00
|
|
|
license="BSD",
|
2021-05-03 14:34:25 +08:00
|
|
|
# (setup.py only supports 1 author...)
|
|
|
|
author="Jacob Alexander", # <- Current maintainer; Original author -> Jason Paryani
|
2019-10-14 11:19:33 -07:00
|
|
|
author_email="haata@kiibohd.com",
|
2021-10-01 11:00:22 -07: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=[
|
2021-10-01 11:00:22 -07:00
|
|
|
"Development Status :: 5 - Production/Stable",
|
|
|
|
"Intended Audience :: Developers",
|
|
|
|
"License :: OSI Approved :: BSD License",
|
|
|
|
"Operating System :: MacOS :: MacOS X",
|
|
|
|
"Operating System :: Microsoft :: Windows :: Windows 10",
|
|
|
|
"Operating System :: POSIX",
|
|
|
|
"Programming Language :: C++",
|
|
|
|
"Programming Language :: Cython",
|
|
|
|
"Programming Language :: Python :: 3.7",
|
|
|
|
"Programming Language :: Python :: 3.8",
|
|
|
|
"Programming Language :: Python :: 3.9",
|
2022-08-27 01:13:09 +10:00
|
|
|
"Programming Language :: Python :: 3.10",
|
2021-10-01 11:00:22 -07:00
|
|
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
|
|
"Topic :: Communications",
|
|
|
|
],
|
2013-07-06 16:53:00 -07:00
|
|
|
)
|