Skip to content

skip and skip-glob are not enforced when using settings-path #909

Closed
@rsebille

Description

@rsebille

Hi,

Version used: 4.3.15, not tested on other versions.

Setup:

$ tree -a
.
├── conf
│   └── .isort.cfg
├── file_glob_skip.py
└── file_to_be_skipped.py

1 directory, 3 files
$ cat conf/.isort.cfg 
[isort]
skip =
    file_to_be_skipped.py
skip_glob =
    *glob_skip*
$ cat file_glob_skip.py 
import os

print("Hello World")

import sys
$ cat file_to_be_skipped.py 
import os

print("Hello World")

import sys

Files are not skipped when using --settings-path=conf/.isort.cfg:

$ isort --check-only --settings-path=conf/.isort.cfg
ERROR: /home/romain/Area51/isort_skip_bug/file_glob_skip.py Imports are incorrectly sorted.
ERROR: /home/romain/Area51/isort_skip_bug/file_to_be_skipped.py Imports are incorrectly sorted.

But works when using CLI options:

$ isort --check-only --skip file_to_be_skipped.py --skip-glob '*glob_skip*' 
Skipped 2 files

The problem seems to have two causes:

  1. check_skip is always set to False [1] which make SortImports not even trying any of the skip options [2] while the class use True as default for that argument [3]
  2. Options defined in a settings-path file are not used [4] by iter_source_code() [5], the config dict will only contain options a local .isort.cfg and CLI options.

[1] https://github.com/timothycrosley/isort/blob/4.3.15/isort/main.py#L320
[2] https://github.com/timothycrosley/isort/blob/4.3.15/isort/isort.py#L98
[3] https://github.com/timothycrosley/isort/blob/4.3.15/isort/isort.py#L51
[4] https://github.com/timothycrosley/isort/blob/4.3.15/isort/main.py#L348-L349
[5] https://github.com/timothycrosley/isort/blob/4.3.15/isort/main.py#L353

A bisect give me 91ae94e as first bad commit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions