def _run(command, options, interactive=None): if interactive is None: interactive = options['--interactive'] if interactive: code_globals['options'] = options repl = Repl( buche, reader, code_globals=code_globals, address="/repl", log_address="/" ) buche.command_template(content=str(hrepr(repl))) buche.master.send({ "command": "redirect", "from": "/stdout", "to": "/" }) try: res = command(Options(options)) code_globals['res'] = res except InferenceError as e: print_inference_error(e) except Exception as e: buche(e, interactive=True) if interactive: repl.start(nodisplay=True)
class ReportInteractor: def __init__(self, id, item): self.id = id self.item = item self.report = None self.shown = False self.reported = False def set_report(self, report): self.report = report if self.shown: self.show_report() def show(self, synchronous=False): if self.shown: return self.repl = Repl(buche[f'main-tabs/tab-{self.id}'], get_reader(), code_globals=_code_globals) self.log = self.repl.log buche['main-tabs'].command_new( label=self.item.name, paneAddress=f'tab-{self.id}', ) self.repl.start(synchronous=synchronous) self.shown = True if self.report is not None: self.show_report() def show_report(self): if self.reported: return self.log.html.b(f'Status: {actual_outcome(self.report)}') if self.report.excinfo: self.log(self.report.excinfo.value, interactive=True) if self.report.capstdout: self.log.html(H.div['report-stdout']( H.div('Captured stdout'), H.bucheLog(address='__stdout'))) prout(self.report.capstdout, self.log['__stdout']) if self.report.capstderr: self.log.html(H.div['report-stderr']( H.div('Captured stderr'), H.bucheLog(address='__stderr'))) prout(self.report.capstderr, self.log['__stderr']) self.reported = True
def show(self, synchronous=False): if self.shown: return self.repl = Repl(buche[f'main-tabs/tab-{self.id}'], get_reader(), code_globals=_code_globals) self.log = self.repl.log buche['main-tabs'].command_new( label=self.item.name, paneAddress=f'tab-{self.id}', ) self.repl.start(synchronous=synchronous) self.shown = True if self.report is not None: self.show_report()