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

feat(python_file_finder): improve ignore handling #908

Merged
merged 4 commits into from
Oct 29, 2024

Conversation

mkniewallner
Copy link
Collaborator

@mkniewallner mkniewallner commented Oct 21, 2024

Closes #882.

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes

Currently, if a .gitignore file is hanging around in a parent directory that is outside a git repository, deptry will read it. Thinking this through, I believe we should simply avoid reading any .gitignore altogether if not in a git repository, by not disabling require_git. This is in line with what many tools do in the Python ecosystem, one such example being Ruff.

The positive side-effect of doing that is that when in a git repository, ignore crate will only read parents directories to find gitignore files up to when it finds a .git directory, fixing the use case reported in the issue. Newly added tests demonstrate that this fixes the issue.

Copy link

codecov bot commented Oct 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.6%. Comparing base (d9a1ba1) to head (ca9e39b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #908   +/-   ##
=====================================
  Coverage   92.6%   92.6%           
=====================================
  Files         37      37           
  Lines       1006    1006           
  Branches      99      99           
=====================================
  Hits         932     932           
  Misses        59      59           
  Partials      15      15           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mkniewallner mkniewallner force-pushed the fix/correctly-handle-gitignore branch from 509f541 to d5d737f Compare October 21, 2024 22:31
@mkniewallner mkniewallner changed the title fix(python_file_finder): correctly handle gitignore feat(python_file_finder): improve ignore handling Oct 22, 2024
@mkniewallner mkniewallner force-pushed the fix/correctly-handle-gitignore branch 3 times, most recently from 7eb7c5d to 4361f55 Compare October 22, 2024 22:41
@mkniewallner mkniewallner added breaking Change that introduces a breaking change enhancement New feature or request labels Oct 22, 2024
@@ -61,9 +61,8 @@ fn build_walker(

walk_builder
.types(build_types(ignore_notebooks).unwrap())
.standard_filters(use_git_ignore)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.rs/ignore/0.4.23/ignore/struct.WalkBuilder.html#method.standard_filters

All the options that standard_filters set are enabled by default anyway, so this does not change the current behaviour when not overriding exclusion list. But when overriding it, this allows disabling everything related to ignore (because there actually is more than .gitignore at play).

@mkniewallner mkniewallner force-pushed the fix/correctly-handle-gitignore branch from 4217bf7 to 17a3031 Compare October 29, 2024 12:30
@mkniewallner mkniewallner enabled auto-merge (squash) October 29, 2024 12:30
@mkniewallner mkniewallner disabled auto-merge October 29, 2024 13:02
@mkniewallner mkniewallner force-pushed the fix/correctly-handle-gitignore branch from 17a3031 to ca9e39b Compare October 29, 2024 13:07
@mkniewallner mkniewallner merged commit 919e33a into main Oct 29, 2024
22 checks passed
@mkniewallner mkniewallner deleted the fix/correctly-handle-gitignore branch October 30, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Change that introduces a breaking change enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.gitignore from parent git repository is used while it shouldn't
2 participants