diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index bc03905ab2bbd..1cb8633545995 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -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 diff --git a/.gitignore b/.gitignore index 99939ff7fce0c..65ccbe93ab378 100644 --- a/.gitignore +++ b/.gitignore @@ -154,7 +154,3 @@ cifar-10-batches-py *.pt # ctags tags -data -MNIST -runs -*trace* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b7dcc232e66d6..b878b4e750191 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/pyproject.toml b/pyproject.toml index e8a3213f2b738..1f21e1f088acb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/pytorch_lightning/profiler/pytorch.py b/pytorch_lightning/profiler/pytorch.py index fa2c2917f98a2..5b3a5a105cf3a 100644 --- a/pytorch_lightning/profiler/pytorch.py +++ b/pytorch_lightning/profiler/pytorch.py @@ -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()