Add shared Jupyter defaults for model training lite
This commit is contained in:
@@ -138,6 +138,17 @@ def clean(value: Any) -> str:
|
||||
|
||||
def load_local_defaults() -> dict[str, Any]:
|
||||
defaults: dict[str, Any] = {}
|
||||
skill_dir = Path(__file__).resolve().parents[1]
|
||||
shared_config_path = skill_dir / "jupyter_defaults.json"
|
||||
if shared_config_path.exists():
|
||||
try:
|
||||
shared_defaults = json.loads(shared_config_path.read_text(encoding="utf-8"))
|
||||
if isinstance(shared_defaults, dict):
|
||||
defaults.update({key: value for key, value in shared_defaults.items() if value})
|
||||
if any(clean(shared_defaults.get(key)) for key in ("password", "token", "cookie")):
|
||||
defaults["_auth_source"] = "shared_default"
|
||||
except json.JSONDecodeError as exc:
|
||||
raise SystemExit(f"invalid shared defaults JSON: {shared_config_path}: {exc}") from exc
|
||||
env_defaults = {
|
||||
"jupyter_url": os.environ.get("MODEL_TRAINING_LITE_JUPYTER_URL"),
|
||||
"password": os.environ.get("MODEL_TRAINING_LITE_JUPYTER_PASSWORD"),
|
||||
@@ -146,12 +157,16 @@ def load_local_defaults() -> dict[str, Any]:
|
||||
"auth_type": os.environ.get("MODEL_TRAINING_LITE_JUPYTER_AUTH_TYPE"),
|
||||
}
|
||||
defaults.update({key: value for key, value in env_defaults.items() if value})
|
||||
config_path = Path(__file__).resolve().parents[1] / ".local" / "jupyter_defaults.json"
|
||||
if any(clean(env_defaults.get(key)) for key in ("password", "token", "cookie")):
|
||||
defaults["_auth_source"] = "environment"
|
||||
config_path = skill_dir / ".local" / "jupyter_defaults.json"
|
||||
if config_path.exists():
|
||||
try:
|
||||
file_defaults = json.loads(config_path.read_text(encoding="utf-8"))
|
||||
if isinstance(file_defaults, dict):
|
||||
defaults.update({key: value for key, value in file_defaults.items() if value})
|
||||
if any(clean(file_defaults.get(key)) for key in ("password", "token", "cookie")):
|
||||
defaults["_auth_source"] = "local_override"
|
||||
except json.JSONDecodeError as exc:
|
||||
raise SystemExit(f"invalid local defaults JSON: {config_path}: {exc}") from exc
|
||||
return defaults
|
||||
@@ -161,7 +176,7 @@ def auth_source(payload: dict[str, Any], defaults: dict[str, Any]) -> str:
|
||||
if any(clean(payload.get(key)) for key in ("jupyter_password", "password", "jupyter_token", "token", "jupyter_cookie")):
|
||||
return "input"
|
||||
if any(clean(defaults.get(key)) for key in ("password", "token", "cookie")):
|
||||
return "local_default"
|
||||
return clean(defaults.get("_auth_source")) or "default"
|
||||
return ""
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user