How to use the removestar.removestar.fix_code function in removestar

To help you get started, we’ve selected a few removestar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asmeurer / removestar / removestar / test_removestar.py View on Github external
    raises(RuntimeError, lambda: fix_code(submod))
    assert fix_code(submod/'submod1.py') == code_submod1_fixed
github asmeurer / removestar / removestar / test_removestar.py View on Github external
    raises(RuntimeError, lambda: fix_code(directory/'notarealfile.py'))
github asmeurer / removestar / removestar / __main__.py View on Github external
args.max_line_length = float('inf')

    for file in _iter_paths(args.paths):
        directory, filename = os.path.split(file)
        if args.skip_init and filename == '__init__.py':
            continue

        if not os.path.isfile(file):
            print(f"Error: {file}: no such file or directory", file=sys.stderr)
            continue

        with open(file) as f:
            code = f.read()

        try:
            new_code = fix_code(code, file=file, max_line_length=args.max_line_length,
                                verbose=args.verbose, quiet=args.quiet, allow_dynamic=args.allow_dynamic)
        except (RuntimeError, NotImplementedError) as e:
            if not args.quiet:
                print(f"Error with {file}: {e}", file=sys.stderr)
            continue

        if new_code != code:
            if args.in_place:
                with open(file, 'w') as f:
                    f.write(new_code)
            else:

                print(get_diff_text(io.StringIO(code).readlines(),
                    io.StringIO(new_code).readlines(), file))