Exemplo n.º 1
0
    def __init__(
            self,
            out=None,
            prefix='',
            columns='time',
            overwrite=False,
            color=None,
            enabled=True,
            watch_extras=(),
            replace_watch_extras=None,
            formatter_class=DefaultFormatter,
            pformat=None,
    ):
        if can_color:
            if color is None:
                isatty = getattr(out or sys.stderr, 'isatty', lambda: False)
                color = bool(isatty())
        else:
            color = False

        self.write = get_write_function(out, overwrite)
        self.formatter = formatter_class(prefix, columns, color)
        self.enabled = enabled

        if pformat is None:
            try:
                from prettyprinter import pformat
            except Exception:
                try:
                    from pprintpp import pformat
                except Exception:
                    from pprint import pformat

        self.pformat = pformat

        self.pp = PP(self)

        class ConfiguredTracer(Tracer):
            config = self

        self.snoop = ConfiguredTracer
        self.spy = Spy(self)

        self.last_frame = None
        self.thread_local = threading.local()

        if replace_watch_extras is not None:
            self.watch_extras = ensure_tuple(replace_watch_extras)
        else:
            self.watch_extras = (len_shape_watch, dtype_watch) + ensure_tuple(watch_extras)
Exemplo n.º 2
0
    def __init__(self, prefix, columns, color):
        prefix = six.text_type(prefix)
        if prefix and prefix == prefix.rstrip():
            prefix += u' '
        self.prefix = prefix
        self.columns = [
            column if callable(column) else getattr(
                self, u'{}_column'.format(column))
            for column in ensure_tuple(columns, split=True)
        ]
        self.column_widths = dict.fromkeys(self.columns, 0)
        if color is True:
            color = NeutralMonokaiStyle
        if color:
            self.c = Colors
            self.c.grey = formatters[color].style_string["Token.Comment"][0]

            def highlighted(code):
                return cached_highlight(code, color)

            def highlighted_source_line(event):
                return event.source.highlighted[color][event.line_no - 1]
        else:
            self.c = NoColors()

            def highlighted(code):
                return code

            def highlighted_source_line(event):
                return event.source_line

        self.highlighted = highlighted
        self.highlighted_source_line = highlighted_source_line
Exemplo n.º 3
0
 def __init__(
         self,
         watch=(),
         watch_explode=(),
         depth=1,
 ):
     self.watch = [
         v if isinstance(v, BaseVariable) else CommonVariable(v)
         for v in ensure_tuple(watch)
     ] + [
         v if isinstance(v, BaseVariable) else Exploding(v)
         for v in ensure_tuple(watch_explode)
     ]
     self.frame_infos = ArgDefaultDict(FrameInfo)
     self.depth = depth
     assert self.depth >= 1
     self.target_codes = set()
     self.target_frames = set()
Exemplo n.º 4
0
 def __init__(self, source, exclude=()):
     self.source = source
     self.exclude = ensure_tuple(exclude)
     self.code = compile(source, '<variable>', 'eval')
     self.unambiguous_source = with_needed_parentheses(source)