| 27 | |
| 28 | |
| 29 | class DocumentationProvider: |
| 30 | def __init__(self, is_async: bool) -> None: |
| 31 | self.is_async = is_async |
| 32 | self.api: Any = {} |
| 33 | self.links: Dict[str, str] = {} |
| 34 | self.printed_entries: List[str] = [] |
| 35 | api_json_path = os.environ.get("PW_API_JSON") |
| 36 | if not api_json_path: |
| 37 | raise RuntimeError( |
| 38 | "PW_API_JSON must point to a Playwright api.json file. Run codegen " |
| 39 | "via ./scripts/update_api.sh, which generates api.json from a " |
| 40 | "microsoft/playwright checkout (PW_SRC_DIR)." |
| 41 | ) |
| 42 | self.api = json.loads(pathlib.Path(api_json_path).read_text(encoding="utf-8")) |
| 43 | self.errors: Set[str] = set() |
| 44 | self.class_aliases: Dict[str, str] = { |
| 45 | "Disposable": "AsyncContextManager" if is_async else "SyncContextManager", |
| 46 | "DisposableStub": ( |
| 47 | "AsyncContextManager" if is_async else "SyncContextManager" |
| 48 | ), |
| 49 | } |
| 50 | self._patch_case() |
| 51 | |
| 52 | def _patch_case(self) -> None: |
| 53 | self.classes = {} |
| 54 | for clazz in self.api: |
| 55 | if not works_for_python(clazz) and clazz["name"] not in self.class_aliases: |
| 56 | continue |
| 57 | members = {} |
| 58 | self.classes[clazz["name"]] = clazz |
| 59 | events = [] |
| 60 | for member in clazz["members"]: |
| 61 | if not works_for_python(member): |
| 62 | continue |
| 63 | member_name = member["name"] |
| 64 | new_name = name_or_alias(member) |
| 65 | self._add_link(member["kind"], clazz["name"], member_name, new_name) |
| 66 | |
| 67 | if member["kind"] == "event": |
| 68 | events.append(member) |
| 69 | else: |
| 70 | new_name = to_snake_case(new_name) |
| 71 | member["name"] = new_name |
| 72 | members[new_name] = member |
| 73 | apply_type_or_override(member) |
| 74 | |
| 75 | if "args" in member: |
| 76 | args = {} |
| 77 | for arg in member["args"]: |
| 78 | if not works_for_python(arg): |
| 79 | continue |
| 80 | if arg["name"] == "options": |
| 81 | for option in arg["type"]["properties"]: |
| 82 | if not works_for_python(option): |
| 83 | continue |
| 84 | option = self_or_override(option) |
| 85 | option_name = to_snake_case(name_or_alias(option)) |
| 86 | option["name"] = option_name |
no outgoing calls
no test coverage detected