diff --git a/ufmt/config.py b/ufmt/config.py index c2a5736..4f6ba1f 100644 --- a/ufmt/config.py +++ b/ufmt/config.py @@ -8,7 +8,7 @@ import tomlkit from trailrunner import project_root -from .types import Formatter, UfmtConfig +from .types import Formatter, Sorter, UfmtConfig LOG = logging.getLogger(__name__) @@ -35,6 +35,7 @@ def load_config(path: Optional[Path] = None, root: Optional[Path] = None) -> Ufm raise ValueError(f"{config_path}: excludes must be a list of strings") formatter = Formatter(config.pop("formatter", UfmtConfig.formatter)) + sorter = Sorter(config.pop("sorter", Sorter.usort)) if config: LOG.warning("%s: unknown values ignored: %r", config_path, sorted(config)) @@ -44,6 +45,7 @@ def load_config(path: Optional[Path] = None, root: Optional[Path] = None) -> Ufm pyproject_path=config_path, excludes=excludes, formatter=formatter, + sorter=sorter, ) return UfmtConfig() diff --git a/ufmt/tests/config.py b/ufmt/tests/config.py index 05deaf5..07a9f97 100644 --- a/ufmt/tests/config.py +++ b/ufmt/tests/config.py @@ -177,6 +177,18 @@ def test_invalid_config(self, log_mock): ): load_config(self.td / "fake.py") + with self.subTest("unsupported sorter"): + self.pyproject.write_text( + dedent( + """ + [tool.ufmt] + sorter = "garbage" + """ + ) + ) + with self.assertRaisesRegex(ValueError, "'garbage' is not a valid Sorter"): + load_config(self.td / "fake.py") + @patch("ufmt.config.LOG") def test_config_excludes(self, log_mock): with self.subTest("missing"):