How to use the isort.io.File function in isort

To help you get started, we’ve selected a few isort 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 timothycrosley / isort / isort / io.py View on Github external
def from_contents(contents: str, filename: str) -> "File":
        return File(
            contents, path=Path(filename).resolve(), encoding=_determine_content_encoding(contents)
        )
github timothycrosley / isort / isort / api.py View on Github external
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,
    )
github timothycrosley / isort / isort / io.py View on Github external
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)
github timothycrosley / isort / isort / compat.py View on Github external
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(
github timothycrosley / isort / isort / compat.py View on Github external
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,