Skip to content

Commit

Permalink
Add Vulture (dead code detector) (#2471)
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo authored Nov 17, 2024
1 parent 66892b2 commit d047352
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
"/dev/pts", "posix",
],
"pypy": ["pypy"],
"docker": ["docker", "docker-compose"],
"vm": [
"docker", "docker-compose", "vmware", "lxc", "hyperv", "virtualpc",
"virtualbox", "bhyve", "openvz", "lxc", "xen", "kvm", "qemu", "heroku",
],
# types
"enhancement": ["enhancement"],
"memleak": ["memory leak", "leaks memory", "memleak", "mem leak"],
Expand All @@ -88,10 +93,10 @@
"continuous integration", "unittest", "pytest", "unit test",
],
# critical errors
"priority-high": [
"critical": [
"WinError", "WindowsError", "RuntimeError", "ZeroDivisionError",
"SystemError", "MemoryError", "core dumped",
"segfault", "segmentation fault",
"SystemError", "MemoryError", "core dump", "segfault",
"segmentation fault",
],
}

Expand Down
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

XXXX-XX-XX

**Enhancements**

- 2471_: use Vulture CLI tool to detect dead code.

**Bug fixes**

- 2470_, [Linux]: `users()`_ may return "localhost" instead of the actual IP
address of the user logged in.

Expand Down
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ ruff: ## Run ruff linter.
black: ## Run black formatter.
@git ls-files '*.py' | xargs $(PYTHON) -m black --check --safe

_pylint: ## Python pylint (not mandatory, just run it from time to time)
@git ls-files '*.py' | xargs $(PYTHON) -m pylint --rcfile=pyproject.toml --jobs=0

lint-c: ## Run C linter.
@git ls-files '*.c' '*.h' | xargs $(PYTHON) scripts/internal/clinter.py

Expand All @@ -193,6 +190,14 @@ lint-all: ## Run all linters
${MAKE} lint-rst
${MAKE} lint-toml

# --- not mandatory linters (just run from time to time)

pylint: ## Python pylint
@git ls-files '*.py' | xargs $(PYTHON) -m pylint --rcfile=pyproject.toml --jobs=0 $(ARGS)

vulture: ## Find unused code
@git ls-files '*.py' | xargs $(PYTHON) -m vulture $(ARGS)

# ===================================================================
# Fixers
# ===================================================================
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test_bind_unix_socket(self):
with contextlib.closing(sock):
assert sock.type == socket.SOCK_DGRAM

def tcp_tcp_socketpair(self):
def test_tcp_socketpair(self):
addr = ("127.0.0.1", get_free_port())
server, client = tcp_socketpair(socket.AF_INET, addr=addr)
with contextlib.closing(server):
Expand Down
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ disable = [
"wrong-import-position",
]

[tool.vulture]
exclude = [
"docs/conf.py",
"psutil/_compat.py",
"scripts/internal/winmake.py",
]
ignore_decorators = [
"@_common.deprecated_method",
"@atexit.register",
"@pytest.fixture",
]

[tool.rstcheck]
ignore_messages = [
"Duplicate explicit target name",
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
CP37_PLUS = PY37_PLUS and sys.implementation.name == "cpython"
Py_GIL_DISABLED = sysconfig.get_config_var("Py_GIL_DISABLED")

# Test deps, installable via `pip install .[test]`.
# Test deps, installable via `pip install .[test]` or
# `make install-pydeps-test`.
if PY3:
TEST_DEPS = [
"pytest",
Expand All @@ -87,7 +88,8 @@
TEST_DEPS.append("wheel")
TEST_DEPS.append("wmi")

# Development deps, installable via `pip install .[dev]`.
# Development deps, installable via `pip install .[dev]` or
# `make install-pydeps-dev`.
DEV_DEPS = [
"abi3audit",
"black",
Expand All @@ -106,6 +108,7 @@
"toml-sort",
"twine",
"virtualenv",
"vulture",
"wheel",
]
if WINDOWS:
Expand Down

0 comments on commit d047352

Please sign in to comment.