From ffe06912e0bdfadd3b0f8777d7467acee097feee Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 9 Mar 2021 10:29:44 +0100 Subject: [PATCH 1/5] fix comparing versions --- pytorch_lightning/utilities/imports.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/utilities/imports.py b/pytorch_lightning/utilities/imports.py index 41a13d6c678a0d..9e2e38c2698dfc 100644 --- a/pytorch_lightning/utilities/imports.py +++ b/pytorch_lightning/utilities/imports.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """General utilities""" +import importlib import operator import platform import sys @@ -42,8 +43,15 @@ def _module_available(module_path: str) -> bool: def _compare_version(package: str, op, version) -> bool: + """Compare package version with some requirements + + >>> _compare_version("torch", operator.ge, "0.1") + True + """ try: - pkg_version = LooseVersion(get_distribution(package).version) + pkg = importlib.import_module(package) + assert hasattr(pkg, '__version__') + pkg_version = pkg.__version__ return op(pkg_version, LooseVersion(version)) except DistributionNotFound: return False From c8d690a4ebb388d76847adb573e88cc2f111cb8b Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 9 Mar 2021 10:34:29 +0100 Subject: [PATCH 2/5] chlog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed7eec7cff7f93..30c3c604fb547d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed `trainer.test` from `best_path` hangs after calling `trainer.fit` ([#6272](https://github.com/PyTorchLightning/pytorch-lightning/pull/6272)) +- Fixed comparing required versions ([#6434](https://github.com/PyTorchLightning/pytorch-lightning/pull/6434)) + + ## [1.2.2] - 2021-03-02 ### Added From f7156da33f222e35aca63b3c7d339a01279e7be6 Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 9 Mar 2021 10:36:33 +0100 Subject: [PATCH 3/5] . --- pytorch_lightning/utilities/imports.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/utilities/imports.py b/pytorch_lightning/utilities/imports.py index 9e2e38c2698dfc..70ec05e7e1427e 100644 --- a/pytorch_lightning/utilities/imports.py +++ b/pytorch_lightning/utilities/imports.py @@ -20,7 +20,7 @@ from importlib.util import find_spec import torch -from pkg_resources import DistributionNotFound, get_distribution +from pkg_resources import DistributionNotFound def _module_available(module_path: str) -> bool: From f573043781b1a05332b032c109ad5f42f60c7173 Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 9 Mar 2021 11:06:36 +0100 Subject: [PATCH 4/5] ... --- pytorch_lightning/utilities/imports.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytorch_lightning/utilities/imports.py b/pytorch_lightning/utilities/imports.py index 70ec05e7e1427e..7bb6f51b1195ee 100644 --- a/pytorch_lightning/utilities/imports.py +++ b/pytorch_lightning/utilities/imports.py @@ -48,6 +48,8 @@ def _compare_version(package: str, op, version) -> bool: >>> _compare_version("torch", operator.ge, "0.1") True """ + if not _module_available(package): + return False try: pkg = importlib.import_module(package) assert hasattr(pkg, '__version__') From 8be4ef35e48e7fde23593bf37d35917839f723b6 Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Tue, 9 Mar 2021 14:05:59 +0100 Subject: [PATCH 5/5] datasets --- pl_examples/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pl_examples/__init__.py b/pl_examples/__init__.py index ffd60f9ed71af4..e3c5a78124137d 100644 --- a/pl_examples/__init__.py +++ b/pl_examples/__init__.py @@ -15,10 +15,10 @@ _DATASETS_PATH = os.path.join(_PACKAGE_ROOT, 'Datasets') _TORCHVISION_AVAILABLE = _module_available("torchvision") -_TORCHVISION_MNIST_AVAILABLE = True +_TORCHVISION_MNIST_AVAILABLE = _TORCHVISION_AVAILABLE _DALI_AVAILABLE = _module_available("nvidia.dali") -if _TORCHVISION_AVAILABLE: +if _TORCHVISION_MNIST_AVAILABLE: try: from torchvision.datasets.mnist import MNIST MNIST(_DATASETS_PATH, download=True)