Best-effort retrieval of Fabric runtime metadata.
Source code in src/fabricops_kit/config.py
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825 | def _get_fabric_runtime_metadata(notebook_name: str | None = None) -> dict[str, Any]:
"""Best-effort retrieval of Fabric runtime metadata."""
metadata: dict[str, Any] = {
"notebook_name": notebook_name,
"workspace_name": None,
"user_name": None,
"runtime_available": False,
}
try:
import notebookutils.runtime as nb_runtime # type: ignore
metadata["runtime_available"] = True
context = getattr(nb_runtime, "context", None)
if context is not None:
def _ctx_value(*keys: str) -> Any:
for key in keys:
if hasattr(context, key):
value = getattr(context, key, None)
if value is not None:
return value
if isinstance(context, dict):
value = context.get(key)
if value is not None:
return value
get_method = getattr(context, "get", None)
if callable(get_method):
value = get_method(key)
if value is not None:
return value
return None
metadata["notebook_name"] = metadata["notebook_name"] or _ctx_value("currentNotebookName", "current_notebook_name")
metadata["workspace_name"] = _ctx_value("currentWorkspaceName", "workspaceName", "workspace_name")
metadata["user_name"] = _ctx_value("userName", "user_name")
except Exception:
pass
return metadata
|