Skip to content

Commit 0bfd972

Browse files
guidooswaldDBclaude
andcommitted
Add PEP 257 Google-style docstrings (Sphinx/Napoleon) across all modules
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 30839ed commit 0bfd972

4 files changed

Lines changed: 512 additions & 68 deletions

File tree

api_catalog.py

Lines changed: 106 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,56 @@
1+
"""Databricks Workspace API Catalog.
2+
3+
Declarative registry of every Databricks REST API endpoint exposed by
4+
the explorer UI, organised by category. The two main data structures
5+
are:
6+
7+
* :data:`API_CATALOG` -- nested dict of categories → endpoint
8+
definitions.
9+
* :data:`LIST_TO_GET` -- mapping that drives inline navigation from
10+
list responses to their corresponding *get* endpoints.
11+
12+
Attributes:
13+
API_CATALOG: Master endpoint registry keyed by category name.
14+
LIST_TO_GET: Mapping of list-endpoint IDs to get-endpoint metadata.
15+
ENDPOINT_MAP: Flat map of *all* endpoints keyed by their string ID.
16+
TOTAL_ENDPOINTS: Total number of registered endpoints.
17+
TOTAL_CATEGORIES: Total number of API categories.
118
"""
2-
Databricks Workspace API Catalog
3-
Complete catalog of all major Databricks workspace REST APIs.
4-
"""
5-
from typing import Dict, Any, List
619

7-
STR = "string"
8-
INT = "integer"
9-
BOOL = "boolean"
20+
from typing import Any, Dict, List, Optional
21+
22+
STR: str = "string"
23+
INT: str = "integer"
24+
BOOL: str = "boolean"
1025

1126

12-
def _p(name: str, desc: str, required: bool = False, type_: str = STR, default: str = "") -> Dict:
13-
return {"name": name, "description": desc, "required": required, "type": type_, "default": default}
27+
def _p(
28+
name: str,
29+
desc: str,
30+
required: bool = False,
31+
type_: str = STR,
32+
default: str = "",
33+
) -> Dict[str, Any]:
34+
"""Build a parameter definition dict for an endpoint.
35+
36+
Args:
37+
name: Parameter name as expected by the Databricks REST API.
38+
desc: Human-readable description shown in the UI.
39+
required: Whether the parameter is mandatory.
40+
type_: Data type hint (``"string"``, ``"integer"``, or
41+
``"boolean"``).
42+
default: Default value pre-filled in the input field.
43+
44+
Returns:
45+
A parameter dict consumable by :func:`app.build_param_form`.
46+
"""
47+
return {
48+
"name": name,
49+
"description": desc,
50+
"required": required,
51+
"type": type_,
52+
"default": default,
53+
}
1454

1555

1656
API_CATALOG: Dict[str, Any] = {
@@ -620,17 +660,48 @@ def _p(name: str, desc: str, required: bool = False, type_: str = STR, default:
620660
}
621661

622662

623-
def _nested_get(obj: Dict, dotted_key: str):
624-
"""Get a value from a dict using a dotted key like 'settings.name'."""
663+
def _nested_get(obj: Dict, dotted_key: str) -> Any:
664+
"""Retrieve a value from a nested dict using a dotted key path.
665+
666+
Args:
667+
obj: The root dictionary.
668+
dotted_key: Dot-separated key path (e.g. ``"settings.name"``).
669+
670+
Returns:
671+
The resolved value, or ``None`` if any segment is missing.
672+
"""
625673
for part in dotted_key.split("."):
626674
if not isinstance(obj, dict):
627675
return None
628676
obj = obj.get(part)
629677
return obj
630678

631679

632-
def extract_chips(endpoint_id: str, data: Any) -> List[Dict]:
633-
"""Extract clickable ID chips from a list API response."""
680+
def extract_chips(endpoint_id: str, data: Any) -> List[Dict[str, Any]]:
681+
"""Extract clickable ID chip descriptors from a list API response.
682+
683+
Chips power the inline navigation links and side-panel items that
684+
let users jump from a list response to the corresponding *get*
685+
endpoint for each row.
686+
687+
Args:
688+
endpoint_id: The ``id`` of the list endpoint whose response is
689+
being processed (must be a key in :data:`LIST_TO_GET`).
690+
data: The parsed JSON response body (typically a ``dict`` with
691+
a top-level array key).
692+
693+
Returns:
694+
A list of chip dicts, each containing:
695+
696+
* ``get_id`` -- target *get* endpoint ID.
697+
* ``param`` -- query/path parameter name for the get call.
698+
* ``id_field`` -- JSON key that holds the identifier.
699+
* ``value`` -- the identifier value (stringified).
700+
* ``label`` -- short display label (max 60 chars).
701+
* ``title`` -- tooltip text (typically the raw ID).
702+
* ``extras`` -- additional params to pass along.
703+
* ``actions`` -- list of secondary action dicts.
704+
"""
634705
mapping = LIST_TO_GET.get(endpoint_id)
635706
if not mapping:
636707
return []
@@ -679,17 +750,35 @@ def extract_chips(endpoint_id: str, data: Any) -> List[Dict]:
679750
return chips
680751

681752

682-
def get_endpoint_by_id(endpoint_id: str) -> Dict[str, Any]:
683-
"""Find an endpoint by its ID across all categories."""
753+
def get_endpoint_by_id(endpoint_id: str) -> Optional[Dict[str, Any]]:
754+
"""Find an endpoint definition by its unique string ID.
755+
756+
Searches every category in :data:`API_CATALOG`.
757+
758+
Args:
759+
endpoint_id: The endpoint ``id`` to look up (e.g.
760+
``"clusters-list"``).
761+
762+
Returns:
763+
A copy of the endpoint dict enriched with ``category`` and
764+
``category_color`` keys, or ``None`` if not found.
765+
"""
684766
for category_name, category in API_CATALOG.items():
685767
for endpoint in category["endpoints"]:
686768
if endpoint["id"] == endpoint_id:
687769
return {**endpoint, "category": category_name, "category_color": category["color"]}
688770
return None
689771

690772

691-
def build_endpoint_map() -> Dict[str, Dict]:
692-
"""Build a flat map of all endpoints keyed by ID."""
773+
def build_endpoint_map() -> Dict[str, Dict[str, Any]]:
774+
"""Build a flat lookup of all endpoints keyed by their string ID.
775+
776+
Each value is an endpoint dict augmented with ``category`` and
777+
``category_color``.
778+
779+
Returns:
780+
A ``{endpoint_id: endpoint_dict}`` mapping.
781+
"""
693782
return {
694783
endpoint["id"]: {**endpoint, "category": cat_name, "category_color": cat["color"]}
695784
for cat_name, cat in API_CATALOG.items()

0 commit comments

Comments
 (0)