Skip to content
New issue

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

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

Already on GitHub? # to your account

Support .toml configuration format with --config flag #249

Merged
merged 2 commits into from
Apr 17, 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 @@ -1194,7 +1194,11 @@ def merge_configuration_file(flag_args):

if "config_file" in flag_args:
config_file = pathlib.Path(flag_args["config_file"]).resolve()
config = process_config_file(config_file)

if config_file.suffix == ".toml":
config = process_pyproject_toml(config_file)
else:
config = process_config_file(config_file)

if not config:
_LOGGER.error(
Expand Down
26 changes: 26 additions & 0 deletions test_autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -3385,6 +3385,32 @@ def test_config_option(self):
check=True,
)

def test_config_option_toml(self):
with temporary_file(
suffix=".toml",
contents=(
"[tool.autoflake]\n"
"check = true\n"
'exclude = [\n "build",\n ".venv",\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,
exclude="build,.venv",
)

def test_load_false(self):
self.create_file("test_me.py")
self.create_file(
Expand Down