Skip to content

Commit

Permalink
Revert "Read exclude patterns from .gitignore in absence of user-prov…
Browse files Browse the repository at this point in the history
…ided patterns (#344) (#345)"

This reverts commit aa6fcd2.

After further thought, the --exclude flag and .gitignore file
have different responsibilities and mixing them will surprise
some users.
  • Loading branch information
jendrikseipp committed Jan 6, 2024
1 parent 458be54 commit e20349b
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 79 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Bump flake8, flake8-comprehensions and flake8-bugbear (Sebastian Csar, #341).
* Switch to tomllib/tomli to support heterogeneous arrays (Sebastian Csar, #340).
* Provide whitelist parity for `MagicMock` and `Mock` (maxrake).
* Use .gitignore to exclude files if --exclude is missing from both pyproject.toml and the command line (whosayn, #344, #345).
* Properly detect when no .gitignore is present (travisdart, #346).

# 2.10 (2023-10-06)

Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ If you want to ignore a whole file or directory, use the `--exclude` parameter
(e.g., `--exclude "*settings.py,*/docs/*.py,*/test_*.py,*/.venv/*.py"`). The
exclude patterns are matched against absolute paths.

Vulture 2.11+ parses the `.gitignore` file in the current working directory for
exclude patterns if the `--exclude` parameter is unused and if there are no
exclude patterns in the pyproject.toml file.

#### Flake8 noqa comments

<!-- Hide noqa docs until we decide whether we want to support it.
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pathspec >= 0.12.1
tomli >= 1.1.0; python_version < '3.11'
56 changes: 0 additions & 56 deletions tests/test_gitignore_patterns.py

This file was deleted.

17 changes: 1 addition & 16 deletions vulture/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import string
import sys

from pathspec import PathSpec
from vulture import lines
from vulture import noqa
from vulture import utils
Expand Down Expand Up @@ -115,13 +114,6 @@ def _ignore_variable(filename, varname):
)


def _get_gitignore_pathspec():
if (gitignore := Path(".gitignore").resolve()).is_file():
with gitignore.open() as fh:
return PathSpec.from_lines("gitwildmatch", fh)
return PathSpec.from_lines("gitwildmatch", [])


class Item:
"""
Hold the name, type and location of defined code.
Expand Down Expand Up @@ -271,16 +263,9 @@ def prepare_pattern(pattern):
return pattern

exclude = [prepare_pattern(pattern) for pattern in (exclude or [])]
gitignore = _get_gitignore_pathspec()

def exclude_path(path):
# If no exclude patterns are provided via the CLI or
# a TOML file, use .gitignore patterns to inform exclusion.
return (
_match(path, exclude, case=False)
if exclude
else gitignore.match_file(path)
)
return _match(path, exclude, case=False)

paths = [Path(path) for path in paths]

Expand Down

0 comments on commit e20349b

Please sign in to comment.