Commit graph

159 commits

Author SHA1 Message Date
John Vandenberg
bd91c52d57 Fix bare exception from str(obj)
There is no test coverage for these exception clauses,
however the invocation of obj.__str__() for client
objects could raise any exception, hence the very broad
exception catch.
2021-06-01 15:51:23 +08:00
John Vandenberg
a20e69dbe9 Replace bare exception from getfullargspec
getfullargspec is based on signature, which is documented to
raise TypeError and ValueError.

Related to https://github.com/capnproto/pycapnp/issues/254
2021-06-01 15:45:57 +08:00
John Vandenberg
0f6df849cd Refine exception invoking which on non-union type
Related to https://github.com/capnproto/pycapnp/issues/254
2021-06-01 15:40:35 +08:00
John Vandenberg
c179c72087 Allow enum to be used with .init 2021-05-31 19:31:53 +08:00
John Vandenberg
1795cac230 _StructModuleWhich: Use enum 2021-05-31 18:57:40 +08:00
John Vandenberg
0c904443bd Add Union on top level union messages
Closes https://github.com/capnproto/pycapnp/issues/247
2021-05-31 16:33:10 +08:00
Pavol Vargovcik
c0109662d2 _SegmentArrayMessageReader: release each view 2021-05-13 13:33:16 +02: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
John Vandenberg
a730554030 Dont crash if __file__ is not set by importer 2021-04-30 10:41:15 +08:00
Keith Rothman
480a079a16 Add missing inhertance to _Schema for _StructSchema.
Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
2020-12-14 11:11:38 -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
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
Floris van Nee
8bbb0f47ae Avoid infinite loop on to_dict() for RPC results 2020-04-24 19:49:50 +02: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
Keith Rothman
20d6c4eef7 Rename capnp.lib.capnp.Promise to capnp.lib.capnp._Promise.
This is to prevent aliasing with capnp.includes.capnp_cpp.Promise. This
aliasing is problematic if capnp/lib/capnp.pxd uses the template definition
from capnp.includes.capnp_cpp.Promise.

Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
2020-02-28 16:53:52 -08:00
Jacob Alexander
ac6cdec2d0
Fixes Issue #202
- __path__ was being set to a string
- It's supposed to be a list of strings or None

For pycapnp pydoc isn't super useful at the module level as pydoc will
scan all the files in the directory and just list them.

Here's thread_capnp for example, notice how it doesn't show any
information on the .capnp files.

Help on package thread_capnp:

NAME
    thread_capnp

PACKAGE CONTENTS
    addressbook
    async_calculator_client
    async_calculator_server
    async_client
    async_reconnecting_ssl_client
    async_server
    async_ssl_client
    async_ssl_server
    calculator_client
    calculator_server
    thread_client
    thread_server

DATA
    Example = <capnp.lib.capnp._InterfaceModule object>
    schema = <capnp.lib.capnp._ParsedSchema object>
2020-02-07 16:44:41 -08:00
Pavol Vargovcik
f3ae35eedd fix: package_path is _NamespacePath, not list 2020-01-20 17:51:41 +01:00
Jacob Alexander
dd3551f978
Adding poll_once() to TwoPartyServer API
- poll_forever() doesn't allow for checking socket connection to client
  * Need to check for client, if eof received then we can close the
  connection and cleanup pycapnp cpu resources (async tasks)
- Updated async examples to fix bugs
  * Add checking code for socket connection to the client and gracefully
  cleanup resources once the client socket connection closes
  * Instanciate a new TwoPartyServer per connection (allows for multiple
  connections)
- Should resolve Issue #198
2020-01-08 18:06:26 -08:00
Andrey Cizov
7bce2f751a
fix #181 2019-12-26 22:13:34 -08:00
Andrey Cizov
0f0b30c666
enable structs to be initialized the Python way 2019-12-26 21:25:29 -08:00
Jacob Alexander
362cce345b Fixing Windows tests
- Adding import path filter to exclude non-directories
  Otherwise kj will through exceptions
- Skipped AF_UNIX socket test
- Use default socket configuration when it doesn't matter the type of
socket used
- Open files with utf8 encoding (needed for text validation)
- Explictly call python executable when running external scripts
- Fix path creation to always use os.path.join
- Added timeout to client wait in some tests

- Some broken tests still remain (most likely asyncio related)
2019-10-19 00:26:55 -07:00
Jacob Alexander
62eccff150
Adding capnp extension validation check
- To catch odd import problems on Windows
2019-10-18 12:25:04 -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
10355a74ac
More agressive warning fixes
capnp/lib/capnp.cpp:35163:294: warning: moving a temporary object prevents copy
      elision [-Wpessimizing-move]
  ...*)__pyx_t_3), new  ::capnp::DynamicStruct::Pipeline(std::move((( ::capn...
                                                         ^
capnp/lib/capnp.cpp:35163:294: note: remove std::move call here
  ...std::move((( ::capnp::DynamicValue::Pipeline)__pyx_v_self->thisptr->get(__pyx_t_5)).releaseAs< ::capnp::DynamicStruct>())...
     ^~~~~~~~~~                                                                                                              ~
capnp/lib/capnp.cpp:39540:53: warning: moving a temporary object prevents copy
      elision [-Wpessimizing-move]
  __pyx_v_self->thisptr = new  ::kj::AsyncIoContext(std::move( ::kj::se...
                                                    ^
capnp/lib/capnp.cpp:39540:53: note: remove std::move call here
  ...= new  ::kj::AsyncIoContext(std::move( ::kj::setupAsyncIo()));
                                 ^~~~~~~~~~                     ~
capnp/lib/capnp.cpp:47838:294: warning: moving a temporary object prevents copy
      elision [-Wpessimizing-move]
  ...*)__pyx_t_3), new  ::capnp::DynamicStruct::Pipeline(std::move((( ::capn...
                                                         ^
capnp/lib/capnp.cpp:47838:294: note: remove std::move call here
  ...std::move((( ::capnp::DynamicValue::Pipeline)__pyx_v_self->thisptr->get(__pyx_t_5)).releaseAs< ::capnp::DynamicStruct>())...
     ^~~~~~~~~~                                                                                                              ~
2019-10-14 23:54:00 -07:00
Jacob Alexander
f6dd08dda6
Removing deprecated Restorer and ezRestore references
- Not recommended to be used in new designs
- Just pollutes warning messages during compilation (hiding ones that
should be fixed)
- Updated test code to use bootstrap
- Sped up some of the test code that was just sleeping while waiting for
the server (now polling for the socket)
2019-10-14 23:19:39 -07:00
Jacob Alexander
de61c304e1
Adding sleep delay
- Reduces 99% CPU usage to around 1%
- It might be useful to have the sleep/delay tunable for certain
applications depending on the latency requirements
2019-10-12 16:21:58 -07:00
Jacob Alexander
75e0e7e84c
Fixed or waved all pytest failures and errors
- Needed to include cleanup_global_schema_parser() to handle duplicate
imports of the same .capnp file
  * Duplicate IDs are a problem as pytest does not fully cleanup between
  tests
- Marked some tests as xfail as I'm not sure the test is supposed to
work anymore with recent versions of capnproto
2019-09-27 01:12:54 -07:00
Jacob Alexander
8915ef79f1
TwoWayPipe and basic asyncio support
Note: I've tried not to break any behaviour of the previously working APIs

Python API Changes / Additions
- capnp/lib/capnp.pyx
  * class _RemotePromise
    + [Added] cpdef _wait(self)
      = Exception raising code that used to be inside of wait(self)
    + [Modified] def wait(self)
      = Same functionality as before
    + [Added] async def a_wait(self)
      = Cannot use await as that's a reserved keyword
      = Uses pollRemote and asyncio.sleep(0) to make call asynchronous
  * class _TwoPartyVatNetwork
    + [Added] cdef _init_pipe(self, _TwoWayPipe pipe, Side side,
    schema_cpp.ReaderOptions opts)
      = Instanciates a TwoPartyVatNetwork using a TwoWayPipe (instead of
      using a file handle or connection as before)
  * class TwoPartyClient
    + [Modified] def __init__(self, socket=None, restorer=None,
    traversal_limit_in_words=None, nesting_limit=None)
      = Changes the socket parameter to be optional
      = If socket is not specified, default to using a TwoWayPipe
    + [Added] async def read(self, bufsize)
      = awaitable function that blocks until data has been read
      = bufsize defines the maximum amount of data to be read back
        (e.g. 4096 bytes)
      = Reads data from TwoWayPipe
    + [Added] def write(self, data)
      = Write data to TwoWayPipe
      = Not awaitable as the write interface of the TwoWayPipe doesn't
      have poll functionality
  * class TwoPartyServer
    + [Modified] def __init__(self, socket=None, restorer=None,
    server_socket=None, bootstrap=None, traversal_limit_in_words=None,
    nesting_limit=None)
      = Changes the socket parameter to be optional
      = If socket is not specified, default to using a TwoWayPipe
      = Simplified code by removing an else (self._connect)
    + [Added] async def read(self, bufsize)
      = awaitable function that blocks until data has been read
      = bufsize defines the maximum amount of data to be read back
        (e.g. 4096 bytes)
      = Reads data from TwoWayPipe
    + [Added] def write(self, data)
      = Write data to TwoWayPipe
      = Not awaitable as the write interface of the TwoWayPipe doesn't
      have poll functionality
    + [Added] async def poll_forever(self)
      = asyncio equivalent of run_forever()
  * class _TwoWayPipe
    + Wrapper class for TwoWayPipe

Other Additions
- capnp/helpers/asyncHelper.h
  * pollWaitScope
    + Pumps the kj event handler
    + Used for the TwoWayServer
  * pollRemote
    + Polls a remote promise
    + i.e. a capnp RPC call
- capnp/helpers/asyncIoHelper.h
  * AsyncIoStreamReadHelper
    + I wasn't able to figure out Promise[size_t] using Cython so this was
    the next best thing I could think of doing
    + Was needed to handle read polling from a read promise
      = Polling is used for asyncio as kj waits need a wrapper to be
      compatible
- capnp/lib/capnp.pyx
  * makeTwoWayPipe
    + Wrapper for kj newTwoWayPipe function
  * poll_once
    + Single pump of the kj event handler (used with pollWaitScope)

TwoWayClient Usage - TwoWayPipe
- See examples/async_client.py

TwoWayServer Usage - TwoWayPipe
- See examples/async_server.py

capnp/helpers/asyncIoHelper.h

Misc Changes
- Fixed thread_server.py and thread_client.py to use bootstrap instead
of ez_restore
- async_client.py and async_server.py examples
  * Uses the same thread.capnp as thread_client.py and thread_server.py
  * They are compatible, so you can mix and match client and server for
  compatibility testing
  * async_client.py and async_server.py require <address>:<port>
  formatting (unlike autodetection from thread_client.py and
  thread_server.py)
2019-09-26 21:42:48 -07:00
Jacob Alexander
e73b63ddd1
Removed deprecated functions
- PyObject_AsReadBuffer
- PyObject_AsWriteBuffer
2019-09-16 21:37:00 -07:00
Andrey Cizov
e8662a1dc9
remove deprecation warnings 2019-09-16 21:34:58 -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
Trevor Highland
dbd23721a9 Support long messages in read_multiple_bytes. 2019-01-28 17:04:34 +00:00
Colin Jermain
eb62693915 Exposing SchemaParser in Cython header 2018-11-06 21:11:59 -05:00
Yuval Katsnelson
a73395e7bb Fixed Python object leak in RemotePromise 2017-12-06 10:48:38 +02:00
Ivan Smirnov
18e87a1719 (Remove now-redundant import) 2017-11-28 00:19:15 +00:00
Ivan Smirnov
6a5f697f72 Support generic buffers in from_bytes()
(Also throw a TypeError if it's not a bytes object or a buffer)
2017-11-28 00:18:20 +00:00
Ben Moran
fbc1767475 Expose Duration units and add a Nanoseconds function to let us build against 0.6.0 2017-06-08 12:01:11 +01:00
Jason Paryani
073a503add Merge pull request #136 from ternaris/lists-from-tuples
support initializing DynamicListBuilder from tuple
2017-04-09 17:36:35 -07:00
Jason Paryani
3f04134e72 Merge pull request #139 from tundra/develop
Pass options correctly through from_bytes to FlatArrayMessageReader
2017-04-09 17:11:20 -07:00
Jason Paryani
5eec70231a Merge pull request #126 from asilversempirical/pass_reader_opts_clean
Let TwoParty Clients and Servers take ReaderOptions
2017-04-09 16:52:36 -07:00
Christian Plesner Hansen
34385afbbd Pass options correctly through from_bytes to FlatArrayMessageReader 2017-02-15 12:02:41 +01:00
Florian Friesdorf
1bfc20fefb support initializing DynamicListBuilder from tuple 2017-02-09 02:16:25 +01:00
Alex Silverstein
0382beb26a Let TwoParty Clients and Servers take ReaderOptions 2017-01-22 02:25:58 +00:00
Florian Friesdorf
f2c7f61b7d include class attributes in __dir__
This enables tab completion for methods as well as fieldnames.
2017-01-20 11:00:11 +01:00
Madeleine Thompson
93ea35e558 make enums hashable 2016-12-05 22:43:09 -05:00
Jason Paryani
97824b957b Add clear_write_flag method to builders
Fixes #111
2016-08-09 12:26:18 -07:00
Jason Paryani
d85200cee3 Remove recursive loop in KjException.type
Fixes #108
2016-07-29 11:59:02 -07:00
Jason Paryani
4488194f59 Make event loop be lazy initialized for real 2016-07-29 11:57:19 -07:00
Jason Paryani
da233c46ad Make the event loop be lazy initialized
Fixes #101
2016-07-07 12:11:42 -07:00