Skip to content

Commit 0bad218

Browse files
aniketmauryaAniket MauryaBordatchatonRJ722
authored
Added Vulture dead code checker (#5654)
* integrated vulture CI * added vulture in workflows * added vulture in workflows * vulture logs verbose set false * Apply suggestions from code review * ignore name list and args to underscore naming * add ignore names * deadcode whitelist * deadcode whitelist * Apply suggestions from code review Co-authored-by: Rahul Jha <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update whitelist * Sort * Updates * Updates * Apply suggestions from code review * Updates Co-authored-by: Aniket Maurya <[email protected]> Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: chaton <[email protected]> Co-authored-by: Rahul Jha <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ethan Harris <[email protected]> Co-authored-by: Ethan Harris <[email protected]>
1 parent 0a72fd2 commit 0bad218

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

.github/workflows/code-formatting.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,23 @@ jobs:
7474
- name: mypy check
7575
run: |
7676
mypy
77+
78+
dead-code-vulture:
79+
name: Python dead code checker
80+
runs-on: ubuntu-20.04
81+
82+
# Timeout: https://stackoverflow.com/a/59076067/4521646
83+
timeout-minutes: 10
84+
steps:
85+
- name: Checkout
86+
uses: actions/checkout@v2
87+
- uses: actions/setup-python@v2
88+
with:
89+
python-version: 3.7
90+
91+
- name: Install dependencies
92+
run: pip install vulture && pip list
93+
94+
- name: Check for dead code with Vulture
95+
run: |
96+
vulture pytorch_lightning

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,3 @@ cifar-10-batches-py
154154
*.pt
155155
# ctags
156156
tags
157-
data
158-
MNIST
159-
runs
160-
*trace*

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ repos:
3939
name: Format code
4040
language: python
4141

42+
- repo: https://github.com/jendrikseipp/vulture
43+
rev: 'v2.3'
44+
hooks:
45+
- id: vulture
46+
4247
- repo: https://github.com/PyCQA/flake8
4348
rev: 3.9.2
4449
hooks:

pyproject.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,28 @@ profile = "black"
1616
line_length = 120
1717
force_sort_within_sections = "False"
1818
order_by_type = "False"
19+
20+
[tool.vulture]
21+
exclude = ['pytorch_lightning/metrics']
22+
make_whitelist = true
23+
min_confidence = 95
24+
paths = ["pytorch_lightning"]
25+
ignore_names = [
26+
"*_nb",
27+
"*batch",
28+
"*idx",
29+
"*param*",
30+
"cmd_line",
31+
"kw",
32+
"loc",
33+
"mocked_device_count*",
34+
"my_path",
35+
"new_device",
36+
"new_dtype",
37+
"prediction",
38+
"root",
39+
"signum",
40+
"torch_save",
41+
"using_lbfgs",
42+
]
43+
sort_by_size = true

pytorch_lightning/profiler/pytorch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __enter__(self) -> None:
9090

9191
self._handles[module_name] = [pre_forward_handle, post_forward_handle]
9292

93-
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
93+
def __exit__(self, type: Any, value: Any, traceback: Any) -> None:
9494
for handles in self._handles.values():
9595
for h in handles:
9696
h.remove()

0 commit comments

Comments
 (0)