Skip to content

Commit ffd3148

Browse files
authored
Allow db_path to be set to ":memory:" (#70)
1 parent e668814 commit ffd3148

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

jupyter_server_fileid/manager.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,20 @@ class BaseFileIdManager(ABC, LoggingConfigurable, metaclass=FileIdManagerMeta):
6161
help=(
6262
"The path of the DB file used by File ID manager implementations. "
6363
"Defaults to `jupyter_data_dir()/file_id_manager.db`."
64+
"You can set it to ':memory:' to disable sqlite writing to the filesystem."
6465
),
6566
config=True,
6667
)
6768

6869
@validate("db_path")
6970
def _validate_db_path(self, proposal):
70-
if proposal["value"] is None:
71-
raise TraitError(f"BaseFileIdManager : {proposal['trait'].name} must not be None")
72-
if not os.path.isabs(proposal["value"]):
73-
raise TraitError(
74-
f"BaseFileIdManager : {proposal['trait'].name} must be an absolute path"
75-
)
76-
return proposal["value"]
71+
db_path = proposal["value"]
72+
if db_path == ":memory:" or os.path.isabs(db_path):
73+
return db_path
74+
75+
raise TraitError(
76+
f"BaseFileIdManager : {proposal['trait'].name} must be an absolute path or \":memory:\""
77+
)
7778

7879
JOURNAL_MODES = ["DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF"]
7980
db_journal_mode = Unicode(

tests/test_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ def test_validates_db_path(jp_root_dir, any_fid_manager_class):
148148
)
149149

150150

151+
def test_memory_db_path(jp_root_dir, any_fid_manager_class):
152+
any_fid_manager_class(root_dir=str(jp_root_dir), db_path=":memory:")
153+
154+
151155
def test_different_roots(
152156
any_fid_manager_class, fid_db_path, jp_root_dir, test_path, test_path_child
153157
):

0 commit comments

Comments
 (0)