Skip to content
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
8 changes: 6 additions & 2 deletions examples/em_deposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -60,6 +62,8 @@ def print_report(label: str, report: dsp.CheckReport) -> None:


def main() -> None:
config = DepositConfig.load()

# ── 0. Validate configuration ─────────────────────────────────────────────
_unset = [
name
Expand All @@ -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 ─────────────────────
Expand All @@ -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:
Expand Down
17 changes: 11 additions & 6 deletions examples/xray_deposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
from rich.panel import Panel
from rich.text import Text

from onedep_lib.config import DepositConfig

logging.disable(logging.ERROR)

_console = Console(stderr=True)

# ── 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:
Expand All @@ -53,6 +55,8 @@ def print_report(label: str, report: dsp.CheckReport) -> None:


def main() -> None:
config = DepositConfig.load()

# ── 0. Validate configuration ─────────────────────────────────────────────
_unset = [
name
Expand All @@ -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 ────────────────────────────────────────────
Expand All @@ -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:
Expand Down Expand Up @@ -162,3 +166,4 @@ def main() -> None:

if __name__ == "__main__":
main()

10 changes: 3 additions & 7 deletions src/onedep_lib/dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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
Expand Down
Loading