Source code for bumps.persistent_settings

"""
Persist settings to disk.

Settings are stored in .venv/etc/bumps/KEY

As of this writing, only `base_path` is saved.
"""

import sys
from pathlib import Path
from typing import Optional

ETC_PATH = Path(sys.prefix, "etc")
DEFAULT_APPLICATION = "bumps"


[docs] def set_value(key: str, value: str, application: str = DEFAULT_APPLICATION): settings_path = ETC_PATH / application / key try: settings_path.parent.mkdir(parents=True, exist_ok=True) with open(settings_path, "w") as f: f.write(value) return True except Exception as e: return False
[docs] def get_value(key: str, default_value: Optional[str] = None, application: str = DEFAULT_APPLICATION): settings_path = ETC_PATH / application / key try: with open(settings_path, "r") as f: return f.read() except Exception as e: return default_value