def command_debug(arguments): stx.__save_trace__ = True arguments.decls = True arguments.stores = False arguments.check = True setup_buche(arguments) args = getargs(arguments) r, genv = getfn(arguments) @reader.on_click def handle(e, cmd): try: obj = id_registry[int(cmd.objId)] if 'break' in obj.annotations: obj.annotations.remove('break') buche[cmd.path]('Unset breakpoint.') else: obj.annotations.add('break') buche[cmd.path]('Set breakpoint.') except Exception as exc: buche[cmd.path](exc) budb.set_trace() fn = compile(genv[r]) try: buche(fn.debug(args, budb), gutter='result') except Exception as exc: buche(exc, gutter='error')
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)
def bucheg(graph, **kwargs): from myia.ir import ANFNode from myia.abstract import Inferrer def ttip(node): if isinstance(node, ANFNode): return node.abstract buche(graph, node_tooltip=ttip, function_in_node=True, graph_width='95vw', graph_height='95vh', **kwargs)
def parse(o): from myia.parser import parse fn, = o.options['fns'] buche( parse(fn), graph_width='95vw', graph_height='95vh', function_in_node=not o['--function-nodes'], graph_beautify=not o['--no-beautify'] and not o['--function-nodes'], )
def bucheg(graph, **kwargs): from myia.ir import ANFNode def ttip(node): if isinstance(node, ANFNode): return node.abstract kw = dict(node_tooltip=ttip, function_in_node=True, graph_width='95vw', graph_height='95vh') kw.update(kwargs) buche(graph, **kw)
def parse(o): from myia.parser import parse (fn, ) = o.options["fns"] buche( parse(fn), graph_width="95vw", graph_height="95vh", function_in_node=not o["--function-nodes"], graph_beautify=not o["--no-beautify"] and not o["--function-nodes"], )
def main(*option_dicts, read_argv=True, read_config=True, rest_target='--fn'): options = resolve_options(*option_dicts, read_argv=read_argv, read_config=read_config, rest_target=rest_target) options = process_options(options, rest_target) try: options['command'](Options(options)) except InferenceError: raise except Exception as e: buche(e)
def on_error(e, exc): vm = e.owner focus = vm.frame.focus add_class(focus, 'error0') buche.html('<h2>An error occurred</h2>') buche.html('<h3>Node</h3>') buche(vm.frame) buche(focus) buche.html('<h3>Traceback</h3>') for i, frame in enumerate([vm.frame] + vm.frames): node = frame.focus if node: add_class(node, 'error')
def display(data, format, mode='normal'): global setup_done if format == 'html': print(H(data).as_page()) elif format == 'buche': if mode == 'normal': buche(data) elif isinstance(data, dict): for k, v in data.items(): buche['funcs'][str(k)](v) else: buche(data) elif isinstance(data, dict): for k, v in data.items(): print(f'{k}:\n {v}') else: print(data)
def show(o): res = o.run(default=[steps.parse, steps.resolve], ) g = res['graph'] def ttip(node): if isinstance(node, ANFNode): return node.abstract buche( g, graph_width='95vw', graph_height='95vh', node_tooltip=ttip, function_in_node=not o['--function-nodes'], graph_beautify=not o['--no-beautify'] and not o['--function-nodes'], ) return res
def show(o): res = o.run(default=[steps.parse, steps.resolve], ) g = res["graph"] def ttip(node): if isinstance(node, ANFNode): return node.abstract buche( g, graph_width="95vw", graph_height="95vh", node_tooltip=ttip, function_in_node=not o["--function-nodes"], graph_beautify=not o["--no-beautify"] and not o["--function-nodes"], ) return res
def show(o): res = o.run(default=[steps.parse, steps.resolve]) if 'error' in res: raise res['error'] g = res['graph'] def ttip(node): if isinstance(node, ANFNode): return node.inferred buche( g, graph_width='95vw', graph_height='95vh', node_tooltip=ttip, function_in_node=not o['--function-nodes'], graph_beautify=not o['--no-beautify'], )
def pytest_sessionstart(session): global _capture _capture = session.config.pluginmanager.get_plugin('capturemanager') buche.command_template(src=template_path) buche( H.script(""" function tippy(x, y) { f = () => tippy(x, y); setTimeout(f, 1000); } """, type="text/javascript")) scripts = [ "https://unpkg.com/popper.js@1/dist/umd/popper.min.js", "https://unpkg.com/tippy.js@4" ] for s in scripts: buche(H.script(type="text/javascript", src=s)) buche(H.span()) buche(H.style(mcss)) buche.require('cytoscape')
def ibuche(*args, **kwargs): _log.append(args) buche(*args, interactive=True, **kwargs)
def __call__(self, universe, graph): buche(self.label, graph, function_in_node=True, duplicate_constants=True, follow_references=True)
""" .my-template { background-color: #eee; padding: 5px; display: flex; flex-direction: column; align-items: start; } """ )) # Display simple HTML buche.html.h3('Welcome!') # Display objects buche(1234) buche([x * x for x in range(100)]) buche.dict(avocado="green", banana="yellow", cherry="red") # Open automatically creates an address for an element div1 = buche.open.div(style="border: 3px solid red") # You can also set an address explicitly buche.html.div(address='/two', style="border: 3px solid blue") # Get a printer for the given address div2 = buche['/two'] # These objects will go in the divs div1('One') div2('Two')