Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def fstringify(file_or_path, verbose=False, quiet=False):
to_use = os.path.abspath(file_or_path)
if not os.path.exists(to_use):
print(f"`{file_or_path}` not found")
sys.exit(1)
if os.path.isdir(to_use):
files = astor.code_to_ast.find_py_files(to_use)
else:
files = ((os.path.dirname(to_use), os.path.basename(to_use)),)
fstringify_files(files, verbose=verbose, quiet=quiet)
def _resolve_files(files_or_paths) -> List[str]:
"""Resolve relative paths and directory names into a list of absolute paths to python files."""
files = []
for file_or_path in files_or_paths:
abs_path = os.path.abspath(file_or_path)
if not os.path.exists(abs_path):
print(f"`{file_or_path}` not found")
sys.exit(1)
if os.path.isdir(abs_path):
for folder, filename in astor.code_to_ast.find_py_files(abs_path):
files.append(os.path.join(folder, filename))
else:
files.append(abs_path)
files = [f for f in files if all(b not in file_or_path for b in blacklist)]
return files
def fstringify_dir(in_dir):
files = astor.code_to_ast.find_py_files(in_dir)
return fstringify_files(files)