예제 #1
0
    def provn(self, line, cell):
        # Remove comment on %%provn line
        pos = line.find("#")
        line = line[:pos if pos != -1 else None]

        formatter = DollarFormatter()
        line = formatter.vformat(line,
                                 args=[],
                                 kwargs=self.shell.user_ns.copy())
        args = parse_argstring(self.provn, line)

        provn, dot_content = configure_graph(graph, args, cell)

        extensions = [x.lower() for x in args.extensions]

        if "provn" in extensions:
            if args.output:
                with open(args.output + ".provn", "w") as f:
                    f.write(provn)
            extensions.remove("provn")

        if not extensions:
            return "provn file created"

        dot_display = DotDisplay(dot_content, extensions, args.prog,
                                 args.extra)

        if args.output:
            dot_display.save(*((args.output + "." + ext)
                               for ext in extensions))

        return dot_display
예제 #2
0
파일: repl.py 프로젝트: JoaoFelipe/provbug
def _pb_format(value):
    if value is None:
        return value
    try:
        shell = get_ipython()
        formatter = DollarFormatter()
        value = formatter.vformat(value, args=[], kwargs=shell.user_ns.copy())
    except NameError:
        pass
    return value
예제 #3
0
 def execute(self, func, line, cell, magic_cls):
     formatter = DollarFormatter()
     cell = formatter.vformat(cell, args=[],
                              kwargs=magic_cls.shell.user_ns.copy())
     _, args = self.arguments(func, line)
     for trial_ref in args.trials:
         trial = Trial(trial_ref=trial_ref)
         trial.prolog.load_cli_facts()
     result = TrialProlog.prolog_query(cell)
     if args.result:
         magic_cls.shell.user_ns[args.result] = result
     else:
         return list(result)
예제 #4
0
 def execute(self, func, line, cell, magic_cls):
     formatter = DollarFormatter()
     cell = formatter.vformat(cell,
                              args=[],
                              kwargs=magic_cls.shell.user_ns.copy())
     _, args = self.arguments(func, line)
     for trial_ref in args.trials:
         trial = Trial(trial_ref=trial_ref)
         trial.prolog.load_cli_facts()
     result = TrialProlog.prolog_query(cell)
     if args.result:
         magic_cls.shell.user_ns[args.result] = result
     else:
         return list(result)
예제 #5
0
 def execute(self, func, line, cell, magic_cls):
     f = DollarFormatter()
     cell = f.vformat(cell, args=[], kwargs=magic_cls.shell.user_ns.copy())
     _, args = self.arguments(func, line)
     result = persistence.query(default_string(cell))
     if args.result:
         magic_cls.shell.user_ns[args.result] = result
     else:
         result = list(result)
         table = Table()
         if result:
             table.append(list(keys(result[0])))
         for line in result:
             table.append(list(values(line)))
         return table
예제 #6
0
 def execute(self, func, line, cell, magic_cls):
     formatter = DollarFormatter()
     cell = formatter.vformat(cell, args=[], kwargs=magic_cls.shell.user_ns.copy())
     _, args = self.arguments(func, line)
     result = relational.query(text_to_native_str(cell))
     if args.result:
         magic_cls.shell.user_ns[args.result] = result
     else:
         result = list(result)
         table = Table()
         if result:
             table.append(list(viewkeys(result[0])))
         for line in result:
             table.append(list(viewvalues(line)))
         return table
예제 #7
0
 def execute(self, func, line, cell, magic_cls):
     formatter = DollarFormatter()
     cell = formatter.vformat(cell, args=[],
                              kwargs=magic_cls.shell.user_ns.copy())
     _, args = self.arguments(func, line)
     result = relational.query(text_to_native_str(cell))
     if args.result:
         magic_cls.shell.user_ns[args.result] = result
     else:
         result = list(result)
         table = Table()
         if result:
             table.append(list(viewkeys(result[0])))
         for line in result:
             table.append(list(viewvalues(line)))
         return table
예제 #8
0
    def var_expand(self, cmd, depth=0, formatter=DollarFormatter()):
        """Expand python variables in a string.

        The depth argument indicates how many frames above the caller should
        be walked to look for the local namespace where to expand variables.

        The global namespace for expansion is always the user's interactive
        namespace.
        """
        ns = self.user_ns.copy()
        try:
            frame = sys._getframe(depth + 1)
        except ValueError:
            # This is thrown if there aren't that many frames on the stack,
            # e.g. if a script called run_line_magic() directly.
            pass
        else:
            ns.update(frame.f_locals)

        try:
            # We have to use .vformat() here, because 'self' is a valid and common
            # name, and expanding **ns for .format() would make it collide with
            # the 'self' argument of the method.
            cmd = formatter.vformat(cmd, args=[], kwargs=ns)
        except Exception:
            # if formatter couldn't format, just let it go untransformed
            pass
        return cmd
예제 #9
0
    def dot(self, line, cell):
        # pylint: disable=E0602
        # Remove comment on %%provn line
        pos = line.find("#")
        line = line[:pos if pos != -1 else None]

        formatter = DollarFormatter()
        line = formatter.vformat(line,
                                 args=[],
                                 kwargs=self.shell.user_ns.copy())
        args = parse_argstring(self.dot, line)

        dot_display = DotDisplay(cell, args.extensions, args.prog, args.extra)
        if args.output:
            dot_display.save(*((args.output + "." + ext)
                               for ext in args.extensions))

        return dot_display
예제 #10
0
 def visit_Call(self, node) -> Any:
     fields = {f: v for f, v in ast.iter_fields(node)}
     # Check if is a call to `run_cell_magic`
     if isinstance(fields['func'], ast.Attribute) and fields['func'].attr == 'run_cell_magic':
         for _, name, _, _ in DollarFormatter().parse(fields['args'][1].value):
             if name is not None:
                 self.deps.add(name)
     # Visit other fields
     self._visit_fields(fields)