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

Issue #227, Feature/pathformat, adds --absolute-paths option #230

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ vulture.egg-info/
.pytest_cache/
.tox/
.venv/
.idea/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# unreleased

* added --absolute-paths option to have vulture output absolute paths instead of relative paths (mcooperman, #227)
changed git signing key to correct verification

* Only parse format strings when being used with `locals()` (jingw, #225).

# 2.1 (2020-08-19)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ ignore_names = ["visit_*", "do_*"]
make_whitelist = true
min_confidence = 80
sort_by_size = true
absolute_paths = false
verbose = true
paths = ["myscript.py", "mydir"]
```
Expand Down
5 changes: 5 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_cli_args():
ignore_names=["name1", "name2"],
make_whitelist=True,
min_confidence=10,
absolute_paths=True,
sort_by_size=True,
verbose=True,
)
Expand All @@ -39,6 +40,7 @@ def test_cli_args():
"--min-confidence=10",
"--sort-by-size",
"--verbose",
"--absolute-paths",
"path1",
"path2",
]
Expand Down Expand Up @@ -97,6 +99,7 @@ def test_config_merging():
min_confidence = 10
sort_by_size = false
verbose = false
absolute_paths = true
paths = ["toml_path"]
"""
)
Expand All @@ -108,6 +111,7 @@ def test_config_merging():
"--make-whitelist",
"--min-confidence=20",
"--sort-by-size",
"--absolute-paths",
"--verbose",
"cli_path",
]
Expand All @@ -120,6 +124,7 @@ def test_config_merging():
make_whitelist=True,
min_confidence=20,
sort_by_size=True,
absolute_paths=True,
verbose=True,
)
assert result == expected
Expand Down
26 changes: 26 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
"""module: test-utils"""

# standard imports
import ast
import pathlib

# external imports

# local imports
from vulture import utils


def check_paths(filename, absolute=False):
pathstr = utils.format_path(filename, absolute)
# platform dependencies and path types need to be accounted for
pp = pathlib.PurePath(pathstr)
check = pp.is_absolute()
if absolute:
assert check
# even if absolute == True, the path might have been specified absolute
# so can't conclude negatively


def test_absolute_path():
check_paths(__file__, absolute=True)


def test_relative_path():
check_paths(__file__, absolute=False)


def check_decorator_names(code, expected_names):
decorator_names = []

Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ deps =
flake8-2020
flake8-bugbear
flake8-comprehensions
flake8_formatter_abspath
pyupgrade
whitelist_externals =
bash
commands =
black --check --diff .
flake8 setup.py tests/ vulture/
flake8 --format=abspath setup.py tests/ vulture/
bash -c "pyupgrade --py36-plus `find dev/ tests/ vulture/ -name '*.py'` setup.py"

[testenv:fix-style]
Expand Down
2 changes: 2 additions & 0 deletions vulture/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""module: __main__"""

from vulture.core import main

main()
9 changes: 9 additions & 0 deletions vulture/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"make_whitelist": False,
"sort_by_size": False,
"verbose": False,
"absolute_paths": False,
}


Expand Down Expand Up @@ -69,6 +70,7 @@ def _parse_toml(infile):
make_whitelist = true
min_confidence = 10
sort_by_size = true
absolute_paths = false
verbose = true
paths = ["path1", "path2"]
"""
Expand Down Expand Up @@ -149,6 +151,13 @@ def csv(exclude):
default=missing,
help="Sort unused functions and classes by their lines of code.",
)
parser.add_argument(
"--absolute-paths",
action="store_true",
default=False,
required=False,
help="Output absolute file paths.",
)
parser.add_argument(
"-v", "--verbose", action="store_true", default=missing
)
Expand Down
Loading