Skip to content

Commit

Permalink
Run unittets and cleaning (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultdvx authored Jun 14, 2024
1 parent 5df49b3 commit 3547ca1
Show file tree
Hide file tree
Showing 52 changed files with 50 additions and 189 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: 'Lint codebase'

on:
pull_request:
branches: [ dev ]
branches: [ "dev", "refactoring" ]
push:
branches: [ dev ]
branches: [ "dev", "refactoring" ]

permissions:
contents: read
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Test

on:
push:
branches: [dev]
branches: ["dev", "refactoring"]
pull_request:
branches: [dev]
branches: ["dev", "refactoring"]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_interpret.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_predict.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_prepare_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_quality_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_random_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_resume.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_train.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_transfer_learning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_tsvtools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ["dev", "refactoring"]
pull_request:
branches: ["dev", "refactoring"]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ help: Makefile

.PHONY: check.lock
check.lock:
@$(POETRY) lock --check
@$(POETRY) check --lock

## build : Build the package.
.PHONY: build
Expand Down
9 changes: 2 additions & 7 deletions clinicadl/callbacks/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from abc import ABC, abstractmethod
from enum import Enum
from logging import getLogger
from pathlib import Path
from typing import Any, Dict, Optional, Tuple
from typing import Optional

from pydantic import BaseModel, ConfigDict, computed_field, field_validator
from pydantic.types import NonNegativeFloat, NonNegativeInt, PositiveFloat, PositiveInt
from pydantic import BaseModel, ConfigDict

from clinicadl.preprocessing.preprocessing import read_preprocessing
from clinicadl.utils.enum import ExperimentTracking

logger = getLogger("clinicadl.callbacks_config")
Expand Down
2 changes: 1 addition & 1 deletion clinicadl/caps_dataset/data_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DataConfig(BaseModel): # TODO : put in data module
diagnoses: Tuple[str, ...] = ("AD", "CN")
data_df: Optional[pd.DataFrame] = None
label: Optional[str] = None
label_code: Union[str, dict[str, int], None] = {}
label_code: Union[str, Dict[str, int], None] = {}
multi_cohort: bool = False
mask_path: Optional[Path] = None
preprocessing_json: Optional[Path] = None
Expand Down
1 change: 0 additions & 1 deletion clinicadl/caps_dataset/data_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding: utf8
# TODO: create a folder for generate/ prepare_data/ data to deal with capsDataset objects ?
import abc
from logging import getLogger
from pathlib import Path
from typing import Any, Callable, Dict, Optional
Expand Down
1 change: 0 additions & 1 deletion clinicadl/commandline/modules_options/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# from .task import classification, reconstruction, regression
1 change: 0 additions & 1 deletion clinicadl/commandline/modules_options/caps_dataset.py

This file was deleted.

1 change: 0 additions & 1 deletion clinicadl/commandline/modules_options/computational.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from clinicadl.config.config.computational import ComputationalConfig
from clinicadl.config.config_utils import get_default_from_config_class as get_default
from clinicadl.config.config_utils import get_type_from_config_class as get_type

# Computational
amp = click.option(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import get_args

import click

from clinicadl.config.config_utils import get_default_from_config_class as get_default
Expand Down
1 change: 0 additions & 1 deletion clinicadl/commandline/pipelines/generate/trivial/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import tarfile
from logging import getLogger
from pathlib import Path

Expand Down
1 change: 0 additions & 1 deletion clinicadl/commandline/pipelines/predict/options.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import click

from clinicadl.config.config_utils import get_default_from_config_class as get_default
from clinicadl.config.config_utils import get_type_from_config_class as get_type
from clinicadl.predict.config import PredictConfig

# predict specific
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from typing import Optional

import click

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import click

from clinicadl.caps_dataset.caps_dataset_config import CapsDatasetConfig
from clinicadl.commandline import arguments
from clinicadl.commandline.modules_options import (
Expand All @@ -10,9 +10,6 @@
)
from clinicadl.prepare_data.prepare_data import DeepLearningPrepareData
from clinicadl.utils.enum import ExtractionMethod
from clinicadl.commandline import arguments
from clinicadl.commandline.modules_options import data, dataloader, modality, preprocessing
from clinicadl.utils.enum import ExtractionMethod


@click.command(name="image", no_args_is_help=True)
Expand All @@ -27,7 +24,6 @@
@modality.custom_suffix
@data.participants_tsv
def image_bids_cli(kwargs):

image_config = CapsDatasetConfig.from_preprocessing_and_extraction_method(
extraction=ExtractionMethod.IMAGE,
preprocessing_type=kwargs["preprocessing"],
Expand Down
2 changes: 0 additions & 2 deletions clinicadl/config/config/maps_manager.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from enum import Enum
from logging import getLogger
from pathlib import Path
from typing import Optional

from pydantic import BaseModel, ConfigDict

from clinicadl.utils.exceptions import ClinicaDLArgumentError # type: ignore
from clinicadl.utils.maps_manager.maps_manager import MapsManager # type: ignore

logger = getLogger("clinicadl.predict_config")

Expand Down
2 changes: 1 addition & 1 deletion clinicadl/config/config_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typing
from enum import Enum
from typing import Any, get_args, get_origin
from typing import Any, get_args

import click
from pydantic import BaseModel
Expand Down
29 changes: 12 additions & 17 deletions clinicadl/generate/generate_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import tarfile
from logging import getLogger
from pathlib import Path
from time import time
Expand All @@ -14,22 +13,8 @@
field_validator,
)

from clinicadl.utils.clinica_utils import (
RemoteFileStructure,
clinicadl_file_reader,
fetch_file,
)
from clinicadl.utils.enum import (
Pathology,
Preprocessing,
SUVRReferenceRegions,
Tracer,
)
from clinicadl.utils.exceptions import (
ClinicaDLArgumentError,
ClinicaDLTSVError,
DownloadError,
)
from clinicadl.utils.enum import Pathology
from clinicadl.utils.exceptions import ClinicaDLArgumentError

logger = getLogger("clinicadl.predict_config")

Expand All @@ -52,6 +37,8 @@ class GenerateArtifactsConfig(BaseModel):
noise_std: Tuple[NonNegativeFloat, NonNegativeFloat] = (5.0, 15.0)
rotation: Tuple[NonNegativeFloat, NonNegativeFloat] = (2.0, 4.0) # float o int ???
translation: Tuple[NonNegativeFloat, NonNegativeFloat] = (2.0, 4.0)
# pydantic config
model_config = ConfigDict(validate_assignment=True)

@field_validator("gamma", "noise_std", "rotation", "translation", mode="before")
def list_to_tuples(cls, v):
Expand Down Expand Up @@ -85,16 +72,22 @@ class GenerateHypometabolicConfig(BaseModel):
anomaly_degree: NonNegativeFloat = 30.0
pathology: Pathology = Pathology.AD
sigma: NonNegativeFloat = 5
# pydantic config
model_config = ConfigDict(validate_assignment=True)


class GenerateRandomConfig(BaseModel):
mean: NonNegativeFloat = 0.0
sigma: NonNegativeFloat = 0.5
# pydantic config
model_config = ConfigDict(validate_assignment=True)


class GenerateTrivialConfig(BaseModel):
atrophy_percent: PositiveFloat = 60.0
mask_path: Optional[Path] = None
# pydantic config
model_config = ConfigDict(validate_assignment=True)


class GenerateSheppLoganConfig(BaseModel):
Expand All @@ -107,6 +100,8 @@ class GenerateSheppLoganConfig(BaseModel):
extract_json: Optional[str] = None
image_size: PositiveInt = 128
smoothing: bool = False
# pydantic config
model_config = ConfigDict(validate_assignment=True)

@field_validator("extract_json", mode="before")
def compute_extract_json(cls, v: str):
Expand Down
6 changes: 1 addition & 5 deletions clinicadl/generate/generate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import random
from copy import copy
from pathlib import Path
from typing import Dict, Optional, Union
from typing import Dict, Optional

import numpy as np
import pandas as pd
from pydantic import BaseModel
from scipy.ndimage import gaussian_filter
from skimage.draw import ellipse

Expand All @@ -22,15 +21,12 @@
from clinicadl.utils.enum import (
LinearModality,
Preprocessing,
SUVRReferenceRegions,
Tracer,
)

# from clinicadl.caps_dataset.caps_dataset_config import CapsDatasetConfig
from clinicadl.utils.exceptions import (
ClinicaDLArgumentError,
ClinicaDLTSVError,
DownloadError,
)


Expand Down
3 changes: 0 additions & 3 deletions clinicadl/hugging_face/pull_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from pathlib import Path

import click

from clinicadl.utils import cli_param
from clinicadl.utils.maps_manager import MapsManager


@click.command(name="pull", no_args_is_help=True)
Expand Down
6 changes: 1 addition & 5 deletions clinicadl/interpret/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from enum import Enum
from logging import getLogger
from pathlib import Path
from typing import Dict, Optional, Union
from typing import Optional

from pydantic import BaseModel, field_validator

from clinicadl.caps_dataset.data_config import DataConfig as DataBaseConfig
from clinicadl.caps_dataset.data_utils import (
load_data_test,
)
from clinicadl.caps_dataset.dataloader_config import DataLoaderConfig
from clinicadl.config.config.computational import ComputationalConfig
from clinicadl.config.config.cross_validation import CrossValidationConfig
Expand Down
1 change: 0 additions & 1 deletion clinicadl/mlflow_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
import sys
import warnings
from urllib.parse import urlparse
Expand Down
2 changes: 1 addition & 1 deletion clinicadl/network/autoencoder/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from torch import nn

from clinicadl.network.autoencoder.cnn_transformer import CNN_Transformer
from clinicadl.network.cnn.models import Conv4_FC3, Conv5_FC3, resnet18
from clinicadl.network.cnn.models import Conv4_FC3, Conv5_FC3
from clinicadl.network.sub_network import AutoEncoder
from clinicadl.network.vae.vae_layers import (
DecoderLayer3D,
Expand Down
1 change: 0 additions & 1 deletion clinicadl/network/cnn/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from clinicadl.network.network_utils import *
from clinicadl.network.sub_network import CNN
from clinicadl.utils.enum import Normalization
from clinicadl.utils.exceptions import ClinicaDLNetworksError


Expand Down
2 changes: 0 additions & 2 deletions clinicadl/predict/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from logging import getLogger

from pydantic import BaseModel

from clinicadl.caps_dataset.data_config import DataConfig as DataBaseConfig
from clinicadl.caps_dataset.dataloader_config import DataLoaderConfig
from clinicadl.config.config.maps_manager import (
Expand Down
Loading

0 comments on commit 3547ca1

Please sign in to comment.