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
|
2023-01-26 16:43:40 -08:00
|
|
|
MINOR = 3
|
|
|
|
MICRO = 0
|
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:
|
2022-11-30 10:18:06 -08:00
|
|
|
if pkgconfig.installed("capnp", ">= 0.7.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(
|
|
|
|
"*",
|
Integrate the KJ event loop into Python's asyncio event loop (#310)
* Integrate the KJ event loop into Python's asyncio event loop
Fix #256
This PR attempts to remove the slow and expensive polling behavior for asyncio
in favor of proper linking of the KJ event loop to the asyncio event loop.
* Don't memcopy buffer
* Improve promise cancellation and prepare for timer implementation
* Add attribution for asyncProvider.cpp
* Implement timeout
* Cleanup
* First round of simplifications
* Add more a_wait functions and a shutdown function
* Fix edge-cases with loop shutdown
* Clean up calculator examples
* Cleanup
* Cleanup
* Reformat
* Fix warnings
* Reformat again
* Compatibility with macos
* Inline the asyncio loop in some places where this is feasible
* Add todo
* Fix
* Remove synchronous wait
* Wrap fd listening callbacks in a class
* Remove poll_forever
* Remove the thread-local/thread-global optimization
This will not matter much soon anyway, and simplifies things
* Share promise code by using fused types
* Improve refcounting of python objects in promises
We replace many instances of PyObject* by Own<PyRefCounter> for more automatic
reference management.
* Code wrapPyFunc in a similar way to wrapPyFuncNoArg
* Refactor capabilityHelper, fix several memory bugs for promises and add __await__
* Improve promise ownership, reduce memory leaks
Promise wrappers now hold a Own<Promise<Own<PyRefCounter>>> object. This might
seem like excessive nesting of objects (which to some degree it is, but with
good reason):
- The outer Own is needed because Cython cannot allocate objects without a
nullary constructor on the stack (Promise doesn't have a nullary constructor).
Additionally, I believe it would be difficult or impossible to detect when a
promise is cancelled/moved if we use a bare Promise.
- Every promise returns a Owned PyRefCounter. PyRefCounter makes sure that a
reference to the returned object keeps existing until the promise is fulfilled
or cancelled. Previously, this was attempted using attach, which is redundant
and makes reasoning about PyINCREF and PyDECREF very difficult.
- Because a promise holds a Own<Promise<...>>, when we perform any kind of
action on that promise (a_wait, then, ...), we have to explicitly move() the
ownership around. This will leave the original promise with a NULL-pointer,
which we can easily detect as a cancelled promise.
Promises now only hold references to their 'parents' when strictly needed. This
should reduce memory pressure.
* Simplify and test the promise joining functionality
* Attach forgotten parent
* Catch exceptions in add_reader and friends
* Further cleanup of memory leaks
* Get rid of a_wait() in examples
* Cancel all fd read operations when the python asyncio loop is closed
* Formatting
* Remove support for capnp < 7000
* Bring asyncProvider.cpp more in line with upstream async-io-unix.c++
It was originally copied from the nodejs implementation, which in turn copied
from async-io-unix.c++. But that copy is pretty old.
* Fix a bug that caused file descriptors to never be closed
* Implement AsyncIoStream based on Python transports and protocols
* Get rid of asyncProvider
All asyncio now goes through _AsyncIoStream
* Formatting
* Add __dict__ to PyAsyncIoStreamProtocol for python 3.7
* Reintroduce strange ipv4/ipv6 selection code to make ci happy
* Extra pause_reading()
* Work around more python bugs
* Be careful to only close transport when this is still possible
* Move pause_reading() workaround
2023-06-06 20:08:15 +02:00
|
|
|
[
|
|
|
|
"capnp/helpers/capabilityHelper.cpp",
|
|
|
|
"capnp/lib/*.pyx",
|
|
|
|
],
|
2021-10-01 11:00:22 -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(
|
2023-04-04 03:55:17 +02:00
|
|
|
python_requires=">=3.7",
|
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",
|
2022-11-04 19:20:38 +01:00
|
|
|
"helpers/*.cpp",
|
2021-10-01 11:00:22 -07:00
|
|
|
"includes/*.pxd",
|
|
|
|
"lib/*.pxd",
|
|
|
|
"lib/*.py",
|
|
|
|
"lib/*.pyx",
|
2022-11-04 19:20:38 +01:00
|
|
|
"lib/*.h",
|
2021-10-01 11:00:22 -07:00
|
|
|
"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
|
|
|
)
|