diff --git a/jupyter_server_fileid/manager.py b/jupyter_server_fileid/manager.py index 4343432..549528b 100644 --- a/jupyter_server_fileid/manager.py +++ b/jupyter_server_fileid/manager.py @@ -61,19 +61,20 @@ class BaseFileIdManager(ABC, LoggingConfigurable, metaclass=FileIdManagerMeta): help=( "The path of the DB file used by File ID manager implementations. " "Defaults to `jupyter_data_dir()/file_id_manager.db`." + "You can set it to ':memory:' to disable sqlite writing to the filesystem." ), config=True, ) @validate("db_path") def _validate_db_path(self, proposal): - if proposal["value"] is None: - raise TraitError(f"BaseFileIdManager : {proposal['trait'].name} must not be None") - if not os.path.isabs(proposal["value"]): - raise TraitError( - f"BaseFileIdManager : {proposal['trait'].name} must be an absolute path" - ) - return proposal["value"] + db_path = proposal["value"] + if db_path == ":memory:" or os.path.isabs(db_path): + return db_path + + raise TraitError( + f"BaseFileIdManager : {proposal['trait'].name} must be an absolute path or \":memory:\"" + ) JOURNAL_MODES = ["DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF"] db_journal_mode = Unicode( diff --git a/tests/test_manager.py b/tests/test_manager.py index f6e1606..9524d5c 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -148,6 +148,10 @@ def test_validates_db_path(jp_root_dir, any_fid_manager_class): ) +def test_memory_db_path(jp_root_dir, any_fid_manager_class): + any_fid_manager_class(root_dir=str(jp_root_dir), db_path=":memory:") + + def test_different_roots( any_fid_manager_class, fid_db_path, jp_root_dir, test_path, test_path_child ):