-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read exclude patterns from .gitignore in absence of user-provided pat…
…terns (#344) (#345) * Read exclude patterns from .gitignore in absence of user-provided patterns (#344) Use .gitignore to exclude files if --exclude is missing from both pyproject.toml and the command line. Vulture now requires the pathspec library to run. * Move dependencies to requirements.txt. --------- Co-authored-by: Jendrik Seipp <[email protected]>
- Loading branch information
1 parent
3d0ad1a
commit aa6fcd2
Showing
7 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pathspec >= 0.12.1 | ||
tomli >= 1.1.0; python_version < '3.11' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
import pathlib | ||
import pytest | ||
import shutil | ||
|
||
from . import call_vulture | ||
from vulture.utils import ExitCode | ||
|
||
|
||
class TempGitignore: | ||
def __init__(self, patterns): | ||
self.patterns = patterns | ||
root = pathlib.Path(".").resolve() | ||
self.file = root / ".gitignore" | ||
self.tmpfile = root / ".tmp_gitignore" | ||
|
||
def __enter__(self): | ||
shutil.move(self.file, self.tmpfile) | ||
with open(self.file, "w") as f: | ||
f.write("\n".join(self.patterns)) | ||
|
||
return self.file | ||
|
||
def __exit__(self, *args): | ||
os.remove(self.file) | ||
shutil.move(self.tmpfile, self.file) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def gitignore(request): | ||
with TempGitignore(request.param) as fpath: | ||
yield fpath | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"exclude_patterns,gitignore,exit_code", | ||
( | ||
([], [], ExitCode.NoDeadCode), | ||
([""], [], ExitCode.NoDeadCode), | ||
([], [""], ExitCode.NoDeadCode), | ||
([""], ["core.py", "utils.py"], ExitCode.NoDeadCode), | ||
(["core.py", "utils.py"], [""], ExitCode.DeadCode), | ||
([], ["core.py", "utils.py"], ExitCode.DeadCode), | ||
), | ||
indirect=("gitignore",), | ||
) | ||
def test_gitignore(exclude_patterns, gitignore, exit_code): | ||
def get_csv(paths): | ||
return ",".join(os.path.join("vulture", path) for path in paths) | ||
|
||
cli_args = ["vulture/"] | ||
if exclude_patterns: | ||
cli_args.extend(["--exclude", get_csv(exclude_patterns)]) | ||
|
||
assert gitignore.is_file() | ||
assert call_vulture(cli_args) == exit_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters