Skip to content

pre-commit matches any file ending in setup.py #503

@LordFckHelmchen

Description

@LordFckHelmchen

Describe the bug
The file-regex in the pre-commit hook matches more than just setup.py. This creates issues when having files like app_setup.py in a repo.

To Reproduce

  1. Create a clean repo
  2. touch test_setup.py
  3. install fawltydeps pre-commit hook
  4. run prek run --all-files check-unused

Expected behavior
No errors

Environment

  • OS Windows 1:
  • Version of the code v0.20.0

Additional context

The solution would be to safeguard the files to only match the full name, ie. instead of the existing pattern:

(.*requirements.*\.(txt|in)|pyproject\.toml|setup\.(py|cfg))

do

(^|.+(/|\\))(.*requirements.*\.(txt|in)|pyproject\.toml|setup\.(py|cfg))

which will require the files to be on root (^) or a subdirectory (adjusted for linux & windows fileseps)

This would successfully match

setup.py
sub/dir/setup.py
sub\dir\setup.py

setup.cfg
sub/dir/setup.cfg
sub\dir\setup.cfg

pyproject.toml
sub/dir/pyproject.toml
sub\dir\pyproject.toml

requirements.txt
sub/dir/requirements.txt
sub\dir\requirements.txt

dev_requirements.txt
sub/dir/dev_requirements.txt
sub\dir\dev_requirements.txt

requirements_prod.txt
sub/dir/requirements_prod.txt
sub\dir\requirements_prod.txt

requirements.in
sub/dir/requirements.in
sub\dir\requirements.in

dev_requirements.in
sub/dir/dev_requirements.in
sub\dir\dev_requirements.in

requirements_prod.in
sub/dir/requirements_prod.in
sub\dir\requirements_prod.in

But would not match

test_setup.py
sub\dir\test_setup.py
sub/dir/test_setup.py

testsetup.py
sub\dir\testsetup.py
sub/dir/testsetup.py

setup_test.py
sub\dir\setup_test.py
sub/dir/setup_test.py

setuptest.py
sub\dir\setuptest.py
sub/dir/setuptest.py

spyproject.toml
sub/dir/spyproject.toml
sub\dir\spyproject.toml

pyprojects.toml
sub/dir/spyprojects.toml
sub\dir\pyprojects.toml

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2major: an upcoming releasetype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions