Skip to content

Commit bb15822

Browse files
authored
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
1 parent 313d0d4 commit bb15822

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ docs/_build
4646

4747
capnp/lib/capnp.cpp
4848
capnp/lib/capnp.h
49+
capnp/lib/capnp_api.h
4950
bundled/
5051
example
5152
*.iml

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## v2.0.0b1 (2023-10-03)
22
- Update to bundled capnproto-1.0.1
3-
- Remove explicit support for Python 3.7 (though wheels are still built for now)
3+
- Remove support for Python 3.7
44
- Use custom build backend to support build args (#328)
55
- Update Cython version and Python to 3.12 (#320)
66
- Wrap all capnp code in a context-manager to avoid segfaults (#317)

capnp/lib/capnp.pyx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ from types import ModuleType as _ModuleType
4242
from operator import attrgetter as _attrgetter
4343
from functools import partial as _partial
4444
from contextlib import asynccontextmanager as _asynccontextmanager
45+
from importlib.machinery import ModuleSpec
4546

4647
_CAPNP_VERSION_MAJOR = capnp.CAPNP_VERSION_MAJOR
4748
_CAPNP_VERSION_MINOR = capnp.CAPNP_VERSION_MINOR
@@ -2423,7 +2424,7 @@ cdef class _PyAsyncIoStreamProtocol(DummyBaseClass, asyncio.BufferedProtocol):
24232424

24242425
# State for reading data from the transport
24252426
cdef char* read_buffer
2426-
cdef size_t read_min_bytes
2427+
cdef int32_t read_min_bytes
24272428
cdef size_t read_max_bytes
24282429
cdef size_t read_already_read
24292430
cdef PromiseFulfiller[size_t]* read_fulfiller
@@ -4322,7 +4323,7 @@ class _Importer:
43224323
self.extension = '.capnp'
43234324
self.additional_paths = additional_paths
43244325

4325-
def find_module(self, fullname, package_path=None):
4326+
def find_spec(self, fullname, package_path, target=None):
43264327
if fullname in _sys.modules: # Don't allow re-imports
43274328
return None
43284329

@@ -4363,12 +4364,12 @@ class _Importer:
43634364
path = abspath(path)
43644365

43654366
if is_file(path+sep+capnp_module_name):
4366-
return _Loader(fullname, join_path(path, capnp_module_name), self.additional_paths)
4367+
return ModuleSpec(fullname, _Loader(fullname, join_path(path, capnp_module_name), self.additional_paths))
43674368
if has_underscores:
43684369
if is_file(path+sep+capnp_module_name_dashes):
4369-
return _Loader(fullname, join_path(path, capnp_module_name_dashes), self.additional_paths)
4370+
return ModuleSpec(fullname, _Loader(fullname, join_path(path, capnp_module_name_dashes), self.additional_paths))
43704371
if is_file(path+sep+capnp_module_name_spaces):
4371-
return _Loader(fullname, join_path(path, capnp_module_name_spaces), self.additional_paths)
4372+
return ModuleSpec(fullname, _Loader(fullname, join_path(path, capnp_module_name_spaces), self.additional_paths))
43724373

43734374

43744375
_importer = None

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def run(self): # noqa: C901
210210
]
211211

212212
setup(
213-
python_requires=">=3.7",
213+
python_requires=">=3.8",
214214
name="pycapnp",
215215
packages=["capnp"],
216216
version=VERSION,

test/test_load.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ async def wrapped(self, object, **kwargs):
144144
baz_.text = "test"
145145
baz_.qux.id = 2
146146

147-
wrapper = foo.Wrapper._new_client(Wrapper())
148-
remote = wrapper.wrapped(baz_)
149-
await remote
147+
async with capnp.kj_loop():
148+
wrapper = foo.Wrapper._new_client(Wrapper())
149+
remote = wrapper.wrapped(baz_)
150+
await remote

0 commit comments

Comments
 (0)