Skip to content
Merged
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
23 changes: 17 additions & 6 deletions scripts/research_community_edison.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from typing import Any

import yaml
from dotenv import load_dotenv
from dotenv import dotenv_values, load_dotenv

REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
Expand Down Expand Up @@ -88,13 +88,24 @@ def resolve_job(name: str):


def load_api_key() -> str:
"""Pick up the Edison key from env (with the legacy alias).

The SDK natively reads ``EDISON_PLATFORM_API_KEY``; this repo's
``.env`` sets ``EDISON_API_KEY``. Honor both.
"""Pick up the Edison key, treating the repo ``.env`` as the source of truth.

The SDK natively reads ``EDISON_PLATFORM_API_KEY``; this repo's ``.env`` sets
``EDISON_API_KEY``. Honor both — but prefer whatever the ``.env`` FILE
provides over an ambient/inherited ``EDISON_PLATFORM_API_KEY``. A stale
exported ``EDISON_PLATFORM_API_KEY`` (e.g. left in a terminal session) would
otherwise silently shadow a freshly-updated ``.env`` key, because
``load_dotenv`` does not override already-exported vars — a 403-at-login
footgun. Ambient env is used only when ``.env`` supplies no key.
"""
load_dotenv(REPO_ROOT / ".env")
key = os.environ.get("EDISON_PLATFORM_API_KEY") or os.environ.get("EDISON_API_KEY")
file_vals = dotenv_values(REPO_ROOT / ".env")
key = (
file_vals.get("EDISON_PLATFORM_API_KEY")
or file_vals.get("EDISON_API_KEY")
Comment on lines 101 to +105
or os.environ.get("EDISON_PLATFORM_API_KEY")
or os.environ.get("EDISON_API_KEY")
)
if not key:
raise SystemExit(
"EDISON_PLATFORM_API_KEY (or EDISON_API_KEY) is not set. "
Expand Down
Loading