-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtyped_consumer.py
More file actions
77 lines (57 loc) · 2.05 KB
/
Copy pathtyped_consumer.py
File metadata and controls
77 lines (57 loc) · 2.05 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
"""Small strict-typing example for the public base-cli extension contracts."""
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from typing import Any
import base_cli
@dataclass(frozen=True)
class ApplicationState:
invocation_count: int = 0
@dataclass(frozen=True)
class Services:
workspace: Path
Config = dict[str, Any]
TypedContext = base_cli.Context[Config, ApplicationState, Services]
def profile() -> base_cli.CliProfile:
"""Return a profile whose extension points use only public contracts."""
def resolve_runtime(
cli_name: str,
project: base_cli.ProjectInfo | None,
) -> base_cli.RuntimeBinding:
root = Path(".base-cli-cache").resolve()
run_id = "sample-run"
layout = base_cli.RuntimeLayout(
owner_root=root / cli_name,
run_root=root / cli_name / "runs" / run_id,
state_dir=root / cli_name,
log_dir=root / cli_name / "runs" / run_id / "logs",
cache_dir=root / cli_name / "cache",
temp_dir=root / cli_name / "runs" / run_id / "tmp",
)
return base_cli.RuntimeBinding(
cache_root=root,
layout=layout,
application_home=None,
runtime_owner="typed-sample",
project_root=project.root if project is not None else None,
project_name=project.name if project is not None else None,
inherited_path=None,
history_parent_run_id=None,
run_id=run_id,
)
return base_cli.CliProfile.generic(resolve_runtime=resolve_runtime)
app = base_cli.App(
name="typed-sample",
profile=profile(),
log_to_file=False,
)
@app.command()
@base_cli.option("--verbose", is_flag=True)
def main(ctx: TypedContext, verbose: bool) -> None:
"""Use a consumer-owned context payload without private imports."""
del verbose
assert isinstance(ctx.config, dict)
_ = ctx.application_context
_ = ctx.services
if __name__ == "__main__":
raise SystemExit(base_cli.run_app(app))