Skip to content

Commit

Permalink
Wildcard import (#1411)
Browse files Browse the repository at this point in the history
add `__all__` and `remove import *`. Update CONTRIBUTING.md
  • Loading branch information
rijobro authored Jan 7, 2021
1 parent db7bf89 commit 1f74ca2
Show file tree
Hide file tree
Showing 48 changed files with 764 additions and 59 deletions.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ License information: all source code files should start with this paragraph:
```

##### Exporting modules

If you intend for any variables/functions/classes to be available outside of the file with the edited functionality, then:

- Create or append to the `__all__` variable (in the file in which functionality has been added), and
- Add to the `__init__.py` file.

#### Unit testing
MONAI tests are located under `tests/`.

Expand Down
4 changes: 2 additions & 2 deletions monai/apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .datasets import *
from .utils import *
from .datasets import CrossValidation, DecathlonDataset, MedNISTDataset
from .utils import check_hash, download_and_extract, download_url, extractall
12 changes: 10 additions & 2 deletions monai/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .deviceconfig import *
from .type_definitions import *
from .deviceconfig import (
USE_COMPILED,
get_gpu_info,
get_system_info,
print_config,
print_debug_info,
print_gpu_info,
print_system_info,
)
from .type_definitions import IndexSelection, KeysCollection
10 changes: 10 additions & 0 deletions monai/config/deviceconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
psutil, has_psutil = optional_import("psutil")
psutil_version = psutil.__version__ if has_psutil else "NOT INSTALLED or UNKNOWN VERSION."

__all__ = [
"print_config",
"get_system_info",
"print_system_info",
"get_gpu_info",
"print_gpu_info",
"print_debug_info",
"USE_COMPILED",
]


def get_config_values():
"""
Expand Down
2 changes: 2 additions & 0 deletions monai/config/type_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from typing import Collection, Hashable, Iterable, Union

__all__ = ["KeysCollection", "IndexSelection"]

"""Commonly used concepts
This module provides naming and type specifications for commonly used concepts
within the MONAI package. The intent is to explicitly identify information
Expand Down
32 changes: 28 additions & 4 deletions monai/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,38 @@
ZipDataset,
)
from .decathlon_datalist import load_decathlon_datalist, load_decathlon_properties
from .grid_dataset import *
from .image_reader import *
from .grid_dataset import GridPatchDataset, PatchDataset
from .image_reader import ImageReader, ITKReader, NibabelReader, NumpyReader, PILReader
from .iterable_dataset import IterableDataset
from .nifti_reader import NiftiDataset
from .nifti_saver import NiftiSaver
from .nifti_writer import write_nifti
from .png_saver import PNGSaver
from .png_writer import write_png
from .synthetic import *
from .synthetic import create_test_image_2d, create_test_image_3d
from .thread_buffer import ThreadBuffer
from .utils import *
from .utils import (
DistributedSampler,
compute_importance_map,
compute_shape_offset,
correct_nifti_header_if_necessary,
create_file_basename,
dense_patch_slices,
get_random_patch,
get_valid_patch_size,
is_supported_format,
iter_patch,
iter_patch_slices,
json_hashing,
list_data_collate,
partition_dataset,
partition_dataset_classes,
pickle_hashing,
rectify_header_sform_qform,
select_cross_validation_folds,
set_rnd,
sorted_dict,
to_affine_nd,
worker_init_fn,
zoom_affine,
)
26 changes: 26 additions & 0 deletions monai/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@

nib, _ = optional_import("nibabel")

__all__ = [
"get_random_patch",
"iter_patch_slices",
"dense_patch_slices",
"iter_patch",
"get_valid_patch_size",
"list_data_collate",
"worker_init_fn",
"set_rnd",
"correct_nifti_header_if_necessary",
"rectify_header_sform_qform",
"zoom_affine",
"compute_shape_offset",
"to_affine_nd",
"create_file_basename",
"compute_importance_map",
"is_supported_format",
"partition_dataset",
"partition_dataset_classes",
"select_cross_validation_folds",
"DistributedSampler",
"json_hashing",
"pickle_hashing",
"sorted_dict",
]


def get_random_patch(
dims: Sequence[int], patch_size: Sequence[int], rand_state: Optional[np.random.RandomState] = None
Expand Down
8 changes: 4 additions & 4 deletions monai/engines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .evaluator import *
from .multi_gpu_supervised_trainer import *
from .trainer import *
from .utils import *
from .evaluator import EnsembleEvaluator, Evaluator, SupervisedEvaluator
from .multi_gpu_supervised_trainer import create_multigpu_supervised_evaluator, create_multigpu_supervised_trainer
from .trainer import GanTrainer, SupervisedTrainer, Trainer
from .utils import CommonKeys, GanKeys, default_make_latent, default_prepare_batch, get_devices_spec
2 changes: 2 additions & 0 deletions monai/engines/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import torch

__all__ = ["CommonKeys", "GanKeys", "get_devices_spec", "default_prepare_batch", "default_make_latent"]


class CommonKeys:
"""
Expand Down
2 changes: 1 addition & 1 deletion monai/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
from .stats_handler import StatsHandler
from .surface_distance import SurfaceDistance
from .tensorboard_handlers import TensorBoardImageHandler, TensorBoardStatsHandler
from .utils import *
from .utils import all_gather, stopping_fn_from_loss, stopping_fn_from_metric
from .validation_handler import ValidationHandler
2 changes: 1 addition & 1 deletion monai/inferers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .inferer import *
from .inferer import Inferer, SimpleInferer, SlidingWindowInferer
from .utils import sliding_window_inference
4 changes: 2 additions & 2 deletions monai/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# limitations under the License.

from .confusion_matrix import ConfusionMatrixMetric, compute_confusion_matrix_metric, get_confusion_matrix
from .hausdorff_distance import *
from .hausdorff_distance import HausdorffDistanceMetric, compute_hausdorff_distance, compute_percent_hausdorff_distance
from .meandice import DiceMetric, compute_meandice
from .rocauc import compute_roc_auc
from .surface_distance import SurfaceDistanceMetric, compute_average_surface_distance
from .utils import *
from .utils import do_metric_reduction, get_mask_edges, get_surface_distance, ignore_background
2 changes: 1 addition & 1 deletion monai/metrics/confusion_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import torch

from monai.metrics.utils import *
from monai.metrics.utils import do_metric_reduction, ignore_background
from monai.utils import MetricReduction


Expand Down
2 changes: 1 addition & 1 deletion monai/metrics/hausdorff_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import numpy as np
import torch

from monai.metrics.utils import *
from monai.metrics.utils import do_metric_reduction, get_mask_edges, get_surface_distance, ignore_background
from monai.utils import MetricReduction

__all__ = ["HausdorffDistanceMetric", "compute_hausdorff_distance", "compute_percent_hausdorff_distance"]
Expand Down
2 changes: 1 addition & 1 deletion monai/metrics/meandice.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import torch

from monai.metrics.utils import *
from monai.metrics.utils import do_metric_reduction, ignore_background
from monai.utils import MetricReduction


Expand Down
2 changes: 1 addition & 1 deletion monai/metrics/surface_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import numpy as np
import torch

from monai.metrics.utils import *
from monai.metrics.utils import do_metric_reduction, get_mask_edges, get_surface_distance, ignore_background
from monai.utils import MetricReduction


Expand Down
13 changes: 12 additions & 1 deletion monai/networks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .utils import *
from .utils import (
eval_mode,
icnr_init,
normal_init,
normalize_transform,
one_hot,
pixelshuffle,
predict_segmentation,
slice_channels,
to_norm_affine,
train_mode,
)
2 changes: 1 addition & 1 deletion monai/networks/blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
SEResNetBottleneck,
SEResNeXtBottleneck,
)
from .upsample import *
from .upsample import SubpixelUpsample, Subpixelupsample, SubpixelUpSample, Upsample, UpSample
19 changes: 14 additions & 5 deletions monai/networks/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .convutils import *
from .factories import *
from .filtering import *
from .simplelayers import *
from .spatial_transforms import *
from .convutils import calculate_out_shape, gaussian_1d, polyval, same_padding, stride_minus_kernel_padding
from .factories import Act, Conv, Dropout, LayerFactory, Norm, Pad, Pool, split_args
from .filtering import BilateralFilter
from .simplelayers import (
LLTM,
ChannelPad,
Flatten,
GaussianFilter,
HilbertTransform,
Reshape,
SkipConnection,
separable_filtering,
)
from .spatial_transforms import AffineTransform, grid_count, grid_grad, grid_pull, grid_push
10 changes: 5 additions & 5 deletions monai/networks/nets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

from .ahnet import AHNet
from .autoencoder import AutoEncoder
from .basic_unet import *
from .classifier import *
from .basic_unet import BasicUNet, BasicUnet, Basicunet
from .classifier import Classifier, Critic, Discriminator
from .densenet import DenseNet, densenet121, densenet169, densenet201, densenet264
from .dynunet import *
from .fullyconnectednet import *
from .dynunet import DynUNet, DynUnet, Dynunet
from .fullyconnectednet import FullyConnectedNet, VarFullyConnectedNet
from .generator import Generator
from .highresnet import HighResBlock, HighResNet
from .regressor import Regressor
from .segresnet import SegResNet, SegResNetVAE
from .senet import SENet, se_resnet50, se_resnet101, se_resnet152, se_resnext50_32x4d, se_resnext101_32x4d, senet154
from .unet import *
from .unet import UNet, Unet, unet
from .varautoencoder import VarAutoEncoder
from .vnet import VNet
2 changes: 2 additions & 0 deletions monai/networks/nets/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from monai.networks.layers.factories import Act, Norm, split_args
from monai.networks.nets.regressor import Regressor

__all__ = ["Classifier", "Discriminator", "Critic"]


class Classifier(Regressor):
"""
Expand Down
3 changes: 2 additions & 1 deletion monai/networks/nets/dynunet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

from typing import List, Optional, Sequence, Union

import torch
import torch.nn as nn

from monai.networks.blocks.dynunet_block import *
from monai.networks.blocks.dynunet_block import UnetBasicBlock, UnetOutBlock, UnetResBlock, UnetUpBlock

__all__ = ["DynUNet", "DynUnet", "Dynunet"]

Expand Down
2 changes: 2 additions & 0 deletions monai/networks/nets/fullyconnectednet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from monai.networks.blocks import ADN
from monai.networks.layers.factories import Act

__all__ = ["FullyConnectedNet", "VarFullyConnectedNet"]


def _get_adn_layer(
act: Optional[Union[Tuple, str]], dropout: Optional[Union[Tuple, str, float]], ordering: Optional[str]
Expand Down
3 changes: 2 additions & 1 deletion monai/networks/nets/segresnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F

from monai.networks.blocks.segresnet_block import *
from monai.networks.blocks.segresnet_block import ResBlock, get_conv_layer, get_norm_layer, get_upsample_layer
from monai.networks.layers.factories import Act, Dropout
from monai.utils import UpsampleMode

Expand Down
2 changes: 2 additions & 0 deletions monai/networks/nets/unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from monai.networks.layers.simplelayers import SkipConnection
from monai.utils import alias, export

__all__ = ["UNet", "Unet", "unet"]


@export("monai.networks.nets")
@alias("Unet")
Expand Down
2 changes: 1 addition & 1 deletion monai/optimizers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# limitations under the License.

from .novograd import Novograd
from .utils import *
from .utils import generate_param_groups
Loading

0 comments on commit 1f74ca2

Please sign in to comment.