From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id RyE8Hhm2/F8ddQAA0tVLHw (envelope-from ) for ; Mon, 11 Jan 2021 20:33:29 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id oNiBGRm2/F9zBAAAB5/wlQ (envelope-from ) for ; Mon, 11 Jan 2021 20:33:29 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 04F789405D4 for ; Mon, 11 Jan 2021 20:33:28 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 2362529E53; Mon, 11 Jan 2021 15:33:22 -0500 (EST) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by mail.notmuchmail.org (Postfix) with ESMTPS id 4404227C7D for ; Mon, 11 Jan 2021 15:33:20 -0500 (EST) Received: by mail-ej1-x62b.google.com with SMTP id t16so191115ejf.13 for ; Mon, 11 Jan 2021 12:33:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:in-reply-to:references:date:message-id :mime-version; bh=JgOicMLiBavnqBpWhFV31EjnjYJnz7Y7YvpIgMNFzkc=; b=Z9ksb1I+xvIIT3kROFnNEwUDxsImelhOCC+GujRjBRiVHHGB/wJ6QoeB3UZQqTc4iZ A7cs8bTydmZu7KJj7qc8kJQEjPM2u5oJ9h5Z1d9YN2Bs1NIE8cN8Xk/mJWmm4ET/C9sm OhGrsC2HUUlODy67pn2fP95SE4fNMkhbbtymLc3I4mUT7/jfEmQll2dkGVva+APJZZW9 G+4T6DC/FTbq4VFf7KM5K0vXnB5JsZ1PvzkaAhwc3C8bdwAfg6hEB1o9DskQIAb65k1j 3s2M0aKVO3NC+O7MGv6LsegF9wONKXB85gClsWtwqWDJYNFBcsDNEyS9sy4SBSITylQ3 kbDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:in-reply-to:references :date:message-id:mime-version; bh=JgOicMLiBavnqBpWhFV31EjnjYJnz7Y7YvpIgMNFzkc=; b=uhIhl7zdgom9PEk9yzLufi5jmhH5+J0wMwdgOD7RSag3J96am567kfpaIbkCYwRpTd sHrM0kaKLAikOfCKgirerpcRWreR51YF4dP++rxCWqnh2V2HvjWLETqjW9sxxnfybKlU 5x05nVEL7udoXyfnOVv5Epk0fF0Iel2uhjlFPthqSRlwxMz6sGiy2c5DNc0hvRbsUHw1 8D+nnuYj20/saCoR5fX5EyDmMHz1fuoQ+QhRgjogB6JjbVjBvrLqTU5+etL8tniHJLa9 ymCO3BMEkugRqir2HsgCpezYV7N6jKIi/tfbEQdy1C9wGT04gOIHR/xwN/qk3Or1TUv3 9caQ== X-Gm-Message-State: AOAM531ONrbBSGP0KVSDS5vsX12MlDTVxUeYeiO+tbmdyZ8trAJo45gx B2BWBu4CrUFYmpKNBW+SGyY= X-Google-Smtp-Source: ABdhPJwmVypBcOc1znbpV75tQ2FdLKYeCs2U95M+8Mr6WXR67/jfEuI2O4wan8h0hyFlWd12lk5oog== X-Received: by 2002:a17:906:d146:: with SMTP id br6mr809859ejb.331.1610397198160; Mon, 11 Jan 2021 12:33:18 -0800 (PST) Received: from powell.devork.be (2a02-8388-8480-1180-4c18-fc69-8d8c-22b5.cable.dynamic.v6.surfer.at. [2a02:8388:8480:1180:4c18:fc69:8d8c:22b5]) by smtp.gmail.com with ESMTPSA id mb22sm292113ejb.35.2021.01.11.12.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jan 2021 12:33:17 -0800 (PST) Sender: Floris Bruynooghe Received: (nullmailer pid 804216 invoked by uid 1000); Mon, 11 Jan 2021 20:33:16 -0000 From: Floris Bruynooghe To: Michael J Gruber , notmuch@notmuchmail.org Subject: Re: [PATCH 3/3] python/notmuch2: provide binding for collect_tags() In-Reply-To: <9c89dfcf04606c9f5c1d4514096499f3ae7323d0.1609347527.git.git@grubix.eu> References: <9c89dfcf04606c9f5c1d4514096499f3ae7323d0.1609347527.git.git@grubix.eu> Date: Mon, 11 Jan 2021 21:33:16 +0100 Message-ID: <87sg7743jn.fsf@powell.devork.be> MIME-Version: 1.0 Message-ID-Hash: KPZPXZ7IDRAMVCJYD2SCQXJ5ANLD7L5M X-Message-ID-Hash: KPZPXZ7IDRAMVCJYD2SCQXJ5ANLD7L5M X-MailFrom: floris.bruynooghe@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.08 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=Z9ksb1I+; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 04F789405D4 X-Spam-Score: -1.08 X-Migadu-Scanner: scn0.migadu.com X-TUID: jDTrafjtCM9j Hi Micahel, Thanks for adding this feature! On Wed 06 Jan 2021 at 10:08 +0100, Michael J. Gruber wrote: > diff --git a/bindings/python-cffi/notmuch2/_query.py b/bindings/python-cffi/notmuch2/_query.py > index 1db6ec96..a1310944 100644 > --- a/bindings/python-cffi/notmuch2/_query.py > +++ b/bindings/python-cffi/notmuch2/_query.py > @@ -2,6 +2,7 @@ from notmuch2 import _base as base > from notmuch2 import _capi as capi > from notmuch2 import _errors as errors > from notmuch2 import _message as message > +from notmuch2 import _tags as tags > from notmuch2 import _thread as thread > > > @@ -66,6 +67,17 @@ class Query(base.NotmuchObject): > raise errors.NotmuchError(ret) > return count_p[0] > > + def collect_tags(self): > + """Return the tags of messages matching this query.""" > + msgs_pp = capi.ffi.new('notmuch_messages_t**') > + ret = capi.lib.notmuch_query_search_messages(self._query_p, msgs_pp) > + if ret != capi.lib.NOTMUCH_STATUS_SUCCESS: > + raise errors.NotmuchError(ret) > + self._msgs_p = msgs_pp[0] > + tagset = tags.ImmutableTagSet( > + self, '_msgs_p', capi.lib.notmuch_messages_collect_tags) > + return tags.ImmutableTagSet._from_iterable(tagset) > + > def threads(self): > """Return an iterator over all the threads found by the query.""" > threads_pp = capi.ffi.new('notmuch_threads_t **') How this this look on the C level for the memory allocator? If the query gets freed the messages also get freed? In that case indeed the messages do need to be kept alive together with the query indeed. Keeping them as an attribute on the query object seems reasonable I think, they'd be freed at the same time and I don't think this creates a circular reference. There's only a small detail though: to get the correct ObjectDestroyed exceptions you need Query._msgs_p to be a _base.MemoryPoiniter descriptor, like Query._query_p is currently. And then you also need to set it to None in Query._destroy. It would also be really good to add at least one happy-path test for this, ensuring that you get the tags in the query. You could add some to TestQuery in test_database.py. The database is created with unread and inbox tags i think (see conftest.py:75) so the messages should already have some tags which is sufficient as you're not testing notmuch's behaviour itself but only that the bindings give you a right looking tagset (the tagset itself also has tests already, so no need to test this extensively, just see if you have some tags). Otherwise LGTM! Cheers, Floris