-
Notifications
You must be signed in to change notification settings - Fork 97
Migrate to notmuch2 module #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
88d675e
to
6e98c68
Compare
ret = set() | ||
for msg in db.open().messages('folder:{}'.format(folder)): | ||
with open(msg.path) as f: | ||
ret.add((os.path.basename(msg.messageid), | ||
email.message_from_file(f).get_payload())) | ||
return ret |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: would it be interesting to run this method asynchronously to speed things up? I believe this will speed things up when someone has a bunch of emails to process. Perhaps having a private method that handles the asynchronous call and calls add
? I've done something similar here: https://github.com/afewmail/afew/pull/316/files#r744197423
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just in the test suite, which has 10 e-mails or so.
That mail mover test suite is not exactly "pretty" anyways, the proposed changes are the minimal ones to let it pass with the notmuch2 bindings. I would refactor the e-mail comparisons quite a bit, for example.
My bad, I didn’t pay attention to the file name.
On Sat, 27 Nov 2021 at 10:57 Michael J Gruber ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In afew/tests/test_mailmover.py
<#320 (comment)>:
> + ret = set()
+ for msg in db.open().messages('folder:{}'.format(folder)):
+ with open(msg.path) as f:
+ ret.add((os.path.basename(msg.messageid),
+ email.message_from_file(f).get_payload()))
+ return ret
This is just in the test suite, which has 10 e-mails or so.
That mail mover test suite is not exactly "pretty" anyways, the proposed
changes are the minimal ones to let it pass with the notmuch2 bindings. I
would refactor the e-mail comparisons quite a bit, for example.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#320 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG7RFQFWCGGQMKVQOKAGJLUODPVBANCNFSM5I3ML44A>
.
--
Ben Mezger
|
Hey @mjg ! This is a big subject as the eco-system is gona migrate to the new python module soon (notmuch, alot and afew), But I didn't merge it right away because many distro still ship older version of notmuch (0.2x I think), Is there something going on with the ci runners ? Maybe there is an issue un GH now ? |
I see that lieer is trying to still support 18LTS versions of ubuntu by catering for both versions of the notmuch bindings. Is that something you would prefer, too? In this case this PR needs to be done differently, of course. (Also, I haven't looked into it since.) |
Hey @mjg, If we can refactor the branch to able to support both, it would nice because we could merge now, In the end it depends on the implementation. |
Is there something I can do to help to get this merged ? The current notmuch bindings bother me by causing segmentation faults is certain cases. |
Hey @hbog , |
What would help (without having to port any bindings) is adding more tests so that at least each filter is covered. |
6e98c68
to
4c4d9b4
Compare
I"ve reworked the series and used it in "production", together with #350 and the mailcap dead battery, on Fedora 41with python 3.13. Side note: upcoming notmuch 0.39 will drop the legacy bindings. I see no point in refactoring just to keep supporting the legacy bindings when users can use a specific afew version from pip. |
4c4d9b4
to
599a279
Compare
Hey @mjg , Also would you be interested to co-maintain afew ? (I need help) |
599a279
to
0ed8ad0
Compare
Hi @GuillaumeSeren , A few (huh) days ago I removed python-notmuch from my system and discovered some uses of As for comaintership: I feel honoured by the offer but don't want to make promises which I cannot uphold. (Also, last time I took over comaintership somewhere the maintainer disappeared ...) |
I tried running this patched version of afew with python 3.13 on Debian Testing, and I get the following
I don't know that much about python packaging on Debian, so it could be specific to the way I generated a Debian package. |
Hi @bremner , how do you run afew? Do you have a config file? Does your method of packaging work without this branch? |
Michael J Gruber ***@***.***> writes:
mjg left a comment (afewmail/afew#320)
Hi @bremner , how do you run afew? Do you have a config file?
I just ran "afew" without any arguments. I don't have a config file.
Does your method of packaging work without this branch?
Without this branch I get "You need to specify an action", which seems
like (limited) success.
I use afew installed via pip from a checkout.
I am not actually an afew user, just trying to unbreak the Debian
package. So your method would not work for me.
EDIT: The underlying problem looks to be readfp is gone as of python 3.12
https://docs.python.org/3/whatsnew/3.12.html#configparser
|
Sure, that's why I wrote "together with #350" ;-) |
Michael J Gruber ***@***.***> writes:
mjg left a comment (afewmail/afew#320)
Sure, that's why I wrote "together with #350" ;-)
Ah. Yes, I'm (clearly) not really good at working with github; I just
cherry picked a range of commits and ignored the surounding
commentary. Anyway, with 350 it seems to work. Someone(TM) should really
do a release.
|
@mjg, would you mind rebasing your branch on afew's current master? I would like to try this PR using Arch Linux package manager (directly from your branch), but it seems that your branch is missing some important commits from master. Thanks! |
Signed-off-by: Guillaume Seren <[email protected]>
Signed-off-by: Guillaume Seren <[email protected]>
Signed-off-by: Guillaume Seren <[email protected]>
283ee15 ("Upgrade Database to notmuch2 python module afewmail#278", 2020-11-11) adjusted Databse partially to notmuch2. There, open() does not have a create argument any more. So far, only afew's test suite needs to create a db. So, remove the argument from afew's Database class and use notmuch2's create() directly in the test suite.
Besides the obvious call signature changes, filenames are Posix.Path objects now, searches do not return an email.Message object, and non-existing headers throw a LookupError.
Not caught by the test suite.
0ed8ad0
to
44c6438
Compare
Rebased on top of master which contains the readfp fix now. |
Unsure how related it is but I get this error when
I use build instructions from Arch's afew package with mjg's branch. Later I will try to use build scripts directly and with minimal config unless someone already knows what's the problem in the meantime. |
I'm seeing the same error as @jirijakes - fixed it with this patch: diff --git a/afew/filters/BaseFilter.py b/afew/filters/BaseFilter.py
index 3803d7b..716f8b0 100644
--- a/afew/filters/BaseFilter.py
+++ b/afew/filters/BaseFilter.py
@@ -102,6 +102,9 @@ class Filter:
message.tags.add(tag)
for tag in self._remove_tags.get(message_id, []):
- message.tags.remove(tag)
+ try:
+ message.tags.remove(tag)
+ except KeyError:
+ pass
self.flush_changes() |
Thanks, I guess neither the test nor my setup remove tags which are not present. I vaguely remember a discussion whether this should even be possible to occur or caught earlier. |
Thanks, @tohojo. Yeah, applying this patch makes it all work. But I understand the concern with this kind of fix. |
Yeah, may well be there should be a check somewhere else. Didn't look that closely, just needed a quick fix to get my email working again :) OTOH, if the notmuch bindings have previously just accepted this behaviour there's a good chance that this is how things have always functioned, and suppressing the error just makes it visible what the notmuch bindings were silently doing before? |
With notmuch2 bindings, removing a non-existing tag raises a KeryError. Catch that to allow the same filter usage as with legacy bindings. Suggested-By: Toke Høiland-Jørgensen <[email protected]>
44c6438
to
c4ba4b9
Compare
Yes, checked the usage, and you're supposed to be able to just remove tags, present or not. I've rebased and put @tohojo 's fix second but last - the last ones enables CI and needs be rewritten. Are the new notmuch bindings not available for py 3.9? I could try one by one, of course, and annoy everyone with forced pushes ... |
Well, the Python bindings are just wrappers around C functions, so they are not really portable across Python versions. The way the CI is setup, it just links the distribution packaged version of the bindings into the Python venv, so that will only work with whatever version of Python the distribution ships. And maybe not even that, since the setup-python action AFAIU installs binaries from upstream Python, which I'm not sure are compatible with the one compiled by the distribution. So to get CI working with these bindings, it will have to be changed to clone the notmuch git repository and compile the bindings inside the venv... |
I'm kinda wondering how this worked before. I expected a wheel to be available and to be used. Difficult to test locally, but I may try some pushes ... |
c4ba4b9
to
8f96332
Compare
8f96332
to
9566af1
Compare
Yeah 🥇 |
I'm kinda wondering how this worked before.
Looks like the v1 bindings open the libnotmuch.so library from the Python
side, whereas v2 goes the other way and compiles a Python extension from
the C sources.
|
Just to say that 126f89f works for me as well. Thanks! My setup: arch linux |
Huh, interesting that |
This is more of a POC/minimal change to get afew's update to notmuch2 going. I'll check with notmuch's maintainer what he prefers - there was discussion about shutting down the github mirror of notmuch, which could be a base for pip. But I have no experience with packaging for pip/pypa. The alternative is to trim down the test matrix to default install of python+notmuch, with maybe more distro varsions or variants. |
FTR: alot (the notmuch-based client) clones notmuch.git and builds it in CI, apparantly after giving up on a PR for the pypi notmuch2 project :| |
Hey,
|
I think we should aim for keeping the behavior as close as we can but upgrading the module, |
It is already 👍 |
Here are some contributions on the way to using notmuch2:
I based my work on @GuillaumeSeren `s branch and added my work on top, resulting in a passing test suite. The test suite does not cover all code paths. The last commit in this PR covers changes which are not caught by the suite, and I have not run this branch against my "real" mail database yet.
Also, I use a generator expression at some point, and this may fail on older python versions - I'm not sure which ones afew wants to support.
So, basically: do not merge yet ;)