Skip to content

Commit

Permalink
skip hanging tests & update imports (#258)
Browse files Browse the repository at this point in the history
* fix imports

* timeout

* flake8

* skip

* skip

* skip

* skip

* Apply suggestions from code review
  • Loading branch information
Borda authored Oct 13, 2020
1 parent ecb852d commit 07e3376
Show file tree
Hide file tree
Showing 41 changed files with 164 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_test-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
os: windows-2019

# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 35
timeout-minutes: 45

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/callbacks/variational.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

try:
import torchvision
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')

Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/callbacks/vision/image_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

try:
import torchvision
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')

Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/datamodules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@

from pl_bolts.datamodules.kitti_dataset import KittiDataset
from pl_bolts.datamodules.kitti_datamodule import KittiDataModule
except ImportError:
except ModuleNotFoundError:
pass
6 changes: 4 additions & 2 deletions pl_bolts/datamodules/binary_mnist_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from torchvision import transforms as transform_lib
from torchvision.datasets import MNIST
from pl_bolts.datamodules.mnist_dataset import BinaryMNIST
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
_TORCHVISION_AVAILABLE = False
Expand Down Expand Up @@ -65,7 +65,9 @@ def __init__(
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE:
raise ImportError('You want to use MNIST dataset loaded from `torchvision` which is not installed yet.')
raise ModuleNotFoundError( # pragma: no-cover
'You want to use MNIST dataset loaded from `torchvision` which is not installed yet.'
)

self.dims = (1, 28, 28)
self.data_dir = data_dir
Expand Down
6 changes: 4 additions & 2 deletions pl_bolts/datamodules/cifar10_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from torchvision import transforms as transform_lib
from torchvision.datasets import CIFAR10

except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
_TORCHVISION_AVAILABLE = False
Expand Down Expand Up @@ -84,7 +84,9 @@ def __init__(
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE:
raise ImportError('You want to use CIFAR10 dataset loaded from `torchvision` which is not installed yet.')
raise ModuleNotFoundError( # pragma: no-cover
'You want to use CIFAR10 dataset loaded from `torchvision` which is not installed yet.'
)

self.dims = (3, 32, 32)
self.DATASET = CIFAR10
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/datamodules/cifar10_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

try:
from PIL import Image
except ImportError:
except ModuleNotFoundError:
warn('You want to use `Pillow` which is not installed yet,' # pragma: no-cover
' install it with `pip install Pillow`.')
_PIL_AVAILABLE = False
Expand Down
4 changes: 2 additions & 2 deletions pl_bolts/datamodules/cityscapes_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
try:
from torchvision import transforms as transform_lib
from torchvision.datasets import Cityscapes
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
_TORCHVISION_AVAILABLE = False
Expand Down Expand Up @@ -77,7 +77,7 @@ def __init__(
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE:
raise ImportError(
raise ModuleNotFoundError( # pragma: no-cover
'You want to use CityScapes dataset loaded from `torchvision` which is not installed yet.'
)

Expand Down
4 changes: 2 additions & 2 deletions pl_bolts/datamodules/fashion_mnist_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
try:
from torchvision import transforms as transform_lib
from torchvision.datasets import FashionMNIST
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
_TORCHVISION_AVAILABLE = False
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE:
raise ImportError(
raise ModuleNotFoundError( # pragma: no-cover
'You want to use fashion MNIST dataset loaded from `torchvision` which is not installed yet.'
)

Expand Down
6 changes: 4 additions & 2 deletions pl_bolts/datamodules/imagenet_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
try:
from torchvision import transforms as transform_lib
from pl_bolts.datamodules.imagenet_dataset import UnlabeledImagenet
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
_TORCHVISION_AVAILABLE = False
Expand Down Expand Up @@ -72,7 +72,9 @@ def __init__(
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE:
raise ImportError('You want to use ImageNet dataset loaded from `torchvision` which is not installed yet.')
raise ModuleNotFoundError( # pragma: no-cover
'You want to use ImageNet dataset loaded from `torchvision` which is not installed yet.'
)

self.image_size = image_size
self.dims = (3, self.image_size, self.image_size)
Expand Down
9 changes: 5 additions & 4 deletions pl_bolts/datamodules/imagenet_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@

try:
from sklearn.utils import shuffle
except ImportError:
except ModuleNotFoundError:
warn('You want to use `sklearn` which is not installed yet,' # pragma: no-cover
' install it with `pip install sklearn`.')

try:
from torchvision.datasets import ImageNet
from torchvision.datasets.imagenet import load_meta_file
except ImportError:
raise ImportError('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
except ModuleNotFoundError:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use `torchvision` which is not installed yet, install it with `pip install torchvision`.'
)


class UnlabeledImagenet(ImageNet):
Expand Down
6 changes: 4 additions & 2 deletions pl_bolts/datamodules/mnist_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
try:
from torchvision import transforms as transform_lib
from torchvision.datasets import MNIST
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
_TORCHVISION_AVAILABLE = False
Expand Down Expand Up @@ -65,7 +65,9 @@ def __init__(
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE:
raise ImportError('You want to use MNIST dataset loaded from `torchvision` which is not installed yet.')
raise ModuleNotFoundError( # pragma: no-cover
'You want to use MNIST dataset loaded from `torchvision` which is not installed yet.'
)

self.dims = (1, 28, 28)
self.data_dir = data_dir
Expand Down
9 changes: 5 additions & 4 deletions pl_bolts/datamodules/mnist_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
try:
from torchvision import transforms as transform_lib
from torchvision.datasets import MNIST
except ImportError:
raise ImportError('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
except ModuleNotFoundError:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use `torchvision` which is not installed yet, install it with `pip install torchvision`.'
)

try:
from PIL import Image
except ImportError:
except ModuleNotFoundError:
warn('You want to use `Pillow` which is not installed yet,' # pragma: no-cover
' install it with `pip install Pillow`.')
_PIL_AVAILABLE = False
Expand Down
6 changes: 4 additions & 2 deletions pl_bolts/datamodules/sklearn_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

try:
from sklearn.utils import shuffle as sk_shuffle
except ImportError:
except ModuleNotFoundError:
warn('You want to use `sklearn` which is not installed yet,' # pragma: no-cover
' install it with `pip install sklearn`.')
_SKLEARN_AVAILABLE = False
Expand Down Expand Up @@ -162,7 +162,9 @@ def __init__(
if shuffle and _SKLEARN_AVAILABLE:
X, y = sk_shuffle(X, y, random_state=random_state)
elif shuffle and not _SKLEARN_AVAILABLE:
raise ImportError('You want to use shuffle function from `scikit-learn` which is not installed yet.')
raise ModuleNotFoundError( # pragma: no-cover
'You want to use shuffle function from `scikit-learn` which is not installed yet.'
)

val_split = 0 if x_val is not None or y_val is not None else val_split
test_split = 0 if x_test is not None or y_test is not None else test_split
Expand Down
4 changes: 2 additions & 2 deletions pl_bolts/datamodules/ssl_amdim_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

try:
from sklearn.utils import shuffle
except ImportError:
except ModuleNotFoundError:
warn('You want to use `sklearn` which is not installed yet,' # pragma: no-cover
' install it with `pip install sklearn`.')

try:
from torchvision.datasets import CIFAR10
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')

Expand Down
6 changes: 4 additions & 2 deletions pl_bolts/datamodules/ssl_imagenet_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
try:
from torchvision import transforms as transform_lib

except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
_TORCHVISION_AVAILABLE = False
Expand All @@ -33,7 +33,9 @@ def __init__(
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE:
raise ImportError('You want to use ImageNet dataset loaded from `torchvision` which is not installed yet.')
raise ModuleNotFoundError( # pragma: no-cover
'You want to use ImageNet dataset loaded from `torchvision` which is not installed yet.'
)

self.data_dir = data_dir
self.num_workers = num_workers
Expand Down
6 changes: 4 additions & 2 deletions pl_bolts/datamodules/stl10_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
try:
from torchvision import transforms as transform_lib
from torchvision.datasets import STL10
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
_TORCHVISION_AVAILABLE = False
Expand Down Expand Up @@ -75,7 +75,9 @@ def __init__(
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE:
raise ImportError('You want to use STL10 dataset loaded from `torchvision` which is not installed yet.')
raise ModuleNotFoundError( # pragma: no-cover
'You want to use STL10 dataset loaded from `torchvision` which is not installed yet.'
)

self.dims = (3, 96, 96)
self.data_dir = data_dir if data_dir is not None else os.getcwd()
Expand Down
6 changes: 4 additions & 2 deletions pl_bolts/datamodules/vocdetection_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
try:
from torchvision.datasets import VOCDetection

except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')
_TORCHVISION_AVAILABLE = False
Expand Down Expand Up @@ -120,7 +120,9 @@ def __init__(
super().__init__(*args, **kwargs)

if not _TORCHVISION_AVAILABLE:
raise ImportError('You want to use VOC dataset loaded from `torchvision` which is not installed yet.')
raise ModuleNotFoundError( # pragma: no-cover
'You want to use VOC dataset loaded from `torchvision` which is not installed yet.'
)

self.year = year
self.data_dir = data_dir
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/models/detection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

try:
from pl_bolts.models.detection.faster_rcnn import FasterRCNN
except ImportError: # pragma: no-cover
except ModuleNotFoundError: # pragma: no-cover
pass # pragma: no-cover
else:
__all__.append('FasterRCNN')
2 changes: 1 addition & 1 deletion pl_bolts/models/detection/faster_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
try:
from torchvision.models.detection import faster_rcnn, fasterrcnn_resnet50_fpn
from torchvision.ops import box_iou
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')

Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/models/mnist_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
try:
from torchvision import transforms
from torchvision.datasets import MNIST
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')

Expand Down
7 changes: 4 additions & 3 deletions pl_bolts/models/regression/linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ def cli_main():
# create dataset
try:
from sklearn.datasets import load_boston
except ImportError:
raise ImportError('You want to use `sklearn` which is not installed yet,' # pragma: no-cover
' install it with `pip install sklearn`.')
except ModuleNotFoundError:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use `sklearn` which is not installed yet, install it with `pip install sklearn`.'
)

X, y = load_boston(return_X_y=True) # these are numpy arrays
loaders = SklearnDataModule(X, y)
Expand Down
7 changes: 4 additions & 3 deletions pl_bolts/models/regression/logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ def cli_main():
# Example: Iris dataset in Sklearn (4 features, 3 class labels)
try:
from sklearn.datasets import load_iris
except ImportError:
raise ImportError('You want to use `sklearn` which is not installed yet,' # pragma: no-cover
' install it with `pip install sklearn`.')
except ModuleNotFoundError:
raise ModuleNotFoundError( # pragma: no-cover
'You want to use `sklearn` which is not installed yet, install it with `pip install sklearn`.'
)

X, y = load_iris(return_X_y=True)
loaders = SklearnDataModule(X, y)
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/models/self_supervised/amdim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
AMDIMTrainTransformsImageNet128,
AMDIMEvalTransformsImageNet128,
)
except ImportError:
except ModuleNotFoundError:
pass
2 changes: 1 addition & 1 deletion pl_bolts/models/self_supervised/amdim/amdim_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

try:
from pl_bolts.models.self_supervised.amdim.datasets import AMDIMPretraining
except ImportError:
except ModuleNotFoundError:
pass
from pl_bolts.losses.self_supervised_learning import FeatureMapContrastiveTask
from pl_bolts.models.self_supervised.amdim.networks import AMDIMEncoder
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/models/self_supervised/amdim/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pl_bolts.datamodules.imagenet_dataset import UnlabeledImagenet
from pl_bolts.datamodules.ssl_amdim_datasets import CIFAR10Mixed
from pl_bolts.models.self_supervised.amdim import transforms as amdim_transforms
except ImportError:
except ModuleNotFoundError:
warn('You want to use `torchvision` which is not installed yet,' # pragma: no-cover
' install it with `pip install torchvision`.')

Expand Down
Loading

0 comments on commit 07e3376

Please sign in to comment.