Update on python-cffi bindings
Floris Bruynooghe
flub at devork.be
Fri Dec 29 10:18:01 PST 2017
Hi all,
Daniel Kahn Gillmor <dkg at fifthhorseman.net> writes:
> On Thu 2017-12-21 12:30:39 +0100, Floris Bruynooghe wrote:
>> The API changes a lot and there is no easy migration. And history has
>> shown that's a terrible way to get something new adopted. Last time I
>> suggested a possible multi-tiered approach (maybe not as explicit):
>>
>> 1 I think it's possible to move the memory management technique to the
>> existing API without API breakage. It would still allow users to call
>> functions in the wrong order etc, but that's not any regression.
>>
>> 2 It's probably possible to either switch the existing API to use CFFI
>> or create a drop-in replacement for it based on CFFI. The benefit
>> here is two-fold: users get better PyPy performance and I believe it
>> becomes easier to maintain the bindings, e.g. all you need to do to
>> call notmuch_database_get_path is
>> capi.ffi.string(capi.lib.notmuch_database_get_path(dbptr)) (see
>> https://github.com/flub/notmuch/blob/cffi/bindings/python-cffi/notdb/_database.py#L263)
>> for an actual example). But this really depends on what everyone else
>> here that maintains the Python bindings here thinks. I'd encourage to
>> have a look at the CFFI implementation to get an idea of this.
>
> these two steps on their own seem like they give us:
>
> * better and safer memory management
>
> * better performance on PyPy
>
> * arguably, easier maintenance of the bindings.
>
> These seem like unambiguous wins, and there is no downside -- people
> using the notmuch module can just upgrade to the new version and it's
> done. I'd love to see these changes happen.
>
> The only thing it doesn't do is provide more idiomatic bindings for new
> users, which you describe as:
>
>> 3 As last step I still think providing the more idiomatic bindings is
>> useful, especially for new users. It does take the burden of
>> correctly calling the C functions somewhat more. This could then
>> either treat a notmuch_cffi as a lower level API which more directly
>> maps the C API or it could call C directly as it does now. I'm not
>> currently sure on which is more feasible or better here.
>>
>> An additional thing that could be done here to ease migration is to
>> allow creating the new objects from the old ones allowing a codebase
>> to gradually adopt the newer API where appropriate. E.g.:
>>
>> db = notmuch.Database(...)
>> msg = db.find_message(...)
>> new_db = notdb.Database.from_notmuch(db)
>> new_msg = notdb.Message.from_notmuch(msg)
>> print('Tags not on msg: {}'.format(new_db.tags - new_msg.tags))
>>
>> This would rely on the existing API to migrate to CFFI, otherwise it
>> could still be possible but would be very hairy.
>
> I'm not sure i understand this last sentence. Are you saying that step
> 3 depends on step 2 happening?
The mixing of a new API with the existing API would be possible if we
can successfully migrate the existing notmuch API to use CFFI. If not
it may theoretically be possible but could be a lot of pain.
> I'm not sure about the name "notdb"
I'm in no way attached to this name, just needed something to work with.
Naming things is hard, if anyone has a different idea please share.
> but i don't mind the idea of there
> being some other "more-pythonic" notmuch bindings. New users would
> likely prefer it, and that'd be fine.
>
>> - For exposing completely new APIs, sure building the
>> notdb.ImmutableTagSet and MutableTagSet was not straight forward,
>> likewise for the PropertiesMap. Many other things are much easier
>> though. One possible nice way to alleviate this with the idea of the
>> existing notmuch API being the lower-level layer nearly mimicking the
>> C-API directly. That way adding new APIs there is more or less
>> straight forward and there is less time pressure to add them to the
>> higher level API. Especially if mixing the APIs is supported.
>
> I think this is in line with the approach described above. I like it.
I would really like to hear from some of the existing python binding
users on all of the above and what they thing of this approach. Is this
work worth it to you? Will it make you more or less likely to want to
migrate to more pythonic bindings?
In particular I'm not that convinced in the suitability of the existing
library as a low-level binding as it currently sits somewhere above
basic wrapping of libnotmuch. Anyway, I would appreciate any feedback
on the proposed APIs and way forward.
Cheers,
Floris
More information about the notmuch
mailing list