Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Check import formatting with isort #324

Merged
merged 12 commits into from
Nov 9, 2020
18 changes: 15 additions & 3 deletions .github/workflows/code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Install dependencies
run: |
# python -m pip install --upgrade --user pip
pip install flake8
pip --version
shell: bash

- name: PEP8
run: |
flake8 .

isort:
Borda marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install isort
run: |
pip install isort==5.6.4
pip --version
- name: isort
run: |
isort . --check --diff
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.5.2
hooks:
- id: isort
10 changes: 5 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

import os
import sys
# import m2r
import builtins
import glob
import shutil
import inspect
import os
import re
# import m2r
import builtins
import shutil
import sys

import pt_lightning_sphinx_theme
from sphinx.ext import apidoc
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
else:

# from pl_bolts.models.mnist_module import LitMNIST
from pl_bolts import models, metrics, callbacks, datamodules, transforms, datasets
from pl_bolts import callbacks, datamodules, datasets, metrics, models, transforms

__all__ = [
# 'LitMNIST',
Expand Down
8 changes: 3 additions & 5 deletions pl_bolts/callbacks/data_monitor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from typing import Any, Sequence, Dict
from typing import List, Optional, Union
from typing import Any, Dict, List, Optional, Sequence, Union

import numpy as np
import torch
import torch.nn as nn
from pytorch_lightning import Callback
from pytorch_lightning import LightningModule, Trainer
from pytorch_lightning.loggers import WandbLogger, TensorBoardLogger
from pytorch_lightning import Callback, LightningModule, Trainer
from pytorch_lightning.loggers import TensorBoardLogger, WandbLogger
from pytorch_lightning.utilities import rank_zero_warn
from pytorch_lightning.utilities.apply_func import apply_to_collection
from torch import Tensor
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/callbacks/printing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import copy
from itertools import zip_longest
from typing import List, Any, Dict, Callable, Optional
from typing import Any, Callable, Dict, List, Optional

from pytorch_lightning.callbacks import Callback
from pytorch_lightning.utilities import rank_zero_info
Expand Down
15 changes: 4 additions & 11 deletions pl_bolts/datamodules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@
__all__ += ['BinaryMNISTDataModule']

try:
from pl_bolts.datamodules.cifar10_datamodule import (
CIFAR10DataModule,
TinyCIFAR10DataModule,
)
from pl_bolts.datamodules.cifar10_datamodule import CIFAR10DataModule, TinyCIFAR10DataModule
except ModuleNotFoundError:
pass
else:
__all__ += ['CIFAR10DataModule', 'TinyCIFAR10DataModule']

try:
from pl_bolts.datamodules.experience_source import (
ExperienceSourceDataset,
ExperienceSource,
DiscountedExperienceSource,
ExperienceSource,
ExperienceSourceDataset,
)
except ModuleNotFoundError:
pass
Expand Down Expand Up @@ -52,11 +49,7 @@
__all__ += ['MNISTDataModule']

try:
from pl_bolts.datamodules.sklearn_datamodule import (
SklearnDataset,
SklearnDataModule,
TensorDataset,
)
from pl_bolts.datamodules.sklearn_datamodule import SklearnDataModule, SklearnDataset, TensorDataset
except ModuleNotFoundError:
pass
else:
Expand Down
1 change: 1 addition & 0 deletions pl_bolts/datamodules/binary_mnist_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
try:
from torchvision import transforms as transform_lib
from torchvision.datasets import MNIST

from pl_bolts.datasets.mnist_dataset import BinaryMNIST
except ModuleNotFoundError:
warn_missing_pkg('torchvision') # pragma: no-cover
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/datamodules/experience_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from abc import ABC
from collections import deque, namedtuple
from typing import Iterable, Callable, Tuple, List
from typing import Callable, Iterable, List, Tuple

import torch
from gym import Env
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/datamodules/sklearn_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import torch
from pytorch_lightning import LightningDataModule
from torch.utils.data import Dataset, DataLoader
from torch.utils.data import DataLoader, Dataset

try:
from sklearn.utils import shuffle as sk_shuffle
Expand Down
8 changes: 4 additions & 4 deletions pl_bolts/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pl_bolts.datasets.dummy_dataset import (
RandomDictStringDataset,
RandomDictDataset,
RandomDataset,
DummyDataset,
DummyDetectionDataset
DummyDetectionDataset,
RandomDataset,
RandomDictDataset,
RandomDictStringDataset,
)

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/datasets/base_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import urllib.request
from abc import ABC
from typing import Tuple, Sequence
from typing import Sequence, Tuple
from urllib.error import HTTPError

import torch
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/datasets/cifar10_dataset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import pickle
import tarfile
from typing import Tuple, Optional, Sequence, Callable
from typing import Callable, Optional, Sequence, Tuple

import torch
from torch import Tensor
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/datasets/dummy_dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import torch
from torch.utils.data import Dataset, DataLoader
from torch.utils.data import DataLoader, Dataset


class DummyDataset(Dataset):
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/losses/rl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Loss functions for the RL models
"""

from typing import Tuple, List
from typing import List, Tuple

import numpy as np
import torch
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from pl_bolts.metrics.aggregation import mean, accuracy, precision_at_k
from pl_bolts.metrics.aggregation import accuracy, mean, precision_at_k
4 changes: 1 addition & 3 deletions pl_bolts/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
from pl_bolts.models.autoencoders.basic_vae.basic_vae_module import VAE
from pl_bolts.models.mnist_module import LitMNIST
from pl_bolts.models.regression import LinearRegression, LogisticRegression
from pl_bolts.models.vision import PixelCNN
from pl_bolts.models.vision import SemSegment
from pl_bolts.models.vision import UNet
from pl_bolts.models.vision import PixelCNN, SemSegment, UNet
from pl_bolts.models.vision.image_gpt.igpt_module import GPT2, ImageGPT
9 changes: 6 additions & 3 deletions pl_bolts/models/autoencoders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

from pl_bolts.models.autoencoders.basic_ae.basic_ae_module import AE
from pl_bolts.models.autoencoders.basic_vae.basic_vae_module import VAE

from pl_bolts.models.autoencoders.components import resnet18_encoder, resnet18_decoder
from pl_bolts.models.autoencoders.components import resnet50_encoder, resnet50_decoder
from pl_bolts.models.autoencoders.components import (
resnet18_decoder,
resnet18_encoder,
resnet50_decoder,
resnet50_encoder,
)
8 changes: 6 additions & 2 deletions pl_bolts/models/autoencoders/basic_ae/basic_ae_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import torch.nn as nn
from torch.nn import functional as F

from pl_bolts.models.autoencoders.components import resnet18_encoder, resnet18_decoder
from pl_bolts.models.autoencoders.components import resnet50_encoder, resnet50_decoder
from pl_bolts.models.autoencoders.components import (
resnet18_decoder,
resnet18_encoder,
resnet50_decoder,
resnet50_encoder,
)


class AE(pl.LightningModule):
Expand Down
8 changes: 6 additions & 2 deletions pl_bolts/models/autoencoders/basic_vae/basic_vae_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import torch.nn as nn
from torch.nn import functional as F

from pl_bolts.models.autoencoders.components import resnet18_encoder, resnet18_decoder
from pl_bolts.models.autoencoders.components import resnet50_encoder, resnet50_decoder
from pl_bolts.models.autoencoders.components import (
resnet18_decoder,
resnet18_encoder,
resnet50_decoder,
resnet50_encoder,
)


class VAE(pl.LightningModule):
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/models/gans/basic/basic_gan_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import torch
from torch.nn import functional as F

from pl_bolts.models.gans.basic.components import Generator, Discriminator
from pl_bolts.models.gans.basic.components import Discriminator, Generator


class GAN(pl.LightningModule):
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/models/rl/common/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Named tuple for storing experience steps gathered in training
import collections
from collections import deque, namedtuple
from typing import Tuple, List, Union
from typing import List, Tuple, Union

import numpy as np

Expand Down
3 changes: 1 addition & 2 deletions pl_bolts/models/rl/common/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import numpy as np
import torch
from torch import Tensor
from torch import nn
from torch import Tensor, nn
from torch.nn import functional as F


Expand Down
4 changes: 2 additions & 2 deletions pl_bolts/models/rl/dqn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import argparse
from collections import OrderedDict
from typing import Tuple, List, Dict, Optional
from typing import Dict, List, Optional, Tuple

import numpy as np
import pytorch_lightning as pl
Expand All @@ -15,7 +15,7 @@
from torch.optim.optimizer import Optimizer
from torch.utils.data import DataLoader

from pl_bolts.datamodules.experience_source import ExperienceSourceDataset, Experience
from pl_bolts.datamodules.experience_source import Experience, ExperienceSourceDataset
from pl_bolts.losses.rl import dqn_loss
from pl_bolts.models.rl.common.agents import ValueAgent
from pl_bolts.models.rl.common.memory import MultiStepBuffer
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/models/rl/per_dqn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from pl_bolts.datamodules import ExperienceSourceDataset
from pl_bolts.losses.rl import per_dqn_loss
from pl_bolts.models.rl.common.memory import PERBuffer, Experience
from pl_bolts.models.rl.common.memory import Experience, PERBuffer
from pl_bolts.models.rl.dqn_model import DQN


Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/models/rl/reinforce_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
from collections import OrderedDict
from typing import Tuple, List
from typing import List, Tuple

import numpy as np
import pytorch_lightning as pl
Expand Down
2 changes: 1 addition & 1 deletion pl_bolts/models/rl/vanilla_policy_gradient_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
from collections import OrderedDict
from typing import Tuple, List
from typing import List, Tuple

import numpy as np
import pytorch_lightning as pl
Expand Down
7 changes: 4 additions & 3 deletions pl_bolts/models/self_supervised/amdim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from pl_bolts.models.self_supervised.amdim.amdim_module import AMDIM
from pl_bolts.models.self_supervised.amdim.networks import AMDIMEncoder

try:
from pl_bolts.models.self_supervised.amdim.transforms import (
AMDIMEvalTransformsCIFAR10,
AMDIMTrainTransformsCIFAR10,
AMDIMTrainTransformsSTL10,
AMDIMEvalTransformsImageNet128,
AMDIMEvalTransformsSTL10,
AMDIMTrainTransformsCIFAR10,
AMDIMTrainTransformsImageNet128,
AMDIMEvalTransformsImageNet128,
AMDIMTrainTransformsSTL10,
)
except ModuleNotFoundError:
pass
1 change: 1 addition & 0 deletions pl_bolts/models/self_supervised/amdim/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

try:
from torchvision.datasets import STL10

from pl_bolts.datasets.imagenet_dataset import UnlabeledImagenet
from pl_bolts.datasets.ssl_amdim_datasets import CIFAR10Mixed
from pl_bolts.models.self_supervised.amdim import transforms as amdim_transforms
Expand Down
4 changes: 2 additions & 2 deletions pl_bolts/models/self_supervised/byol/byol_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def add_model_specific_args(parent_parser):

def cli_main():
from pl_bolts.callbacks.ssl_online import SSLOnlineEvaluator
from pl_bolts.datamodules import CIFAR10DataModule, STL10DataModule, ImagenetDataModule
from pl_bolts.models.self_supervised.simclr import SimCLRTrainDataTransform, SimCLREvalDataTransform
from pl_bolts.datamodules import CIFAR10DataModule, ImagenetDataModule, STL10DataModule
from pl_bolts.models.self_supervised.simclr import SimCLREvalDataTransform, SimCLRTrainDataTransform

seed_everything(1234)

Expand Down
8 changes: 4 additions & 4 deletions pl_bolts/models/self_supervised/cpc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pl_bolts.models.self_supervised.cpc.cpc_module import CPCV2
from pl_bolts.models.self_supervised.cpc.networks import cpc_resnet101, cpc_resnet50
from pl_bolts.models.self_supervised.cpc.networks import cpc_resnet50, cpc_resnet101
from pl_bolts.models.self_supervised.cpc.transforms import (
CPCTrainTransformsCIFAR10,
CPCEvalTransformsCIFAR10,
CPCTrainTransformsSTL10,
CPCEvalTransformsImageNet128,
CPCEvalTransformsSTL10,
CPCTrainTransformsCIFAR10,
CPCTrainTransformsImageNet128,
CPCEvalTransformsImageNet128
CPCTrainTransformsSTL10,
)
2 changes: 1 addition & 1 deletion pl_bolts/models/self_supervised/cpc/cpc_finetuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from pl_bolts.models.self_supervised import CPCV2, SSLFineTuner
from pl_bolts.models.self_supervised.cpc.transforms import (
CPCEvalTransformsCIFAR10,
CPCEvalTransformsSTL10,
CPCTrainTransformsCIFAR10,
CPCTrainTransformsSTL10,
CPCEvalTransformsSTL10,
)


Expand Down
Loading