isort: isort does not skip files

Describe the bug

isort does not respect skip and skip_glob configuration options.

To Reproduce

Steps to reproduce the behavior:

  1. Create file.py with the following content:
    import os, \
        sys
    
  2. Create .isort.cfg with the following content:
    [settings]
    skip_glob = file.py
    
  3. Run isort file.py.
  4. Open file.py and check out it’s content to become:
    import os
    import sys
    

Expected behavior

A file.py is skipped and is not touched.

Screenshots

Environment (please complete the following information):

  • OS: Linux
  • Python version: 3.7.2
  • isort version: 4.3.11

Additional context

isort 4.3.10 is working correctly. Issue can be reproduced with skip option as well.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 18
  • Comments: 29 (17 by maintainers)

Commits related to this issue

Most upvoted comments

I’m sorry for letting this regression slip in the last release! It took a while for me to untangle, but it should be fixed in the latest release (4.3.13) of isort, with additional testing put in place to try to ensure the regression is not reintroduced on the future.

Thanks!

~Timothy

@jparise,

Completely agree! I believe 4.3.18 may have included the exact flag that you are hoping for:

https://github.com/timothycrosley/isort/blob/develop/CHANGELOG.md#4318---may-1-2019---hot-fix-release:

--filter-files

Thanks!

~Timothy

There does appear to be a regression here. In version 4.3.10 the following works:

skip_glob = */migrations/*.py

In version 4.3.11 it now processes files such as karaage/migrations/0002_auto_20140924_1111.py. Will try to narrow it down to the commit.

Thanks for the tool, its great!

I believe the following should work for you: isort --check-only ~/Projects/foo/config/settings/base.py -vb --settings-path /Users/Silver/Projects/foo/ --filter-files

Oh, it drives me mad 😃

My setup.cfg located in ~/Projects/foo with the following contents:

[flake8]
max-line-length = 120
exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules

[pycodestyle]
max-line-length = 120
exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules

[mypy]
python_version = 3.7
check_untyped_defs = True
ignore_errors = False
ignore_missing_imports = True
strict_optional = True
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True

[mypy-*.migrations.*]
# Django migrations should not produce any errors:
ignore_errors = True

[tool:isort]
line_length=120
multi_line_output=3
include_trailing_comma=True
skip=migrations
skip_glob=*/node_modules/*,*/config/settings/*.py
known_first_party=myprojectnamehere
known_third_party=willow,modelcluster,taggit,unidecode,bs4,pytz,PIL
known_django=django
known_wagtail=wagtail
sections=FUTURE,STDLIB,DJANGO,WAGTAIL,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
default_section=THIRDPARTY

There is no .isort.cfg anywhere and neither .editorconfig contains anything related to isort.

Observed problem: Files within ~/Projects/foo/config/settings/ are not skipped. I’ve tried several combinations and it never works:

isort --check-only ~/Projects/foo/config/settings/base.py -vb --settings-path /Users/Silver/Projects/foo/

/#######################################################################\
....skipped
                            VERSION 4.3.21

\########################################################################/

from-type place_module for django.utils.translation returned DJANGO
else-type place_module for environ returned THIRDPARTY
SUCCESS: /Users/Silver/Projects/foo/config/settings/base.py Everything Looks Good!

isort version: 4.3.21 @timothycrosley what I’m doing wrong?

Forget what I just said (and deleted). Me confused.

First bad commit is 2c59158602f5d36d88c32cefe7e14a3963068c9e in #878.

Note this commit was hard to test, because it contained unrelated errors fixed in subsequent commits.

Hi @timothycrosley

I’m curious about the use case where you want to skip files based on a config, but then explicitly pass them in?

we rely on this behavior in our project. Our use case is next:

  1. in our configuration file we have the following path: */migrations/* to skip imports codestyle check for auto-generated migrations all the time
  2. we have automation script for tracking changes between the current and previous successful build and run isort only for those specific files. Any changelog might contain any number of files including migrations, but we still want to skip migration during codestyle check. So, unfortunately, described changes introduce a regression for our case 😦

Does that make sense?