Skip to content

Commit 7c77a2a

Browse files
committed
fix(datamodules): catch ModuleNotFound datamodules
1 parent a0f58b9 commit 7c77a2a

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

cellseg_models_pytorch/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
from . import datamodules, datasets, inference, models, training, utils
1+
from . import inference, models, utils
22
from .models import CellPoseUnet, HoverNet, StarDistUnet
33

44
__version__ = "0.1.0"
5-
submodules = ["utils", "models", "inference", "training", "datasets", "datamodules"]
5+
submodules = ["utils", "models", "inference"]
66
__all__ = [
77
"__version__",
8-
"utils",
98
"CellPoseUnet",
109
"StarDistUnet",
1110
"HoverNet",
11+
"utils",
1212
"models",
1313
"inference",
14-
"training",
15-
"datasets",
16-
"datamodules",
1714
]

cellseg_models_pytorch/datamodules/_basemodule.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
from pathlib import Path
33
from typing import Union
44

5-
import pytorch_lightning as pl
5+
try:
6+
import pytorch_lightning as pl
7+
except ModuleNotFoundError:
8+
raise ModuleNotFoundError(
9+
"To use the `csmp.datamodules` module, the pytorch-lightning lib, is needed. "
10+
"Install with `pip install pytorch-lightning`"
11+
)
612
from torch.utils.data import DataLoader
713

814
__all__ = ["BaseDataModule"]

cellseg_models_pytorch/datamodules/downloader.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import re
22
from pathlib import Path
33

4-
import requests
4+
try:
5+
import requests
6+
except ModuleNotFoundError:
7+
raise ModuleNotFoundError(
8+
"To use `SimpleDownloader`, the requests package is needed. "
9+
"Install with `pip install requests`."
10+
)
511
from tqdm import tqdm
612

713

cellseg_models_pytorch/datamodules/pannuke_datamodule.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
import numpy as np
66
from tqdm import tqdm
77

8-
from ..datasets import SegmentationFolderDataset
98
from ..utils import FileHandler, fix_duplicates
10-
from ._basemodule import BaseDataModule
11-
from .downloader import SimpleDownloader
9+
10+
try:
11+
from ..datasets import SegmentationFolderDataset
12+
from ._basemodule import BaseDataModule
13+
from .downloader import SimpleDownloader
14+
except ModuleNotFoundError:
15+
raise ModuleNotFoundError(
16+
"To use the PannukeDataModule, requests, pytorch-lightning, & albumentations "
17+
"libraries are needed. Install with "
18+
"`pip install requests pytorch-lightning albumentations`"
19+
)
1220

1321

1422
class PannukeDataModule(BaseDataModule):

0 commit comments

Comments
 (0)