Configuring isort and autoflake with project.toml

13.7k views Asked by At

I have a series of tools running locally and on Jenkins to check and format my Python code:

  • autoflake
  • isort
  • black

I use pyproject.toml file to configure black, isort with .isort.cfg and autoflake with command line parameters because I haven't found any support to configure it with a configuration file.

Is there way to configure also isort and autoflake with pyproject.toml?

I would like to have all tools configured with just a single file.

2

There are 2 answers

0
subdavis On BEST ANSWER

isort configuration can be found at https://pycqa.github.io/isort/docs/configuration/options.html

In general, config params are separated by underscores. The example below will provide configuration that makes black and isort compatible, as discussed here https://copdips.com/2020/04/making-isort-compatible-with-black.html

[tool.isort]
multi_line_output = 3
line_length = 88
include_trailing_comma = true

[tool.black]
line_length = 88
1
David Ross On

You can just move your isort config to pyproject.toml but change [settings] to [tool.isort].

https://github.com/timothycrosley/isort#configuring-isort

I don't believe autoflake supports pyproject.toml configuration. You are welcome to open an issue on their github page.