Skip to content

Commit

Permalink
Added Vulture dead code checker (#5654)
Browse files Browse the repository at this point in the history
* 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 <rahul722j@gmail.com>

* [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 <aniket.maurya@gdn-commerce.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: chaton <thomas@grid.ai>
Co-authored-by: Rahul Jha <rahul722j@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ethan Harris <ewah1g13@soton.ac.uk>
Co-authored-by: Ethan Harris <ethanwharris@gmail.com>
  • Loading branch information
8 people authored Jun 2, 2021
1 parent 0a72fd2 commit 0bad218
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,23 @@ jobs:
- name: mypy check
run: |
mypy
dead-code-vulture:
name: Python dead code checker
runs-on: ubuntu-20.04

# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Install dependencies
run: pip install vulture && pip list

- name: Check for dead code with Vulture
run: |
vulture pytorch_lightning
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,3 @@ cifar-10-batches-py
*.pt
# ctags
tags
data
MNIST
runs
*trace*
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ repos:
name: Format code
language: python

- repo: https://github.com/jendrikseipp/vulture
rev: 'v2.3'
hooks:
- id: vulture

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
Expand Down
25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,28 @@ profile = "black"
line_length = 120
force_sort_within_sections = "False"
order_by_type = "False"

[tool.vulture]
exclude = ['pytorch_lightning/metrics']
make_whitelist = true
min_confidence = 95
paths = ["pytorch_lightning"]
ignore_names = [
"*_nb",
"*batch",
"*idx",
"*param*",
"cmd_line",
"kw",
"loc",
"mocked_device_count*",
"my_path",
"new_device",
"new_dtype",
"prediction",
"root",
"signum",
"torch_save",
"using_lbfgs",
]
sort_by_size = true
2 changes: 1 addition & 1 deletion pytorch_lightning/profiler/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __enter__(self) -> None:

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

def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
def __exit__(self, type: Any, value: Any, traceback: Any) -> None:
for handles in self._handles.values():
for h in handles:
h.remove()
Expand Down

0 comments on commit 0bad218

Please sign in to comment.