Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def from_contents(contents: str, filename: str) -> "File":
return File(
contents, path=Path(filename).resolve(), encoding=_determine_content_encoding(contents)
)
def sorted_file(filename: str, config: Config = DEFAULT_CONFIG, **config_kwargs) -> str:
file_data = File.read(filename)
config = _config(path=file_data.path.parent, config=config)
return sorted_imports(
file_contents=file_data.contents,
extension=file_data.extension,
config=config,
file_path=file_data.path,
**config_kwargs,
)
def read(filename: str) -> "File":
file_path = Path(filename).resolve()
contents, encoding = _read_file_contents(file_path)
return File(contents=contents, path=file_path, encoding=encoding)
file_contents: str = "",
write_to_stdout: bool = False,
check: bool = False,
show_diff: bool = False,
settings_path: Optional[str] = None,
ask_to_apply: bool = False,
run_path: str = "",
check_skip: bool = True,
extension: str = "",
**setting_overrides: Any,
):
file_encoding = "utf-8"
file_path: Optional[Path] = None
if filename:
if file_contents:
file_data = File.from_contents(file_contents, filename=filename)
else:
file_data = File.read(filename)
file_contents, file_path, file_encoding = file_data
if not extension:
extension = file_data.extension
if settings_path:
setting_overrides["settings_path"] = settings_path
elif file_path and not "settings_file" in setting_overrides:
setting_overrides["settings_path"] = file_path.parent
config = Config(**setting_overrides)
try:
if check:
self.incorrectly_sorted = not api.check_imports(
check: bool = False,
show_diff: bool = False,
settings_path: Optional[str] = None,
ask_to_apply: bool = False,
run_path: str = "",
check_skip: bool = True,
extension: str = "",
**setting_overrides: Any,
):
file_encoding = "utf-8"
file_path: Optional[Path] = None
if filename:
if file_contents:
file_data = File.from_contents(file_contents, filename=filename)
else:
file_data = File.read(filename)
file_contents, file_path, file_encoding = file_data
if not extension:
extension = file_data.extension
if settings_path:
setting_overrides["settings_path"] = settings_path
elif file_path and not "settings_file" in setting_overrides:
setting_overrides["settings_path"] = file_path.parent
config = Config(**setting_overrides)
try:
if check:
self.incorrectly_sorted = not api.check_imports(
file_contents,
extension=extension,