Skip to content

Commit d3ff026

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24778: lint: Convert Python dead code linter test to Python
076cd68 lint: Convert Python dead code linter to Python (Fabian Jahr) Pull request description: The new python version should produce the exact same output as the bash version but be easier to maintain. ACKs for top commit: MarcoFalke: review ACK 076cd68 Tree-SHA512: 6d71a5230d612a981958fb6e178214240b09e842ffe35e207cbbda870ca35476626bf832f55d96f2fc7323a2875935edfee30cacef659a8e6ec4bbb28ff6e36a
2 parents 15220ec + 076cd68 commit d3ff026

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

test/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ Use the `-v` option for verbose output.
308308
| [`lint-python.sh`](lint/lint-python.sh) | [flake8](https://gitlab.com/pycqa/flake8)
309309
| [`lint-python.sh`](lint/lint-python.sh) | [mypy](https://github.com/python/mypy)
310310
| [`lint-python.sh`](lint/lint-python.sh) | [pyzmq](https://github.com/zeromq/pyzmq)
311+
| [`lint-python-dead-code.py`](lint/lint-python-dead-code.py) | [vulture](https://github.com/jendrikseipp/vulture)
311312
| [`lint-shell.sh`](lint/lint-shell.sh) | [ShellCheck](https://github.com/koalaman/shellcheck)
312313
| [`lint-spelling.sh`](lint/lint-spelling.sh) | [codespell](https://github.com/codespell-project/codespell)
313314

test/lint/lint-python-dead-code.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (c) 2022 The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
"""
8+
Find dead Python code.
9+
"""
10+
11+
from subprocess import check_output, STDOUT, CalledProcessError
12+
13+
FILES_ARGS = ['git', 'ls-files', '--', '*.py']
14+
15+
16+
def check_vulture_install():
17+
try:
18+
check_output(["vulture", "--version"])
19+
except FileNotFoundError:
20+
print("Skipping Python dead code linting since vulture is not installed. Install by running \"pip3 install vulture\"")
21+
exit(0)
22+
23+
24+
def main():
25+
check_vulture_install()
26+
27+
files = check_output(FILES_ARGS).decode("utf-8").splitlines()
28+
# --min-confidence 100 will only report code that is guaranteed to be unused within the analyzed files.
29+
# Any value below 100 introduces the risk of false positives, which would create an unacceptable maintenance burden.
30+
vulture_args = ['vulture', '--min-confidence=100'] + files
31+
32+
try:
33+
check_output(vulture_args, stderr=STDOUT)
34+
except CalledProcessError as e:
35+
print(e.output.decode("utf-8"), end="")
36+
print("Python dead code detection found some issues")
37+
exit(1)
38+
39+
40+
if __name__ == "__main__":
41+
main()

test/lint/lint-python-dead-code.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)