isort
isort copied to clipboard
--exclude CLI flag to exclude files and directories from being scanned.
Basically like the --exclude regex_pattern flag in black and flake8 etc, where directories and files are matched with the regular expression provided to check whether they should be excluded for recursive searches.
I think isort already supports this via skip-glob in which case the action item for this ticket would change a bit into:
- Improve the documentation so that skip-glob is a more obvious feature.
- Add an
--excludealias to the CLI for skip-glob
@timothycrosley yeah I guess that the documentation could be improved for skip-glob, I at least didn't get this at first read. Also making an alias will be good as many tools like isort have this --exclude flag to skip files/directories from the CLI.
:+1: for the --exclude alias.
Maybe also consider deprecating skip-glob?
I think deprecating is a good idea, long term it makes sense to only have one obvious and correct way to change any knob, so we could add a deprecation notice in 5.7.0 and then remove the old behaviour in 6.0.0
I found that skip-glob option is confusing, because it doesn't work like real glob. It simply treats single * as .* in regexp. Isort currently uses fnmatch with this behavior documented here fnmatch
Here some examples of user configs . As you can see some of them relying on single * capturing all while others using double ** like in glob.
Therefore behavior can't be changed to Unix like glob in minor release because it will break current users with configs like this https://github.com/fKunstner/qparse/blob/86a7191c4a9d474a7bad6ea637971b3625a25321/.isort.cfg#L7 .
I found this issue when integration tests on my PR were failing on apache/airflow repo. They also used ignore-glob as real glob which lead to inconsistencies with pre-commit. I made PR in their repo to fix it.
We should consider it when implementing --exclude flag. I see 2 options:
- Leave current behavior. Confusion might go away because there will be no glob word in --exclude flag
- Implement --exclude differently, so that Unix style with single * and double ** is supported. python's glob module docs for reference
It would be great if isort could support regex as well in addition to glob.