diff --git a/examples/em_deposition.py b/examples/em_deposition.py index 46c14b7..c434269 100644 --- a/examples/em_deposition.py +++ b/examples/em_deposition.py @@ -22,6 +22,8 @@ from rich.panel import Panel from rich.text import Text +from onedep_lib.config import DepositConfig + logging.disable(logging.ERROR) _console = Console(stderr=True) @@ -60,6 +62,8 @@ def print_report(label: str, report: dsp.CheckReport) -> None: def main() -> None: + config = DepositConfig.load() + # ── 0. Validate configuration ───────────────────────────────────────────── _unset = [ name @@ -80,7 +84,7 @@ def main() -> None: with _console.status("[cyan]Initializing deposit…[/cyan]", spinner="dots") as spin: # ── 1. Initialization ──────────────────────────────────────────────── - dep = dsp.deposit_init(email=EMAIL, users=USERS, country=dsp.Country.USA) + dep = dsp.deposit_init(email=EMAIL, users=USERS, country=dsp.Country.USA, config=config) ok(f"Deposit initialized session_id={dep.session_id}") # ── 2. Set experiment type and EM-specific params ───────────────────── @@ -91,7 +95,7 @@ def main() -> None: # ── 3. Check auth key ───────────────────────────────────────────────── spin.update("[cyan]Checking auth key…[/cyan]") - auth_ok = dsp.check_auth_key() + auth_ok = dsp.check_auth_key(config=config) if auth_ok: ok("Auth key valid") else: diff --git a/examples/xray_deposition.py b/examples/xray_deposition.py index e949cdc..8437042 100644 --- a/examples/xray_deposition.py +++ b/examples/xray_deposition.py @@ -22,6 +22,8 @@ from rich.panel import Panel from rich.text import Text +from onedep_lib.config import DepositConfig + logging.disable(logging.ERROR) _console = Console(stderr=True) @@ -29,10 +31,10 @@ # ── Configuration ───────────────────────────────────────────────────────────── # Change all values marked with <<<< CHANGE THIS before running. -EMAIL = os.getenv("WWPDB_EMAIL") or "your.email@example.com" # <<<< CHANGE THIS -USERS = os.getenv("WWPDB_USERS") and os.getenv("WWPDB_USERS").split(",") or ["0000-0000-0000-0000"] # <<<< CHANGE THIS (ORCID iD) -COORD_FILE = os.getenv("WWPDB_COORD_FILE") or "/path/to/your/coord.cif" # <<<< CHANGE THIS -SF_FILE = os.getenv("WWPDB_SF_FILE") or "/path/to/your/sf.cif" # <<<< CHANGE THIS +EMAIL = os.getenv("WWPDB_EMAIL") or "your.email@example.com" +USERS = os.getenv("WWPDB_USERS") and os.getenv("WWPDB_USERS").split(",") or ["0000-0000-0000-0000"] +COORD_FILE = os.getenv("WWPDB_COORD_FILE") or "/path/to/your/coord.cif" +SF_FILE = os.getenv("WWPDB_SF_FILE") or "/path/to/your/sf.cif" def ok(msg: str) -> None: @@ -53,6 +55,8 @@ def print_report(label: str, report: dsp.CheckReport) -> None: def main() -> None: + config = DepositConfig.load() + # ── 0. Validate configuration ───────────────────────────────────────────── _unset = [ name @@ -74,7 +78,7 @@ def main() -> None: with _console.status("[cyan]Initializing deposit…[/cyan]", spinner="dots") as spin: # ── 1. Initialization ──────────────────────────────────────────────── - dep = dsp.deposit_init(email=EMAIL, users=USERS, country=dsp.Country.USA) + dep = dsp.deposit_init(email=EMAIL, users=USERS, country=dsp.Country.USA, config=config) ok(f"Deposit initialized session_id={dep.session_id}") # ── 2. Set experiment type ──────────────────────────────────────────── @@ -84,7 +88,7 @@ def main() -> None: # ── 3. Check auth key ───────────────────────────────────────────────── spin.update("[cyan]Checking auth key…[/cyan]") - auth_ok = dsp.check_auth_key() + auth_ok = dsp.check_auth_key(config=config) if auth_ok: ok("Auth key valid") else: @@ -162,3 +166,4 @@ def main() -> None: if __name__ == "__main__": main() + diff --git a/src/onedep_lib/dsp.py b/src/onedep_lib/dsp.py index 00e8580..e385bb1 100644 --- a/src/onedep_lib/dsp.py +++ b/src/onedep_lib/dsp.py @@ -58,10 +58,8 @@ def list_sessions(base_dir: Path | None = None) -> list[tuple[LocalSession, list return results -def check_auth_key(config: DepositConfig = None) -> bool: +def check_auth_key(config: DepositConfig) -> bool: """Return True if the configured credentials are valid, False otherwise.""" - config = config or DepositConfig.load() - try: api_client = HttpApiClient(config, auth_provider=TokenStore(config)) api_client.get_all_depositions() @@ -74,10 +72,10 @@ def deposit_init( email: str, users: list[str], country: Country, + config: DepositConfig, experiment_type: ExperimentType | None = None, em_subtype: EMSubType | None = None, coordinates: bool | None = None, - config: DepositConfig | None = None, _base_dir: Path | None = None, _api_client: ApiClient | None = None, _check_runner: CheckRunnerProtocol | None = None, @@ -99,7 +97,6 @@ def deposit_init( Returns: A Deposition object representing the local session. """ - config = config or DepositConfig.load() session_id = str(uuid.uuid4()) base_dir = _base_dir or config.session_dir store: SessionStore = JsonSessionStore(session_id, base_dir=base_dir) @@ -125,7 +122,7 @@ def deposit_init( def deposit_resume( session_id: str, - config: DepositConfig | None = None, + config: DepositConfig, _base_dir: Path | None = None, _api_client: ApiClient | None = None, _check_runner: CheckRunnerProtocol | None = None, @@ -145,7 +142,6 @@ def deposit_resume( Raises: KeyError: If no session with the given session_id exists. """ - config = config or DepositConfig.load() base_dir = _base_dir or config.session_dir store: SessionStore = JsonSessionStore(session_id, base_dir=base_dir) store.get_session() # raises KeyError if not found