Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify directories to isort with config file?

Tags:

python

isort

How can I specify which files to sort using isort using only the config file? I want to be able to isort . and have it only pick up certain target directories. I'm using pyproject.toml and i've tried

[tool.isort]
profile = "black"
src_paths = ["src", "test"]

and

[tool.isort]
profile = "black"
sources = ["src", "test"]

and

[tool.isort]
profile = "black"
directory = ["src", "test"]

to no avail

like image 255
joel Avatar asked Oct 15 '25 22:10

joel


1 Answers

I have checked source code of isort am afraid this is as of now it's not possible.

Closest you can get is when using pipenv shortcuts (ofc if used pipenv as package manager) and setup isort shortcut in Pipfile, like:

[scripts]
isort = "isort src tests"

And then call isort using pipenv run isort which will fix all files in both src and tests dirs.

You can as well chain the scripts, so you can e.g. define second script isort_check in Pipfile, which will just check and not correct isort issues:

[scripts]
isort = "isort src test"
isort_check = "pipenv run isort --check-only --diff --color"

Usage will be pipenv run isort_check which proves configuration of directories is defined just in one place (Single Source of Truth principle.)

like image 75
David Navrkal Avatar answered Oct 18 '25 14:10

David Navrkal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!