forked from ultraworkers/claw-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
77 lines (65 loc) · 2.26 KB
/
setup.py
File metadata and controls
77 lines (65 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from __future__ import annotations
import platform
import sys
from dataclasses import dataclass
from pathlib import Path
from .deferred_init import DeferredInitResult, run_deferred_init
from .prefetch import PrefetchResult, start_keychain_prefetch, start_mdm_raw_read, start_project_scan
@dataclass(frozen=True)
class WorkspaceSetup:
python_version: str
implementation: str
platform_name: str
test_command: str = 'python3 -m unittest discover -s tests -v'
def startup_steps(self) -> tuple[str, ...]:
return (
'start top-level prefetch side effects',
'build workspace context',
'load mirrored command snapshot',
'load mirrored tool snapshot',
'prepare parity audit hooks',
'apply trust-gated deferred init',
)
@dataclass(frozen=True)
class SetupReport:
setup: WorkspaceSetup
prefetches: tuple[PrefetchResult, ...]
deferred_init: DeferredInitResult
trusted: bool
cwd: Path
def as_markdown(self) -> str:
lines = [
'# Setup Report',
'',
f'- Python: {self.setup.python_version} ({self.setup.implementation})',
f'- Platform: {self.setup.platform_name}',
f'- Trusted mode: {self.trusted}',
f'- CWD: {self.cwd}',
'',
'Prefetches:',
*(f'- {prefetch.name}: {prefetch.detail}' for prefetch in self.prefetches),
'',
'Deferred init:',
*self.deferred_init.as_lines(),
]
return '\n'.join(lines)
def build_workspace_setup() -> WorkspaceSetup:
return WorkspaceSetup(
python_version='.'.join(str(part) for part in sys.version_info[:3]),
implementation=platform.python_implementation(),
platform_name=platform.platform(),
)
def run_setup(cwd: Path | None = None, trusted: bool = True) -> SetupReport:
root = cwd or Path(__file__).resolve().parent.parent
prefetches = [
start_mdm_raw_read(),
start_keychain_prefetch(),
start_project_scan(root),
]
return SetupReport(
setup=build_workspace_setup(),
prefetches=tuple(prefetches),
deferred_init=run_deferred_init(trusted=trusted),
trusted=trusted,
cwd=root,
)