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 ms0.migadu.com with LMTPS id cKI5BGS7eGE6NAAAgWs5BA (envelope-from ) for ; Wed, 27 Oct 2021 04:37:24 +0200 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 iG2DO2O7eGFBXgAAB5/wlQ (envelope-from ) for ; Wed, 27 Oct 2021 02:37:23 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A0DEE2A45F for ; Wed, 27 Oct 2021 04:37:23 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id DEBB31F57F; Tue, 26 Oct 2021 22:37:06 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 811811F574 for ; Tue, 26 Oct 2021 22:37:01 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 6ADD35FC42; Tue, 26 Oct 2021 22:37:01 -0400 (EDT) Received: (nullmailer pid 3535984 invoked by uid 1000); Wed, 27 Oct 2021 02:36:57 -0000 From: David Bremner To: David Bremner , notmuch@notmuchmail.org Subject: [PATCH 2/2] WIP/python2: switch to notmuch_database_{open,create}_with_config Date: Tue, 26 Oct 2021 23:36:53 -0300 Message-Id: <20211027023653.3535874-3-david@tethera.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211027023653.3535874-1-david@tethera.net> References: <20211026021131.3162922-1-david@tethera.net> <20211027023653.3535874-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: W6DZPIWDG6MMT637P5MSJCYO66G5M2V7 X-Message-ID-Hash: W6DZPIWDG6MMT637P5MSJCYO66G5M2V7 X-MailFrom: bremner@tethera.net 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; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1635302243; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=RVjU9Byy3/mBACnrpIG25eZbChRs6s3hceO/ca2B6xU=; b=qArQ/Y8U7s8MrMNet0qPzKpGVda1RiLTM9wUVKgg4nqLJScdQFnMNsJ2cZqYMBCT8M9PS7 qYAJTMwkliqmxjlJiC/ml2CBN+RphGHeYW3LW1XaYhaWbi0xVAJ6YIS4LXOdCrjaCBo75e /zXoBSs2pi+Qa9N9WccZudZo1TAptjiJeNOnhMoOXHSXfdsC2ncAsDc/N5epu17cOmMzKV xWqQ9RI80Zo5ItzpgCCbsVhpr36rL1cRWWHFQh/XsVHqE7m3OQKnuhk/u0BNyOi+Jqbtvk bAovhRuA5WvRkPAwsl87dmNHzxnEOsoRKyNqT8MuIWFQAVVYMGeo4eqEwczJag== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635302243; a=rsa-sha256; cv=none; b=ZCO23rc5s3C9KvOQvnJ13yqXIBH2MZ2pwFp3mIh+xsS5KI5JLooSTnMkDzeyhEguR7ZmWk 3HAjZn/mX2uwmFX9bfJ3zGCKNDtTeTtM/0q7s9U0KBwxPU70BXwQSPEwCNpvxtxjn9jxL8 wyLPyccG/AKm+D7Rk5OWJfwxRBApb1a43I63bFBqVEQU9JRCG0opso4MPFVpxzVO4gNX1i r8SsQA2RnqZZdzd+fi7E7x2LZy7AXAlhk/OX8w9B5TW3Nhmtl5TEtCI3cs7/SCa2yplFu5 lLf9aMPRaqWHX1hM6G88b3qfXBIDb2FsqIJ0XXmziiM8q3MPHcjUibCsGjZXnA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.14 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A0DEE2A45F X-Spam-Score: -1.14 X-Migadu-Scanner: scn0.migadu.com X-TUID: hFJT7NmJvjRb This fixes two deprecation warnings, and is a (partial?) fix for split configurations. The main changes to the tests are to force the pytest tests to ignore the configuration found via NOTMUCH_CONFIG. It is possible that there is a misfeature at the library level to be addressed, namely that an implicitely found configuration file should not override an explicitely passed database path. --- bindings/python-cffi/notmuch2/_build.py | 26 +++++++------- bindings/python-cffi/notmuch2/_database.py | 39 +++++++++++++-------- bindings/python-cffi/tests/test_database.py | 2 +- bindings/python-cffi/tests/test_message.py | 4 +-- bindings/python-cffi/tests/test_tags.py | 8 ++--- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/bindings/python-cffi/notmuch2/_build.py b/bindings/python-cffi/notmuch2/_build.py index 24df939e..f6184b97 100644 --- a/bindings/python-cffi/notmuch2/_build.py +++ b/bindings/python-cffi/notmuch2/_build.py @@ -103,20 +103,18 @@ ffibuilder.cdef( notmuch_status_to_string (notmuch_status_t status); notmuch_status_t - notmuch_database_create_verbose (const char *path, - notmuch_database_t **database, - char **error_message); - notmuch_status_t - notmuch_database_create (const char *path, notmuch_database_t **database); - notmuch_status_t - notmuch_database_open_verbose (const char *path, - notmuch_database_mode_t mode, - notmuch_database_t **database, - char **error_message); - notmuch_status_t - notmuch_database_open (const char *path, - notmuch_database_mode_t mode, - notmuch_database_t **database); + notmuch_database_create_with_config (const char *database_path, + const char *config_path, + const char *profile, + notmuch_database_t **database, + char **error_message); + notmuch_status_t + notmuch_database_open_with_config (const char *database_path, + notmuch_database_mode_t mode, + const char *config_path, + const char *profile, + notmuch_database_t **database, + char **error_message); notmuch_status_t notmuch_database_close (notmuch_database_t *database); notmuch_status_t diff --git a/bindings/python-cffi/notmuch2/_database.py b/bindings/python-cffi/notmuch2/_database.py index 868f4408..9f059652 100644 --- a/bindings/python-cffi/notmuch2/_database.py +++ b/bindings/python-cffi/notmuch2/_database.py @@ -109,18 +109,28 @@ class Database(base.NotmuchObject): 'rw': MODE.READ_WRITE, } - def __init__(self, path=None, mode=MODE.READ_ONLY): + @staticmethod + def _encode_for_open(path): + if path is None: + path = capi.ffi.NULL + elif not hasattr(os, 'PathLike') and isinstance(path, pathlib.Path): + path = bytes(path) + else: + path = os.fsencode(path) + return path + + def __init__(self, path=None, mode=MODE.READ_ONLY, cfg_path=None): if isinstance(mode, str): mode = self.STR_MODE_MAP[mode] self.mode = mode - if path is None: - path = self.default_path() - if not hasattr(os, 'PathLike') and isinstance(path, pathlib.Path): - path = bytes(path) + db_pp = capi.ffi.new('notmuch_database_t **') cmsg = capi.ffi.new('char**') - ret = capi.lib.notmuch_database_open_verbose(os.fsencode(path), - mode.value, db_pp, cmsg) + ret = capi.lib.notmuch_database_open_with_config(self._encode_for_open(path), + mode.value, + self._encode_for_open(cfg_path), + capi.ffi.NULL, + db_pp, cmsg) if cmsg[0]: msg = capi.ffi.string(cmsg[0]).decode(errors='replace') capi.lib.free(cmsg[0]) @@ -132,7 +142,7 @@ class Database(base.NotmuchObject): self.closed = False @classmethod - def create(cls, path=None): + def create(cls, path=None, cfg_path=None): """Create and open database in READ_WRITE mode. This is creates a new notmuch database and returns an opened @@ -154,14 +164,13 @@ class Database(base.NotmuchObject): :returns: The newly created instance. """ - if path is None: - path = cls.default_path() - if not hasattr(os, 'PathLike') and isinstance(path, pathlib.Path): - path = bytes(path) + db_pp = capi.ffi.new('notmuch_database_t **') cmsg = capi.ffi.new('char**') - ret = capi.lib.notmuch_database_create_verbose(os.fsencode(path), - db_pp, cmsg) + ret = capi.lib.notmuch_database_create_with_config(cls._encode_for_open(path), + cls._encode_for_open(cfg_path), + capi.ffi.NULL, + db_pp, cmsg) if cmsg[0]: msg = capi.ffi.string(cmsg[0]).decode(errors='replace') capi.lib.free(cmsg[0]) @@ -176,7 +185,7 @@ class Database(base.NotmuchObject): ret = capi.lib.notmuch_database_destroy(db_pp[0]) if ret != capi.lib.NOTMUCH_STATUS_SUCCESS: raise errors.NotmuchError(ret) - return cls(path, cls.MODE.READ_WRITE) + return cls(path, cls.MODE.READ_WRITE, cfg_path=cfg_path) @staticmethod def default_path(cfg_path=None): diff --git a/bindings/python-cffi/tests/test_database.py b/bindings/python-cffi/tests/test_database.py index 9b3219c0..136ab184 100644 --- a/bindings/python-cffi/tests/test_database.py +++ b/bindings/python-cffi/tests/test_database.py @@ -13,7 +13,7 @@ import notmuch2._message as message @pytest.fixture def db(maildir): - with dbmod.Database.create(maildir.path) as db: + with dbmod.Database.create(path=maildir.path, cfg_path="") as db: yield db diff --git a/bindings/python-cffi/tests/test_message.py b/bindings/python-cffi/tests/test_message.py index 532bf921..61658812 100644 --- a/bindings/python-cffi/tests/test_message.py +++ b/bindings/python-cffi/tests/test_message.py @@ -17,7 +17,7 @@ class TestMessage: @pytest.fixture def db(self, maildir): - with notmuch2.Database.create(maildir.path) as db: + with notmuch2.Database.create(maildir.path, cfg_path="") as db: yield db @pytest.fixture @@ -142,7 +142,7 @@ class TestProperties: @pytest.fixture def props(self, maildir): msgid, path = maildir.deliver() - with notmuch2.Database.create(maildir.path) as db: + with notmuch2.Database.create(maildir.path, cfg_path="") as db: msg, dup = db.add(path, sync_flags=False) yield msg.properties diff --git a/bindings/python-cffi/tests/test_tags.py b/bindings/python-cffi/tests/test_tags.py index faf3947b..feb20a0e 100644 --- a/bindings/python-cffi/tests/test_tags.py +++ b/bindings/python-cffi/tests/test_tags.py @@ -23,7 +23,7 @@ class TestImmutable: """ maildir.deliver() notmuch('new') - with database.Database(maildir.path) as db: + with database.Database(maildir.path, cfg_path="") as db: yield db.tags def test_type(self, tagset): @@ -159,7 +159,7 @@ class TestMutableTagset: _, pathname = maildir.deliver() notmuch('new') with database.Database(maildir.path, - mode=database.Mode.READ_WRITE) as db: + mode=database.Mode.READ_WRITE, cfg_path="") as db: msg = db.get(pathname) yield msg.tags @@ -195,7 +195,7 @@ class TestMutableTagset: _, pathname = maildir.deliver(flagged=True) notmuch('new') with database.Database(maildir.path, - mode=database.Mode.READ_WRITE) as db: + mode=database.Mode.READ_WRITE, cfg_path="") as db: msg = db.get(pathname) msg.tags.discard('flagged') msg.tags.from_maildir_flags() @@ -205,7 +205,7 @@ class TestMutableTagset: _, pathname = maildir.deliver(flagged=True) notmuch('new') with database.Database(maildir.path, - mode=database.Mode.READ_WRITE) as db: + mode=database.Mode.READ_WRITE, cfg_path="") as db: msg = db.get(pathname) flags = msg.path.name.split(',')[-1] assert 'F' in flags -- 2.33.0