thzdaq-cli 0.0.6b3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- thzdaq_cli/__init__.py +1 -0
- thzdaq_cli/__main__.py +5 -0
- thzdaq_cli/agents.py +259 -0
- thzdaq_cli/app.py +100 -0
- thzdaq_cli/approvals.py +150 -0
- thzdaq_cli/client.py +140 -0
- thzdaq_cli/daemon.py +266 -0
- thzdaq_cli/devices.py +262 -0
- thzdaq_cli/measurements.py +383 -0
- thzdaq_cli/scripts.py +167 -0
- thzdaq_cli/show.py +71 -0
- thzdaq_cli/station.py +72 -0
- thzdaq_cli/workspaces.py +177 -0
- thzdaq_cli-0.0.6b3.dist-info/METADATA +27 -0
- thzdaq_cli-0.0.6b3.dist-info/RECORD +18 -0
- thzdaq_cli-0.0.6b3.dist-info/WHEEL +4 -0
- thzdaq_cli-0.0.6b3.dist-info/entry_points.txt +2 -0
- thzdaq_cli-0.0.6b3.dist-info/licenses/LICENSE +21 -0
thzdaq_cli/workspaces.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"""thzdaq init, thzdaq python, thzdaq gui: workspaces, the folders of
|
|
2
|
+
experiments.
|
|
3
|
+
|
|
4
|
+
init makes a folder a workspace: thzdaq.toml naming the profile it expects
|
|
5
|
+
(the daemon's by default) and, with --python, the Python its scripts run
|
|
6
|
+
with; data/ and scripts/; with --agents also the files Claude Code and Codex
|
|
7
|
+
read (as agent-setup writes them). python shows the Python of the workspace
|
|
8
|
+
here (checked: it has thzdaq of this program's version), sets another, or
|
|
9
|
+
lists the environments found (thzdaq_api.interpreters). gui opens the window
|
|
10
|
+
in the workspace here, apart from this terminal: another window when one is
|
|
11
|
+
open already. The window is another program, started as installed (the
|
|
12
|
+
build's ThzDAQ, or the GUI package), never imported.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any, Dict, Optional, Tuple
|
|
17
|
+
|
|
18
|
+
from thzdaq_api import host, interpreters, windows
|
|
19
|
+
from thzdaq_api.errors import ErrorCode, LabError
|
|
20
|
+
from thzdaq_api.interpreters import Checked, Environment, check, check_own, stored
|
|
21
|
+
from thzdaq_api.workspace import FILE, create, is_workspace, read, write_python
|
|
22
|
+
|
|
23
|
+
from thzdaq_cli import agents, show
|
|
24
|
+
from thzdaq_cli.client import FAILED, HERE, OK, THIS_FOLDER, Client, Mistyped
|
|
25
|
+
|
|
26
|
+
OWN = "the program's own" # the Python of a workspace that names none
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def add(commands) -> None:
|
|
30
|
+
init = commands.add_parser(
|
|
31
|
+
"init", help="make a folder a workspace: thzdaq.toml, data/, scripts/"
|
|
32
|
+
)
|
|
33
|
+
init.add_argument("folder", nargs="?", default=".", help=THIS_FOLDER)
|
|
34
|
+
init.add_argument(
|
|
35
|
+
"--station",
|
|
36
|
+
help="the profile it expects, by its name in stations/ (default: the "
|
|
37
|
+
"daemon's, when one runs)",
|
|
38
|
+
)
|
|
39
|
+
init.add_argument(
|
|
40
|
+
"--python",
|
|
41
|
+
help="the Python its scripts run with: an environment's folder or its "
|
|
42
|
+
"interpreter (default: the program's own)",
|
|
43
|
+
)
|
|
44
|
+
init.add_argument(
|
|
45
|
+
"--agents",
|
|
46
|
+
action="store_true",
|
|
47
|
+
help="also the files Claude Code and Codex read (as agent-setup)",
|
|
48
|
+
)
|
|
49
|
+
init.set_defaults(run=init_workspace)
|
|
50
|
+
python = commands.add_parser(
|
|
51
|
+
"python", help="the Python the scripts of the workspace here run with"
|
|
52
|
+
)
|
|
53
|
+
actions = python.add_subparsers(dest="action", required=True, metavar="ACTION")
|
|
54
|
+
shown = actions.add_parser("show", help="which one, checked")
|
|
55
|
+
shown.set_defaults(run=show_python)
|
|
56
|
+
chosen = actions.add_parser("set", help="choose another, then check it")
|
|
57
|
+
chosen.add_argument(
|
|
58
|
+
"path", nargs="?", help="an environment's folder (.venv) or its interpreter"
|
|
59
|
+
)
|
|
60
|
+
chosen.add_argument("--own", action="store_true", help="the program's own again")
|
|
61
|
+
chosen.set_defaults(run=set_python)
|
|
62
|
+
listed = actions.add_parser("list", help="environments found here, * the chosen")
|
|
63
|
+
listed.set_defaults(run=list_pythons)
|
|
64
|
+
for action in (shown, chosen, listed):
|
|
65
|
+
action.add_argument("--workspace", help=HERE)
|
|
66
|
+
window = commands.add_parser("gui", help="open the window in the workspace here")
|
|
67
|
+
window.add_argument(
|
|
68
|
+
windows.WORKSPACE,
|
|
69
|
+
help="the folder it opens (default: the workspace here or above, else "
|
|
70
|
+
"the window's default)",
|
|
71
|
+
)
|
|
72
|
+
window.set_defaults(run=open_window)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def init_workspace(args, client: Client) -> int:
|
|
76
|
+
folder = Path(args.folder).resolve()
|
|
77
|
+
station = client.daemons_profile() if args.station is None else args.station
|
|
78
|
+
python = given_python(folder, args.python) if args.python else ""
|
|
79
|
+
written = create(folder, station, python)
|
|
80
|
+
told: Dict[str, Any] = {
|
|
81
|
+
"folder": str(folder),
|
|
82
|
+
"files": {FILE: agents.WRITTEN if written else agents.KEPT},
|
|
83
|
+
"station": read(folder).station,
|
|
84
|
+
"python": python_told(folder),
|
|
85
|
+
}
|
|
86
|
+
if args.agents:
|
|
87
|
+
told["agents"] = agents.setup(folder, args.simulate, agents.library(client))
|
|
88
|
+
client.out(told, init_text)
|
|
89
|
+
return OK if told["python"]["checked"].ok else FAILED
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def init_text(told: Dict[str, Any]) -> str:
|
|
93
|
+
expects = told["station"]
|
|
94
|
+
lines = [
|
|
95
|
+
f"{told['files'][FILE]} {FILE}: "
|
|
96
|
+
+ (f"expects the profile {expects!r}" if expects else "expects no profile"),
|
|
97
|
+
f"workspace {told['folder']}: measurements go to its data/",
|
|
98
|
+
python_text(told["python"]),
|
|
99
|
+
]
|
|
100
|
+
if "agents" in told:
|
|
101
|
+
lines += ["", agents.setup_text(told["agents"])]
|
|
102
|
+
return "\n".join(lines)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def given_python(folder: Path, path: str) -> str:
|
|
106
|
+
"""How thzdaq.toml names a Python typed here; LabError when there is
|
|
107
|
+
none there."""
|
|
108
|
+
interpreters.python_in(interpreters.located(path))
|
|
109
|
+
return stored(folder, path)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def python_told(folder: Optional[Path]) -> Dict[str, Any]:
|
|
113
|
+
"""The Python of a workspace: as its thzdaq.toml names it, the
|
|
114
|
+
interpreter, checked."""
|
|
115
|
+
named = read(folder).python if folder is not None else ""
|
|
116
|
+
found = interpreters.chosen(folder)
|
|
117
|
+
checked = check(found) if found is not None else check_own()
|
|
118
|
+
return {"named": named, "python": str(found or ""), "checked": checked}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def python_text(told: Dict[str, Any]) -> str:
|
|
122
|
+
checked: Checked = told["checked"]
|
|
123
|
+
which = f"{told['named']} ({told['python']})" if told["named"] else OWN
|
|
124
|
+
return f"scripts run with {which}: {checked.text()}"
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def workspace_of(client: Client) -> Path:
|
|
128
|
+
"""The workspace of a command that writes its thzdaq.toml."""
|
|
129
|
+
if client.workspace is None or not is_workspace(client.workspace):
|
|
130
|
+
raise LabError(
|
|
131
|
+
ErrorCode.NOT_FOUND,
|
|
132
|
+
"No workspace here: the program's own folder runs scripts with "
|
|
133
|
+
"the program's own Python",
|
|
134
|
+
"thzdaq init makes a workspace",
|
|
135
|
+
)
|
|
136
|
+
return client.workspace
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def show_python(args, client: Client) -> int:
|
|
140
|
+
told = python_told(client.workspace)
|
|
141
|
+
client.out(told, python_text)
|
|
142
|
+
return OK if told["checked"].ok else FAILED
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def set_python(args, client: Client) -> int:
|
|
146
|
+
if bool(args.path) == args.own:
|
|
147
|
+
raise Mistyped("set a path, or --own")
|
|
148
|
+
folder = workspace_of(client)
|
|
149
|
+
write_python(folder, given_python(folder, args.path) if args.path else "")
|
|
150
|
+
return show_python(args, client)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def list_pythons(args, client: Client) -> int:
|
|
154
|
+
found = interpreters.environments(client.workspace)
|
|
155
|
+
now = interpreters.current(found, client.workspace)
|
|
156
|
+
client.out(found, lambda listed: environments_text(listed, now))
|
|
157
|
+
return OK
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def environments_text(
|
|
161
|
+
found: Tuple[Environment, ...], now: Optional[Environment]
|
|
162
|
+
) -> str:
|
|
163
|
+
return show.table(
|
|
164
|
+
("", "kind", "name", "folder"),
|
|
165
|
+
[("*" if e == now else "", e.kind, e.name, e.path) for e in found],
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def open_window(args, client: Client) -> int:
|
|
170
|
+
command = windows.gui_command(client.workspace, client.simulate)
|
|
171
|
+
host.start_apart(command)
|
|
172
|
+
folder = str(client.workspace) if client.workspace else None
|
|
173
|
+
client.out(
|
|
174
|
+
{"workspace": folder, "command": command},
|
|
175
|
+
lambda told: f"ThzDAQ opens in {told['workspace'] or 'its default workspace'}",
|
|
176
|
+
)
|
|
177
|
+
return OK
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: thzdaq-cli
|
|
3
|
+
Version: 0.0.6b3
|
|
4
|
+
Summary: ThzDAQ command line: a client of the bench daemon
|
|
5
|
+
Project-URL: Homepage, https://github.com/yarvod/ThzDAQ
|
|
6
|
+
Project-URL: Documentation, https://github.com/yarvod/ThzDAQ/blob/master/docs/daemon.md
|
|
7
|
+
Project-URL: Issues, https://github.com/yarvod/ThzDAQ/issues
|
|
8
|
+
Project-URL: Releases, https://github.com/yarvod/ThzDAQ/releases
|
|
9
|
+
Author: yarvod
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: thzdaq-api==0.0.6b3
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# thzdaq-cli
|
|
24
|
+
|
|
25
|
+
The `thzdaq` command: a client of the bench daemon through `thzdaq-api`, like the GUI and
|
|
26
|
+
the MCP server. It starts the daemon's executable when needed and never imports it.
|
|
27
|
+
Install it with [`thzdaq`](https://pypi.org/project/thzdaq/).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
thzdaq_cli/__init__.py,sha256=cg1MCv5wUHDKrvdrqnYJor4QKNN_DG56LFquiboCVOU,90
|
|
2
|
+
thzdaq_cli/__main__.py,sha256=BfXIAPs4HsAtwHn1WzvRfL4RG04k13qOKPsNxwLmRdA,62
|
|
3
|
+
thzdaq_cli/agents.py,sha256=oTBNnzK91vZFbGpaFgEBhouTViLhVuaTtjDGit-KB6I,9886
|
|
4
|
+
thzdaq_cli/app.py,sha256=rAp-fWpCwHcOxeiwzqOrAsC8Z6c9RIXfx17nqfcxSsU,3017
|
|
5
|
+
thzdaq_cli/approvals.py,sha256=lZZFjtAFdgrznrT_n8UtLQmX_Y8UhOggMF6sjoQiAZU,6088
|
|
6
|
+
thzdaq_cli/client.py,sha256=snvbXnp3z4cJlSaxdwlcyRMd_XvDXY4ssChfBgx6hNY,5170
|
|
7
|
+
thzdaq_cli/daemon.py,sha256=1tO98S4piQy6W5Y7qwLAjlY-P2bJrC5eTS-SNE94ynw,10145
|
|
8
|
+
thzdaq_cli/devices.py,sha256=K-9YXAsHypnft5h3nJYcVzd5OM7Pansc0ICdzjJEiEg,9450
|
|
9
|
+
thzdaq_cli/measurements.py,sha256=XTFu9nHzLgkbPZJItiJvOPBo_mcprhzqyBB8avficdQ,14242
|
|
10
|
+
thzdaq_cli/scripts.py,sha256=HHhE9CB_dkOzFc1FzUcLmLjxae6QZe6vZ_WKNmd4ldI,6046
|
|
11
|
+
thzdaq_cli/show.py,sha256=dEYv8_H2-Q3Jo9IRnaOMxb0267M9NDidtSPsfV508Nw,2496
|
|
12
|
+
thzdaq_cli/station.py,sha256=5iNpopYDD_KvfPjJ0E0BGw4iV9vW6MCgN_8P7fQHjM4,2359
|
|
13
|
+
thzdaq_cli/workspaces.py,sha256=Divk0UYaAFH4J-mUJJtUKoODU0Ysrq4PgUg0mhKY4ME,6928
|
|
14
|
+
thzdaq_cli-0.0.6b3.dist-info/METADATA,sha256=wqXqdKqb8hDAV8PCoI6o5EDfMMA8NfkqRXYKLqtpXk4,1147
|
|
15
|
+
thzdaq_cli-0.0.6b3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
16
|
+
thzdaq_cli-0.0.6b3.dist-info/entry_points.txt,sha256=RishkzAh9kf_RjkTvkIsSrhnk9QbwaQR7vQHhkXdMB0,47
|
|
17
|
+
thzdaq_cli-0.0.6b3.dist-info/licenses/LICENSE,sha256=jXHKk1r0G-rRjWXmfQVbjBzee356QkXdR3C8GExo_V0,1063
|
|
18
|
+
thzdaq_cli-0.0.6b3.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 yarvod
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|