Skip to content
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

Allow db_path to be set to ":memory:" #70

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions jupyter_server_fileid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
Loading