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

Created on 6 Oct 2020  路  5Comments  路  Source: PyCQA/isort

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.

documentation enhancement

All 5 comments

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 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:
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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghickman picture ghickman  路  3Comments

adaamz picture adaamz  路  3Comments

kevindaum picture kevindaum  路  4Comments

akaihola picture akaihola  路  3Comments

ionelmc picture ionelmc  路  3Comments