From 5fafd422382145e974176000ed839e1966a3608c Mon Sep 17 00:00:00 2001 From: mirecl Date: Tue, 4 Apr 2023 15:00:58 +0300 Subject: [PATCH 1/8] Add the ability to use the full path for exclude folder/file --- vulture/core.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vulture/core.py b/vulture/core.py index 16c71948..a96f19c5 100644 --- a/vulture/core.py +++ b/vulture/core.py @@ -2,6 +2,7 @@ from fnmatch import fnmatch, fnmatchcase from pathlib import Path import pkgutil +import os import re import string import sys @@ -261,6 +262,11 @@ def handle_syntax_error(e): def scavenge(self, paths, exclude=None): def prepare_pattern(pattern): + if pattern.startswith('./') is True: + pattern = os.path.abspath(pattern) + if os.path.isfile(pattern) is False: + pattern = f"{pattern}/*" + return pattern if not any(char in pattern for char in "*?["): pattern = f"*{pattern}*" return pattern From 41f5d8468cb5caf542125a3a135447bdcf8f51e1 Mon Sep 17 00:00:00 2001 From: mirecl Date: Tue, 4 Apr 2023 15:20:35 +0300 Subject: [PATCH 2/8] Fix linter pattern.startswith("./") --- vulture/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vulture/core.py b/vulture/core.py index a96f19c5..0835150d 100644 --- a/vulture/core.py +++ b/vulture/core.py @@ -262,7 +262,7 @@ def handle_syntax_error(e): def scavenge(self, paths, exclude=None): def prepare_pattern(pattern): - if pattern.startswith('./') is True: + if pattern.startswith("./") is True: pattern = os.path.abspath(pattern) if os.path.isfile(pattern) is False: pattern = f"{pattern}/*" From bbac147a153be3b3ef64aa66668be4025eecdd9e Mon Sep 17 00:00:00 2001 From: mirecl Date: Tue, 4 Apr 2023 15:52:10 +0300 Subject: [PATCH 3/8] Add test case for ./ exclude --- tests/test_script.py | 4 ++++ vulture/core.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_script.py b/tests/test_script.py index b57b5d02..25a06b35 100644 --- a/tests/test_script.py +++ b/tests/test_script.py @@ -62,6 +62,10 @@ def call_vulture_with_excludes(excludes): return call_vulture(["vulture/", "--exclude", get_csv(excludes)]) assert call_vulture_with_excludes(["core.py", "utils.py"]) == 1 + assert ( + call_vulture_with_excludes(["./vulture/core.py", "./vulture/utils.py"]) + == 0 + ) assert call_vulture_with_excludes(glob.glob("vulture/*.py")) == 0 diff --git a/vulture/core.py b/vulture/core.py index 0835150d..0930470b 100644 --- a/vulture/core.py +++ b/vulture/core.py @@ -264,7 +264,7 @@ def scavenge(self, paths, exclude=None): def prepare_pattern(pattern): if pattern.startswith("./") is True: pattern = os.path.abspath(pattern) - if os.path.isfile(pattern) is False: + if pattern.endswith('.py') is False: pattern = f"{pattern}/*" return pattern if not any(char in pattern for char in "*?["): From 386f345fe9e56749f0fa17ff3e326ebfdbbaf4f2 Mon Sep 17 00:00:00 2001 From: mirecl Date: Tue, 4 Apr 2023 15:58:45 +0300 Subject: [PATCH 4/8] Fix linter for pattern.endswith(".py") --- vulture/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vulture/core.py b/vulture/core.py index 0930470b..717e6f55 100644 --- a/vulture/core.py +++ b/vulture/core.py @@ -264,7 +264,7 @@ def scavenge(self, paths, exclude=None): def prepare_pattern(pattern): if pattern.startswith("./") is True: pattern = os.path.abspath(pattern) - if pattern.endswith('.py') is False: + if pattern.endswith(".py") is False: pattern = f"{pattern}/*" return pattern if not any(char in pattern for char in "*?["): From 068185cd97ad764d426a23eacfece8b67e281f4b Mon Sep 17 00:00:00 2001 From: mirecl Date: Tue, 4 Apr 2023 16:47:16 +0300 Subject: [PATCH 5/8] Fix test case for exclude --- tests/test_script.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_script.py b/tests/test_script.py index 25a06b35..89b6c5c5 100644 --- a/tests/test_script.py +++ b/tests/test_script.py @@ -62,10 +62,7 @@ def call_vulture_with_excludes(excludes): return call_vulture(["vulture/", "--exclude", get_csv(excludes)]) assert call_vulture_with_excludes(["core.py", "utils.py"]) == 1 - assert ( - call_vulture_with_excludes(["./vulture/core.py", "./vulture/utils.py"]) - == 0 - ) + assert call_vulture_with_excludes(["./core.py", "./whitelists"]) == 0 assert call_vulture_with_excludes(glob.glob("vulture/*.py")) == 0 From 1ab3494d71424fb7e3249f0d3d0a904b1a390517 Mon Sep 17 00:00:00 2001 From: mirecl Date: Tue, 4 Apr 2023 17:11:54 +0300 Subject: [PATCH 6/8] Add test_exclude_abs_path --- tests/test_script.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/test_script.py b/tests/test_script.py index 89b6c5c5..dad9b7f2 100644 --- a/tests/test_script.py +++ b/tests/test_script.py @@ -54,6 +54,18 @@ def test_min_confidence(): ) +def test_exclude_abs_path(): + assert ( + call_vulture( + [ + "vulture", + "--exclude=./core.py,./whitelists", + ] + ) + == 0 + ) + + def test_exclude(): def get_csv(paths): return ",".join(os.path.join("vulture", path) for path in paths) @@ -62,7 +74,6 @@ def call_vulture_with_excludes(excludes): return call_vulture(["vulture/", "--exclude", get_csv(excludes)]) assert call_vulture_with_excludes(["core.py", "utils.py"]) == 1 - assert call_vulture_with_excludes(["./core.py", "./whitelists"]) == 0 assert call_vulture_with_excludes(glob.glob("vulture/*.py")) == 0 From 579f7a4253e757e9d12fd740c028e9ebb2d08aa9 Mon Sep 17 00:00:00 2001 From: Jendrik Seipp Date: Sun, 24 Nov 2024 20:40:40 +0100 Subject: [PATCH 7/8] Update vulture/core.py --- vulture/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vulture/core.py b/vulture/core.py index 717e6f55..39bf7629 100644 --- a/vulture/core.py +++ b/vulture/core.py @@ -264,7 +264,8 @@ def scavenge(self, paths, exclude=None): def prepare_pattern(pattern): if pattern.startswith("./") is True: pattern = os.path.abspath(pattern) - if pattern.endswith(".py") is False: + if os.path.isdir(pattern): + pattern = os.path.join(pattern, "*") pattern = f"{pattern}/*" return pattern if not any(char in pattern for char in "*?["): From 523dc373264feb76c23dc308a36901d67c21368d Mon Sep 17 00:00:00 2001 From: Jendrik Seipp Date: Sun, 24 Nov 2024 20:40:55 +0100 Subject: [PATCH 8/8] Update vulture/core.py --- vulture/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vulture/core.py b/vulture/core.py index 39bf7629..92442c64 100644 --- a/vulture/core.py +++ b/vulture/core.py @@ -262,7 +262,7 @@ def handle_syntax_error(e): def scavenge(self, paths, exclude=None): def prepare_pattern(pattern): - if pattern.startswith("./") is True: + if pattern.startswith("./"): pattern = os.path.abspath(pattern) if os.path.isdir(pattern): pattern = os.path.join(pattern, "*")