How to use the isort.settings.Config 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 / settings.py View on Github external
settings[key] = _abspaths(os.path.dirname(file_path), _as_list(value))
            elif key == "force_grid_wrap":
                try:
                    result = existing_value_type(value)
                except ValueError:  # backwards compatibility for true / false force grid wrap
                    result = 0 if value.lower().strip() == "false" else 2
                settings[key] = result
            elif key == "comment_prefix":
                settings[key] = str(value).strip("'").strip('"')
            else:
                settings[key] = existing_value_type(value)

    return settings


DEFAULT_CONFIG = Config()
github timothycrosley / isort / isort / api.py View on Github external
) -> Config:
    if path:
        if (
            config is DEFAULT_CONFIG
            and "settings_path" not in config_kwargs
            and "settings_file" not in config_kwargs
        ):
            config_kwargs["settings_path"] = path

    if config_kwargs and config is not DEFAULT_CONFIG:
        raise ValueError(
            "You can either specify custom configuration options using kwargs or "
            "passing in a Config object. Not Both!"
        )
    elif config_kwargs:
        config = Config(**config_kwargs)

    return config
github timothycrosley / isort / isort / compat.py View on Github external
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,
                    config=config,
                    file_path=file_path,
                    show_diff=show_diff,
                )
                self.output = ""
                return
            else:
                self.output = api.sorted_imports(
                    file_contents, extension=extension, config=config, file_path=file_path
                )
github timothycrosley / isort / isort / main.py View on Github external
elif file_names == ["-"]:
        SortImports(file_contents=sys.stdin.read(), write_to_stdout=True, **arguments)
    else:
        if "settings_path" not in arguments:
            arguments["settings_path"] = os.path.abspath(file_names[0]) or os.getcwd()
            if not os.path.isdir(arguments["settings_path"]):
                arguments["settings_path"] = os.path.dirname(arguments["settings_path"])

        config_dict = arguments.copy()
        ask_to_apply = config_dict.pop("ask_to_apply", False)
        jobs = config_dict.pop("jobs", ())
        show_logo = config_dict.pop("show_logo", False)
        filter_files = config_dict.pop("filter_files", False)
        check = config_dict.pop("check", False)
        show_diff = config_dict.pop("show_diff", False)
        config = Config(**config_dict)

        wrong_sorted_files = False
        skipped: List[str] = []

        if filter_files:
            filtered_files = []
            for file_name in file_names:
                if config.is_skipped(Path(file_name)):
                    skipped.append(file_name)
                else:
                    filtered_files.append(file_name)
            file_names = filtered_files

        file_names = iter_source_code(file_names, config, skipped)
        num_skipped = 0
        if config.verbose or show_logo: