Skip to content

Settings in ~/.em_database + system-wide data resolution - #10

Merged
CSSFrancis merged 5 commits into
mainfrom
settings-and-shared-data
Aug 20, 2026
Merged

CSSFrancis merged 5 commits into
mainfrom
settings-and-shared-data

Conversation

@CSSFrancis

Copy link
Copy Markdown
Owner

Replaces the env-var-based data-dir config with a matplotlib-rcParams-style
settings object backed by a YAML file, and adds system-wide → per-user data
resolution.

Stacked on #8 (add-background-downloads-and-widget) — this branch builds
on that download refactor, so the diff below includes #8's commits until it
merges, after which it narrows to just the settings changes. Review/merge #8
first.

Settings (em_database.settings)

  • A live dict seeded at import from ~/.em_database/settings.yaml (relocate with
    EM_DATABASE_CONFIG). Mutate in memory for an immediate effect:
    em_database.settings["data_dir"] = "/big/disk"; settings.save() or
    set_data_dir(..., persist=True) persists across sessions.
  • No environment variable is needed. EM_DATABASE_DATA_DIR is still honored as a
    backward-compat seed.
  • save() writes only values that differ from the defaults, so a default
    (like the data dir) is never frozen into the file — it stays dynamic and keeps
    being obeyed across sessions/machines/default changes.
  • get_setting/set_setting for arbitrary keys; reset_data_dir() clears the
    saved choice.

System-wide vs per-user data

  • filepath() and download() search shared/system locations first, then the
    user's data dir
    , and only download (into the user dir) if the file is nowhere.
  • Shared locations: EM_DATABASE_SHARED_DIR (an os.pathsep list), a
    shared_data_dirs setting, or a system config file
    (/etc/em_database/settings.yaml or %PROGRAMDATA%\em_database\settings.yaml).
  • An admin can install datasets once, system-wide; every user finds them without
    re-downloading.

Colab

  • Auto-enables Colab's custom widget manager and broadens notebook detection, so
    browse(), display(ds), and download toasts work out of the box.

Misc

  • Drops the platformdirs dependency (uses ~/.em_database).

Tests

83 non-slow pass. Adds test_settings.py, test_shared_data.py, and a
conftest.py that isolates every test from the developer's real user/system
config.

- em_database.settings is a live, rcParams-style dict seeded at import from
  ~/.em_database/settings.yaml (override with EM_DATABASE_CONFIG). Mutate in
  memory for an immediate effect; settings.save() / set_data_dir(persist=True)
  persist across sessions. No env var is needed; EM_DATABASE_DATA_DIR is still
  honored as a backward-compat seed.
- save() writes only values that differ from the defaults, so a default (like
  the data dir) is never frozen into the file - it stays dynamic and obeyed.
- Data can be installed system-wide: filepath()/download() search shared
  locations first (EM_DATABASE_SHARED_DIR, a shared_data_dirs setting, or a
  system config at /etc/em_database or %PROGRAMDATA%), then the user's data
  dir, and only download (into the user dir) if it is nowhere to be found.
- Colab: auto-enable the custom widget manager and broaden notebook detection
  so browse()/display()/toasts work out of the box.
- Tests isolate the user + system config; add test_settings and test_shared_data.
Update the README and the changing_download_location example to use
em_database.settings (matplotlib rcParams-style, ~/.em_database/settings.yaml),
the persist/session-only set_data_dir, generic get_setting/set_setting, and the
system-wide shared-data locations. The example resets settings at the end so it
leaves nothing behind when run by the docs gallery.
display(em_database.settings) (or em_database.settings.widget()) now renders an
anywidget panel to set the data directory directly - Save (persist), Use for
session (in-memory), or Reset - and shows the settings-file path and the
shared-then-user search order. Falls back to the dict repr without anywidget.
Pick a folder with a hidden webkitdirectory <input> in the browser and fill the
path field client-side (deriving the absolute path from File.path where the
environment exposes it, e.g. desktop/Electron), then Save. No kernel-side dialog.
The webkitdirectory input made the browser show an "upload" dialog. Use a plain
file <input> instead (a normal "Open" dialog) and take the selected file's
parent as the directory. Move the Browse button onto the directory line, to the
right of the path field.
@CSSFrancis
CSSFrancis merged commit 1ad4b82 into main Aug 20, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant