Skip to content

Commit

Permalink
Support .toml configuration format with --config flag (#249)
Browse files Browse the repository at this point in the history
* Support .toml configuration format with --config flag

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
bricker and pre-commit-ci[bot] authored Apr 17, 2023
1 parent ad613b5 commit 780b44f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
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

0 comments on commit 780b44f

Please sign in to comment.