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

Take possible .gitignore into account for skipping files #20

Open
1 task
roskakori opened this issue Jun 20, 2019 · 6 comments
Open
1 task

Take possible .gitignore into account for skipping files #20

roskakori opened this issue Jun 20, 2019 · 6 comments
Milestone

Comments

@roskakori
Copy link
Owner

roskakori commented Jun 20, 2019

Goals

  • If a .gitignore file is available, use it to skip files.

Implementation notes

The approach currently used by isort.settings is to first collecting the paths of all possible files in the project and then passing them through git check-ignore -z --stdin.

This would be relatively easy to implement and also simplify the implementation of #59 and #71. At least when using a naive way where the whole list of files is kept in memory, even including the ones that are later to be ignored.

With projects that have a large amount of ignored files (e.g. game development after baking assets into a build folder or complex projects with compiled languages and files like *.o or *.class) the scanning step would be much slower than before.

Probably its still worth it as the recommendation still stands to run pygount before the build, where fewer ignored files are lying around. And at a later point, someone else can step in and make a more ambitious implementation based on a recursive generator function that can evaluate each file and folder to be scanned one-by-one using something like gitignore-parser.

@roskakori roskakori added this to the v1.0.1 milestone Jun 20, 2019
@roskakori roskakori self-assigned this Jun 20, 2019
@roskakori roskakori changed the title Take possible .gitignire into account for skipping files Take possible .gitignore into account for skipping files Jun 20, 2019
@adam-moss
Copy link

This would be an useful feature, and would avoid the need to specify --folders-to-skip and --files-to-skip which can be a challenge to get right if processing lots of repos.

@roskakori
Copy link
Owner Author

@adam-moss In practice I've used pygount on a clean checkout when nothing has been built yet. Also I have not yet found a compelling gitignore Python library with a function that simply returns all non ignored files from a folder and it subfolders.

So currently there are no specific plans for this feature.

@adam-moss
Copy link

Agree that is a simpler approach more generally 👍

@roskakori
Copy link
Owner Author

Status update: I looked into how isort gitignores files and added some implementation notes to the original description. It's not pretty but might just work good enough.

@damif94
Copy link

damif94 commented Mar 18, 2022

Sorry I just find this thread; I was also thinking this could be a useful feature.

So it would just be to replicate the gitignore-based path exclusion logic from isort inside the SourceScanner and use it in folders_to_skip?

Maybe I can handle that

@roskakori
Copy link
Owner Author

So it would just be to replicate the gitignore-based path exclusion logic from isort inside the SourceScanner and use it in folders_to_skip?

I'm currently leaning towards reworking the whole SourceScanner without concerns about backwards compatibility for the semi working and mostly confusing --folders_to_skip. Would probably need to bump the semantic version to 2.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🆕 New
Development

No branches or pull requests

3 participants