2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 11:18:27 +08:00

interactive args: add title param

This commit is contained in:
Simon Renblad 2024-03-11 17:07:25 +08:00 committed by Sébastien Bourdeauducq
parent 609684664a
commit c4323e1179
5 changed files with 16 additions and 14 deletions

View File

@ -290,10 +290,11 @@ def _show_datasets(datasets):
def _show_interactive_args(interactive_args):
clear_screen()
table = PrettyTable(["RID", "Key", "Type", "Group", "Tooltip"])
for rid, args in sorted(interactive_args.items(), key=itemgetter(0)):
for key, procdesc, group, tooltip in args:
table.add_row([rid, key, procdesc["ty"], group, tooltip])
table = PrettyTable(["RID", "Title", "Key", "Type", "Group", "Tooltip"])
for rid, input_request in sorted(interactive_args.items(), key=itemgetter(0)):
title = input_request["title"]
for key, procdesc, group, tooltip in input_request["arglist_desc"]:
table.add_row([rid, title, key, procdesc["ty"], group, tooltip])
print(table)

View File

@ -167,7 +167,8 @@ def get_argparser(with_file=True):
class ArgumentManager(ProcessArgumentManager):
def get_interactive(self, interactive_arglist):
def get_interactive(self, interactive_arglist, title):
print(title)
result = dict()
for key, processor, group, tooltip in interactive_arglist:
success = False

View File

@ -214,7 +214,7 @@ class TraceArgumentManager:
self.requested_args[key] = processor, group, tooltip
return None
def get_interactive(self, interactive_arglist):
def get_interactive(self, interactive_arglist, title):
raise NotImplementedError
@ -238,7 +238,7 @@ class ProcessArgumentManager:
raise AttributeError("Supplied argument(s) not queried in experiment: " +
", ".join(unprocessed))
def get_interactive(self, interactive_arglist):
def get_interactive(self, interactive_arglist, title):
raise NotImplementedError
@ -332,7 +332,7 @@ class HasEnvironment:
self.kernel_invariants = kernel_invariants | {key}
@contextmanager
def interactive(self):
def interactive(self, title=""):
"""Request arguments from the user interactively.
This context manager returns a namespace object on which the method
@ -349,7 +349,7 @@ class HasEnvironment:
namespace.setattr_argument = setattr_argument
yield namespace
del namespace.setattr_argument
argdict = self.__argument_mgr.get_interactive(interactive_arglist)
argdict = self.__argument_mgr.get_interactive(interactive_arglist, title)
for key, value in argdict.items():
setattr(namespace, key, value)

View File

@ -121,8 +121,8 @@ class InteractiveArgDB:
self.pending = Notifier(dict())
self.futures = dict()
async def get(self, rid, arglist_desc):
self.pending[rid] = arglist_desc
async def get(self, rid, arglist_desc, title):
self.pending[rid] = {"title": title, "arglist_desc": arglist_desc}
self.futures[rid] = asyncio.get_running_loop().create_future()
try:
value = await self.futures[rid]
@ -136,7 +136,7 @@ class InteractiveArgDB:
if rid not in self.futures:
raise ValueError("no experiment with this RID is "
"waiting for interactive arguments")
if {i[0] for i in self.pending.raw_view[rid]} != set(values.keys()):
if {i[0] for i in self.pending.raw_view[rid]["arglist_desc"]} != set(values.keys()):
raise ValueError("supplied and requested keys do not match")
self.futures[rid].set_result(values)

View File

@ -218,10 +218,10 @@ def examine(device_mgr, dataset_mgr, file):
class ArgumentManager(ProcessArgumentManager):
_get_interactive = make_parent_action("get_interactive_arguments")
def get_interactive(self, interactive_arglist):
def get_interactive(self, interactive_arglist, title):
arglist_desc = [(k, p.describe(), g, t)
for k, p, g, t in interactive_arglist]
arguments = ArgumentManager._get_interactive(arglist_desc)
arguments = ArgumentManager._get_interactive(arglist_desc, title)
for key, processor, _, _ in interactive_arglist:
arguments[key] = processor.process(arguments[key])
return arguments