Commit graph

134 commits

Author SHA1 Message Date
Jacob Alexander
1fb168796d Prepare for v2.0.0 release
- Update CHANGELOG.md
2024-01-19 08:35:01 -08:00
Jacob Alexander
84830d6357 Prepare for v2.0.0b2 release
- Update CHANGELOG.md
2023-11-25 11:04:29 -08:00
Lasse Blaauwbroek
aafec2281e Make reraise_kj_exception available to downstream
I'm using Pycapnp in a project, where we compile `.capnp` files directly to
Cython instead of using the dynamic interface (for speed). For this, we need
access to the `reraise_kj_exception` C function defined by Pycapnp. This is not
possible, because Cython does not automatically make this function available to
downstream users.

My previous solution, in #301, was rather flawed. The  file `capabilityHelper.cpp`, where
`reraise_kj_exception` is defined, was bundled into the distribution, so that
this file could be included in downstream libraries. This turns out to be a
terrible idea, because it redefines a bunch of other things like
`ReadPromiseAdapter`. For reasons not entirely clear to me, this leads to
segmentation faults. This PR revers #301.

Instead, in this PR I've made `reraise_kj_exception` a Cython-level function,
that can be used by downstream libraries. The C-level variant has been renamed
to `c_reraise_kj_exception`.
2023-11-05 13:58:13 -08:00
Tobias Ahrens
bb15822850
Fixes for capnp 1.0 (#1)
* add capnp_api.h to gitignore

* Change type of read_min_bytes from size to int

Not sure why this was not causing issues before or if that
is the right fix ... but it seems to be fine :)

* Adapt python_requires to >=3.8

This was overlooked when 3.7 was deprecated. The ci no longer
works with python 3.7 and cibuildwheel uses python_requires ...

* Replace deprecated find_module with find_spec (importlib)

find_module was deprecated with python 3.4 and python 3.12
removed it (https://docs.python.org/3.12/whatsnew/3.12.html#importlib).

The new command is find_spec and only required a few adaptions
2023-10-11 11:28:24 -07:00
Jacob Alexander
313d0d4c6d Prepare for v2.0.0b1 release
- Update CHANGELOG.md
- Update to bundled capnproto-1.0.1
  * Compiles with capnproto-0.8.0 and higher
- *Breaking Change* Remove allow_cancellation (see
  https://capnproto.org/news/2023-07-28-capnproto-1.0.html)
  * This is tricky to handle for older versions of capnproto. Instead of
    dealing with lots of complication, removing it entirely.
- Fix some documentation after the build backend support was added
- Update tox.ini to support 3.8 to 3.12
- Update cibuildwheel to 2.16.1
  * Adds Python 3.12 supports and implicitly deprecates EOL 3.7 (though it's
    still built)
2023-10-03 12:29:48 -07:00
Tobias Ahrens
d48ffea939
Add custom build backend to support build args (#328)
This implements a custom build backend, inspired by the
[solution used by Pillow.](https://github.com/python-pillow/Pillow/pull/7171)

install-option is deprecated and was removed with pip 23.1. The
comonly accepted solution seems to be to define a custom build
backend for now
https://github.com/pypa/setuptools/issues/2491#issuecomment-1589764230

This commit changes the usage from `--install-option` to `--config-settings`.
2023-10-02 22:30:51 -07:00
Lasse Blaauwbroek
d32854eb00
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 11:08:15 -07:00
Lasse Blaauwbroek
6d5ee1c6f2
Use cibuildwheel in ci (#309)
* Use cibuildwheel in ci

`cibuildwheel` is a system that automatically compiles and repairs wheels for
many python versions and architectures at once. This has some advantages vs the
old situation:
- Macosx wheels had inconsistent minimum versions ranging between 10.9 and
  11.0. I'm not sure why this happens, but for some users this means they have
  to build from source on macosx. With cibuildwheel, the build is
  consistent, with 10.9 as the minimum for x86 and 11.0 for arm64.
- Consolidation between the packaging tests and manylinux tests.
- Addition of musllinux targets and additional cross-compilation to ppc64le and
s390x.
- With cibuildwheel, new python versions should be automatically picked up.
- Separation of the sdist build and lint checks. There is not reason to run that
  many times.

All possible build targets succeed, except for ARM64 on Windows. The upstream
capnp build fails. I've disabled it.

The cross-compilation builds on linux are pretty slow. This could potentially be
sped up by separating the builds of manylinux and musllinux, but I'm not sure if
it's worth the extra complexity. (One can also contemplate disabling these
targets.)

Tests for macosx arm64 cannot be run (but also couldn't be run in the previous
system. This should be remedied once apple silicon becomes available on the CI.

I've also added some commented-out code that can automatically take care of
uploading a build to PyPi when a release is created. One might contemplate using this.

* Set CMAKE_OSX_ARCHITECTURES for arm64 and disable universal2
2023-04-03 18:55:17 -07:00
Jacob Alexander
33c453eff7 Increment version to v1.3.0 2023-01-26 16:43:40 -08:00
Jacob Alexander
9b6ff51f9c Update to v1.2.2 2022-12-01 21:58:30 -08:00
Jacob Alexander
56ef658e46 Update bundled bundled capnp to 0.8.1 due to CVE-2022-46149
- This only affects pycapnp if you're using bundled capnp (otherwise
  just update libcapnp)
  * pypi packages are affected
2022-11-30 10:18:06 -08:00
Lasse Blaauwbroek
928dd13652
Bundle lib/capnp_api.h and helpers/capabilityHelper.cpp (#301) 2022-11-04 11:20:38 -07:00
Jacob Alexander
1814105967 Incrementing version to v1.2.1 2022-09-11 23:08:45 -07:00
Jacob Alexander
583fe9e42d Incrementing version to v1.2.0 2022-08-29 01:13:39 -07:00
Madhava Jay
7862d2a0c4
Added macos arm64 Apple Silicon to CI (#296)
* Added macos arm64 Apple Silicon to CI

- Added missing python 3.10 metadata to setup.py

* Need all python versions in the matrix

* Fixing github action matrix syntax

* Changing MACOSX_DEPLOYMENT_TARGET for older python versions

- Technically no one would be running python 3.7 on M1 anyway

* Adding windows visualcpp build tools and updated cmake

* Increase max-parallel for all matrix builds

* yaml indent

* trying visualstudio2022-workload-vctools

* disabled everything but windows and added tunshell for debugging

* try older powershell

* trying again

* try python instead of powershell

* bash with wget

* Using old windows client on other side

* wrong way

* backwards

* :(

* urgh back to caveman debugging

- trying older windows runners

* try it again with extra build tools

* Reverting back to windows-2019 runner for windows builds

Fixing error:
CMake Error at CMakeLists.txt:2 (project):
  Generator
    Ninja
  does not support platform specification, but platform
    x64
  was specified.
2022-08-26 08:13:09 -07:00
Jacob Alexander
e93b0452cc Incrementing version to v1.1.1 2022-05-23 21:39:51 -07:00
Jacob Alexander
6e7fffd7de
Applying black formatting
- Fixing flake8 configuration to agree with black
- Adding black validation check to github actions
2021-10-01 11:12:21 -07:00
Jacob Alexander
6aa59476a0
Incrementing to v1.1.0 2021-06-07 21:30:48 -07:00
John Vandenberg
8c15feb4eb Remove many lint warnings
Mostly whitespace changes, with max-line-length set to 120
and double-quotes used, adopting black settings.

Related to https://github.com/capnproto/pycapnp/issues/128
2021-05-03 17:02:30 +08:00
Jacob Alexander
2e6d7be1dd
Changing PyPi classifier from Beta to Stable 2020-11-20 13:55:19 -08:00
Jacob Alexander
d6e73c8d75
Adding missing Python 3.9 category 2020-11-20 13:02:54 -08:00
Jacob Alexander
50d3a8e964
Preparing for v1.0.0 release 2020-11-20 11:50:09 -08:00
Jacob Alexander
5e8ccba536
Updating docs for v1.0.0b2
- Full cleanup of all the docs
- General sphinx housekeeping
- Updated all the old/bad links
- More reliable tests
- Updated Changelog
- Removed dead/deprecated code
- Added documentation generation test
2020-06-14 17:05:45 -07:00
Jacob Alexander
49fd4854d8 Minor code cleanup
- Reducing linter errors
- Removing old Python 2-only code (__future__ print)
2020-06-08 23:51:07 -07:00
Jacob Alexander
255119b838 Updating to capnproto v0.8.0
- Includes some test stabilization
- Fixes manylinux2010 build issues (linker flag order due to old gcc)
- More rigorous python setup.py clean
- Requires capnproto v0.8.0 or greater
- Including system libcapnp include path for import (e.g. import
  stream_capnp)
- Bundle libcapnp .capnp files when not using system libcapnp
- Removing more distutils usage. Now using pkg-config to determine the
  system version of libcapnp (mainly for Linux, but should work on macOS
  with brew)
- Removed dead code

Resolves issues #215 #216 #217
Lots of fixes for Issue #218 (all sorts of retry methods needed for
GitHub Actions)
2020-06-08 11:49:17 -07:00
Keith Rothman
dbc9debbbf Move exported functions used in capabilityHelper.h from extern "C" to api.
Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
2020-03-02 06:49:59 -08:00
Jacob Alexander
01e4d3ed2f
Removing pypandoc/pandoc requirement
- Was not working well on manylinux2010 build image
- Not necessary, can use markdown directly now
2019-12-26 23:52:10 -08:00
Jacob Alexander
84600a7ebf
Fixing Pypi warnings and errors
- Issues with pypandoc prevented uploading
2019-12-26 23:16:40 -08:00
Jacob Alexander
0e7a133080
Preparations for v1.0.0 release
- Starting with a beta1 release
2019-12-26 22:49:07 -08:00
Jacob Alexander
6cd971e74f
Adding manylinux2010 github action
- Validates that the manylinux2010 environment can build pycapnp
- Handle lib and lib64 cases
- Has patch for aligned_alloc symbol (not available prior to glibc 2.16)
https://github.com/capnproto/capnproto/issues/743
- Fixes #197
- Should be ready to prepare a v1.0.0b1 release
2019-12-21 00:13:04 -08:00
Jacob Alexander
795a0d88eb
Merge pycapnp-async into pycapnp
- Remove references to pycapnp-async
- Cleanup README.md and setup.py
2019-12-11 22:20:44 -08:00
Jacob Alexander
c1cba47346
Small updates for PyPi 2019-10-21 00:13:19 -07:00
Jacob Alexander
8062e6f401 Adding Windows 32-bit and 64-bit builds
- Basic tests are working
- May need some adjustments to get all tests working
- Cleaned up bundling to take Python arch into account when building
with multiple architectures
2019-10-17 00:36:46 -07:00
Jacob Alexander
67d5276936
Defaulting to built-in capnproto
- Adding code to detect if bundled capnproto is already built
2019-10-15 09:35:55 -07:00
Jacob Alexander
12ddd743ef
Fork pycapnp to pycapnp-async
- Breaking some earlier compatibility to cleanup build messages
- As well as being able to publish pypi releases
  * Builds can be complicated to package correctly
- Windows support
2019-10-14 21:34:08 -07:00
Yann Diorcet
722579d671
Guess include and lib directory using capnp executable 2019-09-30 00:58:10 -07:00
Jacob Alexander
d62e9b80f7
Always use Cython 2019-09-27 00:30:08 -07:00
Jacob Alexander
b3021e4f6b
Fixing flake8 warnings and errors
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude benchmark

Excluding the benchmark directory (due to protobuf generated files)
Also removing some Python2 specific code
2019-09-27 00:15:13 -07:00
Andrey Cizov
423e4f1f8c
remove warning during compilation 2019-09-16 21:34:58 -07:00
Jacob Alexander
de22f7eb97
Fixing compilation errors with capnproto-7.0.0 2019-09-16 21:33:56 -07:00
Andrey Cizov
ab267eccbd fix travis build failure 2019-07-13 15:06:18 +01:00
Jason Paryani
a4f740fb0f Bump version to v0.6.4 and update changelog 2019-01-31 01:10:15 -08:00
Jason Paryani
e4d7e21a66 Add error if trying to run python setup.py sdist without pandoc 2019-01-31 01:03:21 -08:00
Colin Jermain
2b26665f56 Removing Python 3.7 from this PR 2018-11-18 16:27:09 -05:00
Colin Jermain
3afcbb3918 Replacing end-of-life Python versions with live versions 2018-11-18 10:01:10 -05:00
Jason Paryani
19e1b189ca Bump version to v0.6.3 and update changelog 2018-01-14 11:57:08 -08:00
Jason Paryani
add8af4bc9 Bump version to v0.6.2 and update changelog 2017-11-30 22:08:01 -08:00
Jason Paryani
0242ba2d33 Bump to v0.6.1 and update changelog 2017-07-27 20:11:49 -07:00
Ben Moran
1221ec75a9 Update bundled capnproto to 0.6.0 2017-06-08 12:19:52 +01:00
Jason Paryani
98b5ed837b Bump version to v0.5.12 and update CHANGELOG 2017-04-18 21:44:30 -07:00