From d0473528984c1d5f6d97d30bea9aaf79fa04d4f9 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sun, 17 Nov 2024 16:09:33 +0100 Subject: [PATCH] Add Vulture (dead code detector) (#2471) --- .github/workflows/issues.py | 11 ++++++++--- HISTORY.rst | 6 ++++++ Makefile | 11 ++++++++--- psutil/tests/test_testutils.py | 2 +- pyproject.toml | 12 ++++++++++++ setup.py | 7 +++++-- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/.github/workflows/issues.py b/.github/workflows/issues.py index 5e8c2026f..9566fa119 100755 --- a/.github/workflows/issues.py +++ b/.github/workflows/issues.py @@ -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"], @@ -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", ], } diff --git a/HISTORY.rst b/HISTORY.rst index f69375e45..8d636de3a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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. diff --git a/Makefile b/Makefile index 79ad8c8c6..8ddb7c42c 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 # =================================================================== diff --git a/psutil/tests/test_testutils.py b/psutil/tests/test_testutils.py index e11c8f783..1c83a94c6 100755 --- a/psutil/tests/test_testutils.py +++ b/psutil/tests/test_testutils.py @@ -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): diff --git a/pyproject.toml b/pyproject.toml index 988ff9c01..35b5a31c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/setup.py b/setup.py index a7b7e8170..727677c49 100755 --- a/setup.py +++ b/setup.py @@ -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", @@ -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", @@ -106,6 +108,7 @@ "toml-sort", "twine", "virtualenv", + "vulture", "wheel", ] if WINDOWS: