|
19 | 19 | # We spent hours getting startup from 1.7s → 0.5s. |
20 | 20 | # If you add `import pandas` here, I will find you. |
21 | 21 |
|
| 22 | +_LAZY_COMMANDS = { |
| 23 | + "new": "cli_new", |
| 24 | + "init": "cli_init", |
| 25 | + "pack": "cli_pack", |
| 26 | + "publish": "cli_publish", |
| 27 | + "run": "cli_run", |
| 28 | + "deploy": "cli_deploy", |
| 29 | + "auth": "cli_auth", |
| 30 | + "invoke": "cli_invoke", |
| 31 | + "push": "cli_push", |
| 32 | + "pull": "cli_pull", |
| 33 | + "eval": "cli_eval", |
| 34 | + "dev": "cli_dev", |
| 35 | + "add": "cli_add", |
| 36 | + "register": "cli_register", |
| 37 | + "debug": "cli_debug", |
| 38 | + "buckets": "services.cli_buckets", |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +def _load_command(name: str): |
| 43 | + """Load a CLI command by name.""" |
| 44 | + if name not in _LAZY_COMMANDS: |
| 45 | + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") |
| 46 | + module_name = _LAZY_COMMANDS[name] |
| 47 | + mod = __import__(f"uipath._cli.{module_name}", fromlist=[name]) |
| 48 | + return getattr(mod, name) |
| 49 | + |
| 50 | + |
| 51 | +def __getattr__(name: str): |
| 52 | + """Lazy load CLI commands for mkdocs-click compatibility.""" |
| 53 | + return _load_command(name) |
| 54 | + |
22 | 55 |
|
23 | 56 | def add_cwd_to_path(): |
24 | 57 | cwd = os.getcwd() |
@@ -48,35 +81,12 @@ def _get_safe_version() -> str: |
48 | 81 | class LazyGroup(click.Group): |
49 | 82 | """Lazy-load commands only when invoked.""" |
50 | 83 |
|
51 | | - def __init__(self, *args, **kwargs): |
52 | | - super().__init__(*args, **kwargs) |
53 | | - self._lazy_commands = { |
54 | | - "new": "cli_new", |
55 | | - "init": "cli_init", |
56 | | - "pack": "cli_pack", |
57 | | - "publish": "cli_publish", |
58 | | - "run": "cli_run", |
59 | | - "deploy": "cli_deploy", |
60 | | - "auth": "cli_auth", |
61 | | - "invoke": "cli_invoke", |
62 | | - "push": "cli_push", |
63 | | - "pull": "cli_pull", |
64 | | - "eval": "cli_eval", |
65 | | - "dev": "cli_dev", |
66 | | - "add": "cli_add", |
67 | | - "register": "cli_register", |
68 | | - "debug": "cli_debug", |
69 | | - "buckets": "services.cli_buckets", |
70 | | - } |
71 | | - |
72 | 84 | def list_commands(self, ctx): |
73 | | - return sorted(self._lazy_commands.keys()) |
| 85 | + return sorted(_LAZY_COMMANDS.keys()) |
74 | 86 |
|
75 | 87 | def get_command(self, ctx, cmd_name): |
76 | | - if cmd_name in self._lazy_commands: |
77 | | - module_name = self._lazy_commands[cmd_name] |
78 | | - mod = __import__(f"uipath._cli.{module_name}", fromlist=[cmd_name]) |
79 | | - return getattr(mod, cmd_name) |
| 88 | + if cmd_name in _LAZY_COMMANDS: |
| 89 | + return _load_command(cmd_name) |
80 | 90 | return None |
81 | 91 |
|
82 | 92 |
|
|
0 commit comments