Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raises(RuntimeError, lambda: fix_code(submod))
assert fix_code(submod/'submod1.py') == code_submod1_fixed
raises(RuntimeError, lambda: fix_code(directory/'notarealfile.py'))
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))