From d01c01a2f0b4e93eaba08276401658d619c3d12c Mon Sep 17 00:00:00 2001 From: Weslley Morellato Bueno Date: Wed, 1 Jul 2026 16:26:21 +0100 Subject: [PATCH 1/3] Requiring DepositConfig to be instantiated by caller --- examples/em_deposition.py | 8 ++++++-- examples/xray_deposition.py | 32 +++++++++++++++++++++++++------- src/onedep_lib/dsp.py | 10 +++------- 3 files changed, 34 insertions(+), 16 deletions(-) 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..f8fbeec 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,20 @@ # ── 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 "wbueno@ebi.ac.uk" +USERS = os.getenv("WWPDB_USERS") and os.getenv("WWPDB_USERS").split(",") or ["0000-0001-6872-1814"] +COORD_FILE = os.getenv("WWPDB_COORD_FILE") or "/home/wbueno/repos/test_files/xray/2gc2.cif" +SF_FILE = os.getenv("WWPDB_SF_FILE") or "/home/wbueno/repos/test_files/xray/2gc2-sf.cif" + +def _check_config_obj(): + import gc + from onedep_lib.dsp import DepositConfig # adjust class + + instances = [obj for obj in gc.get_objects() if isinstance(obj, DepositConfig)] + + print(len(instances)) + for obj in instances: + print(id(obj), getattr(obj, "refresh_token", None)) def ok(msg: str) -> None: @@ -53,6 +65,8 @@ def print_report(label: str, report: dsp.CheckReport) -> None: def main() -> None: + config = DepositConfig.load() + # ── 0. Validate configuration ───────────────────────────────────────────── _unset = [ name @@ -74,7 +88,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 +98,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: @@ -161,4 +175,8 @@ def main() -> None: if __name__ == "__main__": - main() + try: + main() + except Exception as exc: + _check_config_obj() + 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 From 2fdefd47ca7bf83a65bdbf1175892bf703d39804 Mon Sep 17 00:00:00 2001 From: Weslley Morellato Bueno Date: Wed, 1 Jul 2026 16:28:37 +0100 Subject: [PATCH 2/3] Restored default values --- examples/xray_deposition.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/xray_deposition.py b/examples/xray_deposition.py index f8fbeec..7324778 100644 --- a/examples/xray_deposition.py +++ b/examples/xray_deposition.py @@ -31,10 +31,10 @@ # ── Configuration ───────────────────────────────────────────────────────────── # Change all values marked with <<<< CHANGE THIS before running. -EMAIL = os.getenv("WWPDB_EMAIL") or "wbueno@ebi.ac.uk" -USERS = os.getenv("WWPDB_USERS") and os.getenv("WWPDB_USERS").split(",") or ["0000-0001-6872-1814"] -COORD_FILE = os.getenv("WWPDB_COORD_FILE") or "/home/wbueno/repos/test_files/xray/2gc2.cif" -SF_FILE = os.getenv("WWPDB_SF_FILE") or "/home/wbueno/repos/test_files/xray/2gc2-sf.cif" +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 _check_config_obj(): import gc From 561d4022e4763d3f60981a7208eb9c83a7e51b2f Mon Sep 17 00:00:00 2001 From: Weslley Morellato Bueno Date: Wed, 1 Jul 2026 16:29:57 +0100 Subject: [PATCH 3/3] Removed debug code --- examples/xray_deposition.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/examples/xray_deposition.py b/examples/xray_deposition.py index 7324778..8437042 100644 --- a/examples/xray_deposition.py +++ b/examples/xray_deposition.py @@ -36,16 +36,6 @@ 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 _check_config_obj(): - import gc - from onedep_lib.dsp import DepositConfig # adjust class - - instances = [obj for obj in gc.get_objects() if isinstance(obj, DepositConfig)] - - print(len(instances)) - for obj in instances: - print(id(obj), getattr(obj, "refresh_token", None)) - def ok(msg: str) -> None: _console.print(f"[bold green]✓[/bold green] {msg}") @@ -175,8 +165,5 @@ def main() -> None: if __name__ == "__main__": - try: - main() - except Exception as exc: - _check_config_obj() + main()