Support for pyproject.toml
Dekker1 opened this issue ยท 14 comments
isort added support for using a pyproject.toml
file for it's configuration in version 4.3.5. It would be great if this module could be compatible.
Strong +1 on this!
For a few years I've asked for PyCQA/isort#574 which would make this little flake8 plugin's life so much easier, seems it is not getting any followup though ๐
Understood ๐ค didnโt noticed that.
In the meantime, would you be ok in just making flake8-isort
depend on isort[pyproject]
instead of on plain isort
?
Would that solve the problem?
@sanjioh I don't see what we would gain with adding dependencies on flake8-isort
. If I got it right, what we are missing now is that projects can store their isort
configuration on a pyproject.toml
file which flake8-isort
is not aware of.
We need to update https://github.com/gforcada/flake8-isort/blob/master/flake8_isort.py#L94
@gforcada It looks like isort picks up any config in pyproject.toml
if present (and if toml
is installed), without flake8-isort
having to know.
To reproduce (using a virtualenv):
- pyproject.toml
[tool.isort]
line_length = 10
- test.py
from configparser import ConfigParser
-
pip install flake8 flake8-isort
-
without
toml
installed:
$ flake8 test.py --no-isort-config
test.py:1:1: F401 'configparser.ConfigParser' imported but unused
- with
toml
installed (as perisort[pyproject]
extra):
$ pip install toml
$ flake8 test.py --no-isort-config
test.py:1:1: I001 isort found an import in the wrong position
test.py:1:1: F401 'configparser.ConfigParser' imported but unused
Am I missing something? ๐ค
Thanks for your replies ๐
Oh, I see, despite that we pass where the configuration is, isort
still looks for it and formats accordingly to that.
Then yes, ๐ on adding the dependency.
Now I'm curious if we actually have to do all the mambo jumbo to get the configuration, if anyway isort
already looks for it ๐ค
This probably needs to be reopened.
I went through the code and did not see it acutally looking for the pyproject.toml file.
The original:
# Check for '[isort]' section in other configuration files.
for config_file in ('tox.ini', 'setup.cfg', '.flake8'):
config_file_path = os.path.join(path, config_file)
config = SafeConfigParser()
config.read(config_file_path)
if 'isort' in config.sections():
return config_file_path
My modified one that finds the file:
# Check for '[isort]' section in other configuration files.
for config_file in ('tox.ini', 'setup.cfg', '.flake8', 'pyproject.toml'):
config_file_path = os.path.join(path, config_file)
config = SafeConfigParser()
config.read(config_file_path)
if 'isort' in config.sections():
return config_file_path
if 'tool.isort' in config.sections():
return config_file_path
If I am understanding it right then all that is needed this side is the path to send to isort? There is no other logic done to the configuration?
If so I will happily make a PR for this. Still don't know what to do with the tests as they do pass with the previous behaviour as well.
I totally missed this last comment, thanks @mikewl for it! A PR is always welcome, thanks in advance! ๐
I will try getting to this over the weekend.
I need to spend some time figuring out why the tests were passing in the first place so that the tests fail appropriately on the current version too.
Thank you so much for this awesome plugin.
I'm still getting "I002 no configuration found (.isort.cfg or [isort] in configs)" when I try to run flake8 and isort configuration is only in pyproject.toml
I'm using the isort 4.3.21 and flake8-isort 2.8.0
Thanks