From 786d13b14f500a41981bb2fd74f777357121d97a Mon Sep 17 00:00:00 2001 From: Pavel Bitiukov Date: Mon, 6 Nov 2023 22:33:30 +0000 Subject: [PATCH] Add support for passing the .toml config in the arguments --- autoflake.py | 6 +++++- test_autoflake.py | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/autoflake.py b/autoflake.py index 6bd31e9..b5cc160 100755 --- a/autoflake.py +++ b/autoflake.py @@ -1252,7 +1252,11 @@ def merge_configuration_file( if "config_file" in flag_args: config_file = pathlib.Path(flag_args["config_file"]).resolve() - config = process_config_file(str(config_file)) + process_method = process_config_file + if str(config_file).endswith('.toml'): + process_method = process_pyproject_toml + + config = process_method(str(config_file)) if not config: _LOGGER.error( diff --git a/test_autoflake.py b/test_autoflake.py index ad3315a..9971639 100755 --- a/test_autoflake.py +++ b/test_autoflake.py @@ -3389,6 +3389,28 @@ def test_config_option(self) -> None: check=True, ) + def test_merge_configuration_file__toml_config_option(self) -> None: + with temporary_file( + suffix=".toml", + contents=("[tool.autoflake]\n" "check = true\n"), + ) as temp_config: + self.create_file("test_me.py") + files = [self.effective_path("test_me.py")] + + args, success = autoflake.merge_configuration_file( + { + "files": files, + "config_file": temp_config, + }, + ) + + assert success is True + assert args == self.with_defaults( + files=files, + config_file=temp_config, + check=True, + ) + def test_load_false(self) -> None: self.create_file("test_me.py") self.create_file(