From 37e1340d8e556f3a0384a3952c63a8ea630fb4b8 Mon Sep 17 00:00:00 2001 From: Aniket Maurya Date: Tue, 26 Jan 2021 13:22:34 +0530 Subject: [PATCH 01/17] integrated vulture CI --- .pre-commit-config.yaml | 5 +++++ pyproject.toml | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f8cd909dfa01a..95939e3e9eb90 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,3 +32,8 @@ repos: rev: v0.790 hooks: - id: mypy + + - repo: https://github.com/jendrikseipp/vulture + rev: 'v2.3' # or any later Vulture version + hooks: + - id: vulture diff --git a/pyproject.toml b/pyproject.toml index b4b7c37531491..707f6ae74d848 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,3 +38,10 @@ profile = "black" line_length = 120 force_sort_within_sections = "False" order_by_type = "False" + +[tool.vulture] +make_whitelist = true +min_confidence = 80 +paths = ["pytorch_lightning"] +sort_by_size = true +verbose = true From 9c6f77c5450b1af2798f2f1c0b1a6c5019a93d98 Mon Sep 17 00:00:00 2001 From: Aniket Maurya Date: Tue, 26 Jan 2021 13:36:13 +0530 Subject: [PATCH 02/17] added vulture in workflows --- .github/workflows/code-formatting.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index c76901f39db81..b2242b595b9be 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -74,3 +74,24 @@ jobs: - name: mypy check run: | mypy + + python-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 + + - name: Run checking + run: | + vulture . From 539e3217b9d7afbc05cf28bd6a8f316fdaf3cda0 Mon Sep 17 00:00:00 2001 From: Aniket Maurya Date: Tue, 26 Jan 2021 13:38:48 +0530 Subject: [PATCH 03/17] added vulture in workflows --- .github/workflows/code-formatting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index b2242b595b9be..bfb47fb4d395f 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -94,4 +94,4 @@ jobs: - name: Run checking run: | - vulture . + vulture pytorch_lightning From a402896e402b9f373c2de41f9f66849e168aeced Mon Sep 17 00:00:00 2001 From: Aniket Maurya Date: Tue, 26 Jan 2021 13:54:18 +0530 Subject: [PATCH 04/17] vulture logs verbose set false --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 707f6ae74d848..34159550b11d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ order_by_type = "False" [tool.vulture] make_whitelist = true -min_confidence = 80 +min_confidence = 100 paths = ["pytorch_lightning"] sort_by_size = true -verbose = true +verbose = false From 8f4f05a912eb90d6bce1a02cbe544edefa0e8538 Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 26 Jan 2021 10:00:48 +0100 Subject: [PATCH 05/17] Apply suggestions from code review --- .github/workflows/code-formatting.yml | 3 ++- pyproject.toml | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index bfb47fb4d395f..3d29237e501d7 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -75,7 +75,7 @@ jobs: run: | mypy - python-vulture: + dead-code-vulture: name: Python dead code checker runs-on: ubuntu-20.04 @@ -91,6 +91,7 @@ jobs: - name: Install dependencies run: | pip install vulture + pip list - name: Run checking run: | diff --git a/pyproject.toml b/pyproject.toml index 34159550b11d3..d818fb713730f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,6 @@ order_by_type = "False" [tool.vulture] make_whitelist = true -min_confidence = 100 +min_confidence = 95 paths = ["pytorch_lightning"] sort_by_size = true -verbose = false From 5a4346f49c2b6fd23d4a884256711c7b1a435f9c Mon Sep 17 00:00:00 2001 From: Aniket Maurya Date: Wed, 3 Feb 2021 21:06:52 +0530 Subject: [PATCH 06/17] ignore name list and args to underscore naming --- pyproject.toml | 14 ++++++++++++++ tests/models/test_hparams.py | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d818fb713730f..deda4cb35f56b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,4 +43,18 @@ order_by_type = "False" make_whitelist = true min_confidence = 95 paths = ["pytorch_lightning"] +ignore_names = [ + "*idx", + "*batch", + "loc", + "signum", + "new_dtype", + "new_device", + "*_nb", + "mocked_device_count*", + "*param*", + "cmd_line", + "my_path", + "torch_save" +] sort_by_size = true diff --git a/tests/models/test_hparams.py b/tests/models/test_hparams.py index df69089a83d9d..10ba76a04c822 100644 --- a/tests/models/test_hparams.py +++ b/tests/models/test_hparams.py @@ -60,7 +60,7 @@ class SaveHparamsDecoratedModel(BoringModel): """ Tests that a model can take an object """ @decorate @decorate - def __init__(self, hparams, *my_args, **my_kwargs): + def __init__(self, hparams, *_my_args, **_my_kwargs): super().__init__() self.save_hyperparameters(hparams) @@ -69,7 +69,7 @@ class AssignHparamsDecoratedModel(BoringModel): """ Tests that a model can take an object with explicit setter""" @decorate @decorate - def __init__(self, hparams, *my_args, **my_kwargs): + def __init__(self, hparams, *_my_args, **_my_kwargs): super().__init__() self.hparams = hparams @@ -279,7 +279,7 @@ def __init__(self, *args, my_loss=torch.nn.CrossEntropyLoss(), **kwargs): class UnconventionalArgsEvalModel(EvalModelTemplate): """ A model that has unconventional names for "self", "*args" and "**kwargs". """ - def __init__(obj, *more_args, other_arg=300, **more_kwargs): + def __init__(obj, *more_args, _other_arg=300, **more_kwargs): # intentionally named obj super().__init__(*more_args, **more_kwargs) obj.save_hyperparameters() From 6dbfb512885a13330bd59bcd774b2eb2c201fdd1 Mon Sep 17 00:00:00 2001 From: Aniket Maurya Date: Wed, 3 Feb 2021 21:23:23 +0530 Subject: [PATCH 07/17] add ignore names --- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index deda4cb35f56b..d8c7398c5ec7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,8 @@ ignore_names = [ "*param*", "cmd_line", "my_path", - "torch_save" + "torch_save", + "using_lbfgs", + "kw", ] sort_by_size = true From cd34d9e5927e2e200e1424e45e9dbbbd2e32093a Mon Sep 17 00:00:00 2001 From: Aniket Maurya Date: Thu, 25 Mar 2021 22:37:44 +0530 Subject: [PATCH 08/17] deadcode whitelist --- pyproject.toml | 1 + pytorch_lightning/profiler/pytorch.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5bd9e27166cba..553447e35284b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ force_sort_within_sections = "False" order_by_type = "False" [tool.vulture] +exclude = ['pytorch_lightning/metric/'] make_whitelist = true min_confidence = 95 paths = ["pytorch_lightning"] diff --git a/pytorch_lightning/profiler/pytorch.py b/pytorch_lightning/profiler/pytorch.py index 73abc1baf939d..924b39230a5e4 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, _exc_type: Any, _exc_value: Any, traceback: Any) -> None: for handles in self._handles.values(): for h in handles: h.remove() From 9e1a2b65fcb52154eed712c99b4c5b7dfc1ff1d5 Mon Sep 17 00:00:00 2001 From: Aniket Maurya Date: Thu, 25 Mar 2021 22:38:09 +0530 Subject: [PATCH 09/17] deadcode whitelist --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 553447e35284b..d7dc86661fe7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ force_sort_within_sections = "False" order_by_type = "False" [tool.vulture] -exclude = ['pytorch_lightning/metric/'] +exclude = ['pytorch_lightning/metrics'] make_whitelist = true min_confidence = 95 paths = ["pytorch_lightning"] From 5f4d5333e77d78037acb643a89f67e96a140684a Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 11 May 2021 23:56:56 +0200 Subject: [PATCH 10/17] Apply suggestions from code review Co-authored-by: Rahul Jha --- .github/workflows/code-formatting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 74b6c0d7ca118..967fdd42a26de 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -93,6 +93,6 @@ jobs: pip install vulture pip list - - name: Run checking + - name: Check for dead code with Vulture run: | vulture pytorch_lightning From 21dc1f3876a23b7361a35399f96d653d0d216906 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 11 May 2021 21:57:44 +0000 Subject: [PATCH 11/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .gitignore | 2 +- .pre-commit-config.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9fcf0e1e296df..65ccbe93ab378 100644 --- a/.gitignore +++ b/.gitignore @@ -153,4 +153,4 @@ wandb cifar-10-batches-py *.pt # ctags -tags \ No newline at end of file +tags diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4184fce0d48a9..86d00c9adcca1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,4 +37,4 @@ repos: - repo: https://github.com/jendrikseipp/vulture rev: 'v2.3' # or any later Vulture version hooks: - - id: vulture \ No newline at end of file + - id: vulture From e233e2f5ad2c0b1949bbe907cb6fdf52a21c3e59 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Wed, 2 Jun 2021 10:15:56 +0100 Subject: [PATCH 12/17] Update whitelist --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index d7dc86661fe7b..74f2a2f60bf3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,5 +37,7 @@ ignore_names = [ "torch_save", "using_lbfgs", "kw", + "prediction", + "root", ] sort_by_size = true From b597beb00110b655ba9977cbf16dcb6037d06087 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Wed, 2 Jun 2021 10:31:16 +0100 Subject: [PATCH 13/17] Sort --- pyproject.toml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 74f2a2f60bf3f..1f21e1f088acb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,21 +23,21 @@ make_whitelist = true min_confidence = 95 paths = ["pytorch_lightning"] ignore_names = [ - "*idx", - "*batch", - "loc", - "signum", - "new_dtype", - "new_device", "*_nb", - "mocked_device_count*", + "*batch", + "*idx", "*param*", "cmd_line", - "my_path", - "torch_save", - "using_lbfgs", "kw", + "loc", + "mocked_device_count*", + "my_path", + "new_device", + "new_dtype", "prediction", "root", + "signum", + "torch_save", + "using_lbfgs", ] sort_by_size = true From 4bdbb82c8fc150615ced9656eebfabf40774c270 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Wed, 2 Jun 2021 10:40:46 +0100 Subject: [PATCH 14/17] Updates --- tests/models/test_hparams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/models/test_hparams.py b/tests/models/test_hparams.py index 863456581626f..9903d2b65ff07 100644 --- a/tests/models/test_hparams.py +++ b/tests/models/test_hparams.py @@ -272,7 +272,7 @@ def __init__(self, *args, my_loss=torch.nn.CrossEntropyLoss(), **kwargs): class UnconventionalArgsBoringModel(CustomBoringModel): """ A model that has unconventional names for "self", "*args" and "**kwargs". """ - def __init__(obj, *more_args, _other_arg=300, **more_kwargs): + def __init__(obj, *more_args, other_arg=300, **more_kwargs): # intentionally named obj super().__init__(*more_args, **more_kwargs) obj.save_hyperparameters() From 77b2cd4ec89f3a25cb41719e8c2df66b106b61c4 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Wed, 2 Jun 2021 10:41:26 +0100 Subject: [PATCH 15/17] Updates --- tests/models/test_hparams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/models/test_hparams.py b/tests/models/test_hparams.py index 9903d2b65ff07..06477b3572db7 100644 --- a/tests/models/test_hparams.py +++ b/tests/models/test_hparams.py @@ -55,7 +55,7 @@ class SaveHparamsDecoratedModel(BoringModel): @decorate @decorate - def __init__(self, hparams, *_my_args, **_my_kwargs): + def __init__(self, hparams, *my_args, **my_kwargs): super().__init__() self.save_hyperparameters(hparams) From 6b53480ad4dc588bb2bfec21d215b7c1d2f008c1 Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Wed, 2 Jun 2021 11:43:11 +0200 Subject: [PATCH 16/17] Apply suggestions from code review --- .github/workflows/code-formatting.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 967fdd42a26de..1cb8633545995 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -89,9 +89,7 @@ jobs: python-version: 3.7 - name: Install dependencies - run: | - pip install vulture - pip list + run: pip install vulture && pip list - name: Check for dead code with Vulture run: | From aa8449b0e46e3e03ccd494cf39a7d3f8088f4985 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Wed, 2 Jun 2021 10:47:38 +0100 Subject: [PATCH 17/17] Updates --- pytorch_lightning/profiler/pytorch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/profiler/pytorch.py b/pytorch_lightning/profiler/pytorch.py index a20d895714f50..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()