autoflake icon indicating copy to clipboard operation
autoflake copied to clipboard

Breaking change to configuration logic in v2.1.0

Open kevinr-electric opened this issue 1 year ago • 8 comments

By changing the config file resolution for .toml files, this new minor version has broken configuration in cases where the --config CLI argument is used.

In the new version's changes, in the merge_configuration_file function on line 1199 autoflake now calls the process_pyproject_toml function for .toml files instead the process_config_file function. The result is that the tool will now try to get the "tool.autoflake" section section instead of the "autoflake" section. In other words, a configuration file that worked with v2.0.2 breaks on v2.1.0 (and vice versa).

As an aside, is there a place where release notes are posted? I couldn't find them on GH or Pypi.

kevinr-electric avatar Apr 17 '23 15:04 kevinr-electric

Hi @kevinr-electric, thanks for reporting. I'm going to revert that change and then we can have a separate flag that's exclusive for the location of pyproject.toml.

Currently, autoflake doesn't keep a changelog in a dedicated location. We can introduce something with GitHub releases though.

fsouza avatar Apr 18 '23 12:04 fsouza

Hey @fsouza, thanks for the update. A releases section with release notes would also be appreciated!

kevinr-electric avatar Apr 18 '23 20:04 kevinr-electric

I'm confused here; Passing a toml file to --config was completely broken before (that was the whole point of this PR). How were you doing that?

bricker avatar May 04 '23 00:05 bricker

In version 2.1.1, I'm seeing that [autoflake] works, but [tool.autoflake] does not for a pyproject.toml file.

This is in direct contradiction to the PyPi docs

joeyagreco avatar May 14 '23 08:05 joeyagreco

@joeyagreco can you share an example? I can't repro it:

% cat pyproject.toml
[project]
name = "sample"
description = "Just a sample"
license = { text = "ISC" }

[tool.autoflake]
expand-star-imports = true
% cat sample.py
import os
from sys import *

print("hi", file=stderr)
% autoflake sample.py
--- original/sample.py
+++ fixed/sample.py
@@ -1,4 +1,3 @@
-import os
-from sys import *
+from sys import stderr

 print("hi", file=stderr)
% autoflake --version
autoflake 2.1.1

fsouza avatar May 29 '23 00:05 fsouza

Sure! @fsouza

Here's my pyproject.toml file

[autoflake]
ignore_init_module_imports = true
in_place = true
recursive = true
remove_all_unused_imports = true

Check version

% autoflake --version
> autoflake 2.1.1

Run it

% autoflake --config=pyproject.toml .
> 

Works (removes an unused import)

Let's change the pyproject.toml

[tool.autoflake]
ignore_init_module_imports = true
in_place = true
recursive = true
remove_all_unused_imports = true

Now let's run it again

% autoflake --config=pyproject.toml .
> can't parse config file 'C:\foo\baz\pyproject.toml'

joeyagreco avatar May 29 '23 03:05 joeyagreco

@joeyagreco ahh ok, yes --config doesn't support pyproject.toml at the moment. It's being parsed as an ini file, and toml just happens to be compatible with that.

fsouza avatar May 29 '23 04:05 fsouza

I'm confused here; Passing a toml file to --config was completely broken before (that was the whole point of https://github.com/PyCQA/autoflake/pull/249). How were you doing that?

Sorry, I had missed this message, but I assume people were relying on the fact that simple toml files can be parsed as ini files. After thinking about this a little bit, I feel like we can roll #249 forward again. Alternatively, we could have a dedicated flag for pyproject.toml.

fsouza avatar May 29 '23 04:05 fsouza