From 9c5619ae8aab6ce3443f1112430a3819d13c0cbd Mon Sep 17 00:00:00 2001 From: Sumanth Ratna Date: Sun, 31 Jan 2021 20:08:34 -0500 Subject: [PATCH] Fix mypy 0.800 plus when prepending $PYTHONPATH to sys.path (#5698) * Fix mypy when prepending $PYTHONPATH to sys.path * attempt mypy fix * Revert "attempt mypy fix" This reverts commit fb7ed827d924452218ec23ddb2fd7484952a1294. * fix mypy Co-authored-by: Jirka Borovec --- .github/workflows/code-formatting.yml | 2 +- tests/models/data/__init__.py | 1 + tests/models/data/horovod/__init__.py | 1 + tests/models/data/horovod/train_default_model.py | 8 ++++---- 4 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 tests/models/data/__init__.py create mode 100644 tests/models/data/horovod/__init__.py diff --git a/.github/workflows/code-formatting.yml b/.github/workflows/code-formatting.yml index 032eb0e8a3eabb..7ceb727714eae8 100644 --- a/.github/workflows/code-formatting.yml +++ b/.github/workflows/code-formatting.yml @@ -69,7 +69,7 @@ jobs: python-version: 3.8 - name: Install mypy run: | - pip install "mypy==0.790" + pip install mypy==0.790 pip list - name: mypy check run: | diff --git a/tests/models/data/__init__.py b/tests/models/data/__init__.py new file mode 100644 index 00000000000000..6b0006f6b25003 --- /dev/null +++ b/tests/models/data/__init__.py @@ -0,0 +1 @@ +# this is needed only for mypy==0.800 as it undestands only packages diff --git a/tests/models/data/horovod/__init__.py b/tests/models/data/horovod/__init__.py new file mode 100644 index 00000000000000..6b0006f6b25003 --- /dev/null +++ b/tests/models/data/horovod/__init__.py @@ -0,0 +1 @@ +# this is needed only for mypy==0.800 as it undestands only packages diff --git a/tests/models/data/horovod/train_default_model.py b/tests/models/data/horovod/train_default_model.py index db1321623dd8aa..91533d75369e84 100644 --- a/tests/models/data/horovod/train_default_model.py +++ b/tests/models/data/horovod/train_default_model.py @@ -21,10 +21,10 @@ import os import sys -# this is need as e.g. Conda do not uses `PYTHONPATH` env var as pip or/and virtualenv -from pytorch_lightning.trainer.states import TrainerState - -sys.path = os.getenv('PYTHONPATH').split(':') + sys.path +# this is needed because Conda does not use `PYTHONPATH` env var while pip and virtualenv do +PYTHONPATH = os.getenv('PYTHONPATH', '') +if ':' in PYTHONPATH: + sys.path = PYTHONPATH.split(':') + sys.path from pytorch_lightning import Trainer # noqa: E402 from pytorch_lightning.callbacks import ModelCheckpoint # noqa: E402