MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / pick_machine

Function pick_machine

misc/python/materialize/cli/scratch/create.py:38–69  ·  view source on GitHub ↗

Show available machine configs and let the user pick one.

()

Source from the content-addressed store, hash-verified

36
37
38def pick_machine() -> str:
39 """Show available machine configs and let the user pick one."""
40 scratch_dir = MZ_ROOT / "misc" / "scratch"
41 configs: list[tuple[str, str, str]] = []
42 for f in sorted(scratch_dir.glob("*.json"), key=lambda f: _natsort_key(f.stem)):
43 with open(f) as fh:
44 descs = [MachineDesc.model_validate(obj) for obj in multi_json(fh.read())]
45 for d in descs:
46 configs.append((f.stem, d.instance_type, d.name))
47
48 render_table(
49 ["#", "CONFIG", "INSTANCE TYPE", "NAME"],
50 [
51 [str(i), stem, instance_type, name]
52 for i, (stem, instance_type, name) in enumerate(configs, 1)
53 ],
54 )
55
56 while True:
57 choice = input("Select a machine config [#]: ").strip()
58 try:
59 idx = int(choice)
60 if 1 <= idx <= len(configs):
61 return configs[idx - 1][0]
62 except ValueError:
63 # Allow typing the config name directly
64 for stem, _, _ in configs:
65 if choice == stem:
66 return stem
67 print(
68 f"Invalid choice: {choice!r}. Enter a number 1-{len(configs)} or a config name."
69 )
70
71
72def multi_json(s: str) -> list[dict[Any, Any]]:

Callers 2

runFunction · 0.90
load_machine_descsFunction · 0.85

Calls 5

render_tableFunction · 0.90
_natsort_keyFunction · 0.85
multi_jsonFunction · 0.85
readMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected