|
17 | 17 | from . import stdlibs
|
18 | 18 | from ._future import dataclass, field
|
19 | 19 | from ._vendored import toml
|
20 |
| -from .exceptions import InvalidSettingsPath, ProfileDoesNotExist |
| 20 | +from .exceptions import FormattingPluginDoesNotExist, InvalidSettingsPath, ProfileDoesNotExist |
21 | 21 | from .profiles import profiles
|
22 | 22 | from .sections import DEFAULT as SECTION_DEFAULTS
|
23 | 23 | from .sections import FIRSTPARTY, FUTURE, LOCALFOLDER, STDLIB, THIRDPARTY
|
@@ -173,6 +173,8 @@ class _Config:
|
173 | 173 | remove_redundant_aliases: bool = False
|
174 | 174 | float_to_top: bool = False
|
175 | 175 | filter_files: bool = False
|
| 176 | + formatter: str = "" |
| 177 | + formatting_function: Optional[Callable[[str, str, object], str]] = None |
176 | 178 |
|
177 | 179 | def __post_init__(self):
|
178 | 180 | py_version = self.py_version
|
@@ -348,6 +350,16 @@ def __init__(
|
348 | 350 | path_root / path for path in combined_config.get("src_paths", ())
|
349 | 351 | )
|
350 | 352 |
|
| 353 | + if "formatter" in combined_config: |
| 354 | + import pkg_resources |
| 355 | + |
| 356 | + for plugin in pkg_resources.iter_entry_points("isort.formatters"): |
| 357 | + if plugin.name == combined_config["formatter"]: |
| 358 | + combined_config["formatting_function"] = plugin.load() |
| 359 | + break |
| 360 | + else: |
| 361 | + raise FormattingPluginDoesNotExist(combined_config["formatter"]) |
| 362 | + |
351 | 363 | # Remove any config values that are used for creating config object but
|
352 | 364 | # aren't defined in dataclass
|
353 | 365 | combined_config.pop("source", None)
|
|
0 commit comments