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 _______________________________________________ notmuch mailing list -- notmuch@notmuchmail.org To unsubscribe send an email to notmuch-le...@notmuchmail.org