Beispiel #1
0
def run_script(
    path: Path,
    argv: List[str],
    max_value_str_len: int,
    max_exc_str_len: int,
    ellipsis_: str,
    num_context_lines: int,
    color_scheme: ColorScheme,
) -> int:
    sys.path[0] = str(path.parent)
    sys.argv = [str(path)] + argv
    globals_ = {
        'sys': sys,
        'argparse': argparse,
        '__name__': '__main__',
    }

    with printing_tb(
            reraise=False,
            skip_cur_frame=True,
            max_value_str_len=max_value_str_len,
            max_exc_str_len=max_exc_str_len,
            ellipsis_=ellipsis_,
            num_context_lines=num_context_lines,
            color_scheme=color_scheme,
    ):
        exec(compile(path.read_text(), str(path), "exec"), globals_, globals_)

        return 0

    return 1  # noqa # actually 'this code is unreachable' is wrong
Beispiel #2
0
def main():
    with printing_tb(
        num_context_lines=3,
        max_value_str_len=100,
        max_exc_str_len=1000,
        ellipsis_='...',
        skip_cur_frame=True,  # e.g. no info about 'x'
        reraise=False,  # i.e. program won't fail, exceptions stay inside
    ):
        x = 1
        f(x - 1)
Beispiel #3
0
def main():
    with printing_tb(file_=LoggerAsFile(logger)):
        x = 1
        f(x - 1)
def main():
    with printing_tb():
        x = 1
        f(x - 1)
Beispiel #5
0
def main():
    sizes_str = '300 200 300 0'
    with printing_tb(color_scheme=ColorSchemes.common):
        h1, w1, h2, w2 = map(int, sizes_str.split())

        return get_avg_ratio((h1, w1), (h2, w2))