Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for passing the .toml config in the arguments #285

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 config_file.suffix == ".toml":
process_method = process_pyproject_toml

config = process_method(str(config_file))

if not config:
_LOGGER.error(
Expand Down
22 changes: 22 additions & 0 deletions test_autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down