|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -import ast |
| 3 | +import importlib |
4 | 4 | from pathlib import Path
|
5 | 5 | from typing import Set
|
6 | 6 |
|
|
11 | 11 |
|
12 | 12 | CONTROLLER_DIR = root / "shiny/playwright/controller"
|
13 | 13 | DOCS_CONFIG = root / "docs/_quartodoc-testing.yml"
|
14 |
| -SKIP_PATTERNS = {"Base", "Container", "Label", "StyleM"} |
15 |
| -CONTROLLER_BASE_PATTERNS = { |
16 |
| - "Base", |
17 |
| - "Container", |
18 |
| - "Label", |
19 |
| - "StyleM", |
20 |
| - "WidthLocM", |
21 |
| - "InputActionButton", |
22 |
| - "UiBase", |
23 |
| - "UiWithLabel", |
24 |
| - "UiWithContainer", |
25 |
| -} |
26 |
| - |
27 |
| - |
28 |
| -def _is_valid_controller_class(node: ast.ClassDef) -> bool: |
29 |
| - class_name = node.name |
30 |
| - base_names = {ast.unparse(base) for base in node.bases} |
31 |
| - |
32 |
| - return ( |
33 |
| - not class_name.startswith("_") |
34 |
| - and not any(pattern in class_name for pattern in SKIP_PATTERNS) |
35 |
| - and not any(base.endswith("P") for base in base_names if isinstance(base, str)) |
36 |
| - and any( |
37 |
| - base.startswith("_") or any(p in base for p in CONTROLLER_BASE_PATTERNS) |
38 |
| - for base in base_names |
39 |
| - ) |
40 |
| - ) |
41 | 14 |
|
42 | 15 |
|
43 | 16 | def get_controller_classes() -> Set[str]:
|
44 |
| - classes: Set[str] = set() |
45 |
| - for py_file in CONTROLLER_DIR.glob("*.py"): |
46 |
| - if py_file.name == "__init__.py": |
| 17 | + controller_module = importlib.import_module("shiny.playwright.controller") |
| 18 | + |
| 19 | + res: Set[str] = set() |
| 20 | + for x in dir(controller_module): |
| 21 | + if x.startswith("_") or x.startswith("@"): |
47 | 22 | continue
|
48 |
| - try: |
49 |
| - tree = ast.parse(py_file.read_text(encoding="utf-8")) |
50 |
| - classes.update( |
51 |
| - node.name |
52 |
| - for node in ast.walk(tree) |
53 |
| - if isinstance(node, ast.ClassDef) and _is_valid_controller_class(node) |
54 |
| - ) |
55 |
| - except Exception as e: |
56 |
| - pytest.fail(f"Failed to parse {py_file}: {e}") |
57 |
| - return classes |
| 23 | + res.add(x) |
| 24 | + |
| 25 | + return res |
58 | 26 |
|
59 | 27 |
|
60 | 28 | def get_documented_controllers() -> Set[str]:
|
|
0 commit comments