isort icon indicating copy to clipboard operation
isort copied to clipboard

--exclude CLI flag to exclude files and directories from being scanned.

Open anirudnits opened this issue 5 years ago • 6 comments

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.

anirudnits avatar Oct 06 '20 19:10 anirudnits

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 --exclude alias to the CLI for skip-glob

timothycrosley avatar Oct 07 '20 03:10 timothycrosley

@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.

anirudnits avatar Oct 07 '20 03:10 anirudnits

:+1: for the --exclude alias.

Maybe also consider deprecating skip-glob?

sztamas avatar Oct 07 '20 05:10 sztamas

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

timothycrosley avatar Oct 07 '20 07:10 timothycrosley

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:

  1. Leave current behavior. Confusion might go away because there will be no glob word in --exclude flag
  2. Implement --exclude differently, so that Unix style with single * and double ** is supported. python's glob module docs for reference

timqsh avatar Oct 19 '20 14:10 timqsh

It would be great if isort could support regex as well in addition to glob.

govindrai avatar May 05 '22 21:05 govindrai