Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--skip does not seem to work for specified subdirectories #1685

Closed
Jackenmen opened this issue Mar 6, 2021 · 3 comments
Closed

--skip does not seem to work for specified subdirectories #1685

Jackenmen opened this issue Mar 6, 2021 · 3 comments

Comments

@Jackenmen
Copy link

Jackenmen commented Mar 6, 2021

Let's say you have a tree like this:

+ SomeFolder
+- pyproject.toml
+- directory
 +- subdirectory
  +- file.py

With contents of the files:

  • pyproject.toml
[tool.isort]
skip = [
    "directory/subdirectory"
]
filter_files = true
  • directory/subdirectory/file.py
import os
import collections

When using a command isort directory\subdirectory\file.py, the file directory/subdirectory/file.py gets fixed by isort.

If you change directory/subdirectory in pyproject.toml to be just directory, isort does not touch the directory/subdirectory/file.py, but I was unable to get isort to ignore directory/subdirectory.

As a workaround, you can use skip_glob with directory/subdirectory/* pattern, but it does seem like a bug to me, considering that this work fine for top-level directories.

@gofr
Copy link
Contributor

gofr commented Mar 11, 2021

This is where that logic is implemented (and the next 10 lines):

for skip_path in self.skip:

Files are skipped using skip in two ways:

  1. The normalized, absolutized path of a file matches the normalized, absolutized path of a skip item. E.g. you could specify directory/subdirectory/file.py to skip just that file.
  2. A single component in the relative path of a file matches a skip item. This is why directory works, not because it's a top-level directory. subdirectory would also work, but this skips all directories with that name if you have more than one.

I guess there are two ways to go here:

  • Improve the documentation to clarify that only the above two things work, and if you want something else you should use skip_glob, since that can already do what you need.
  • Expand (1) above to also match paths to directories, not just files.

@gofr
Copy link
Contributor

gofr commented Mar 11, 2021

One pull request for each of the two options I mentioned. The one that changes the implementation would need some tests at least, and some Windows fixes, but leaving them for now...

timothycrosley added a commit that referenced this issue Mar 13, 2021
@Jackenmen
Copy link
Author

Seems like this has been fixed with documentation in #1689 so I'm gonna close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants