|
| 1 | +import json |
| 2 | +from dataclasses import asdict, dataclass |
| 3 | +from typing import Literal, TypedDict |
| 4 | + |
| 5 | + |
| 6 | +@dataclass |
| 7 | +class QuartodocObject: |
| 8 | + project: str |
| 9 | + version: str |
| 10 | + count: int |
| 11 | + items: list["QuartodocObjectItem"] |
| 12 | + |
| 13 | + |
| 14 | +@dataclass |
| 15 | +class QuartodocObjectItem: |
| 16 | + name: str |
| 17 | + domain: str |
| 18 | + |
| 19 | + # function: "shiny.ui.page_sidebar" |
| 20 | + # class: "shiny.render.renderer._renderer.Renderer" |
| 21 | + # attribute: "shiny.render.renderer._renderer.Renderer.output_id" |
| 22 | + role: Literal["function", "class", "attribute", "module"] |
| 23 | + priority: str |
| 24 | + uri: str |
| 25 | + dispname: str |
| 26 | + |
| 27 | + |
| 28 | +def read_objects_file(path: str) -> QuartodocObject: |
| 29 | + with open(path) as file: |
| 30 | + content = json.load(file) |
| 31 | + items = [QuartodocObjectItem(**item) for item in content.pop("items")] |
| 32 | + return QuartodocObject(**content, items=items) |
| 33 | + |
| 34 | + |
| 35 | +def write_objects_file(objects: QuartodocObject, path: str) -> None: |
| 36 | + with open(path, "w") as file: |
| 37 | + json.dump(objects, file, indent=4, default=lambda dc: dc.__dict__) |
| 38 | + |
| 39 | + |
| 40 | +print("\nCombinging objects json files...") |
| 41 | +objects_core = read_objects_file("_objects_core.json") |
| 42 | +objects_express = read_objects_file("_objects_express.json") |
| 43 | + |
| 44 | +items_map: dict[str, QuartodocObjectItem] = {} |
| 45 | + |
| 46 | +for item in [*objects_core.items, *objects_express.items]: |
| 47 | + if item.name in items_map: |
| 48 | + continue |
| 49 | + items_map[item.name] = item |
| 50 | + |
| 51 | +objects_ret = QuartodocObject( |
| 52 | + project="shiny", |
| 53 | + version="1", |
| 54 | + count=len(items_map.values()), |
| 55 | + items=[*items_map.values()], |
| 56 | +) |
| 57 | + |
| 58 | + |
| 59 | +print("Core:", objects_core.count) |
| 60 | +print("Express:", objects_express.count) |
| 61 | +print("Combined:", objects_ret.count) |
| 62 | + |
| 63 | +# Save combined objects file info |
| 64 | +write_objects_file(objects_ret, "objects.json") |
0 commit comments