Skip to content

Commit

Permalink
use log_and_warn function
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGensollen committed Aug 6, 2024
1 parent 2d489ef commit a81b4bb
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions clinica/utils/caps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import json
import warnings
from pathlib import Path
from typing import IO, List, MutableSequence, Optional

Expand All @@ -11,7 +10,7 @@
from clinica.utils.bids import BIDS_VERSION
from clinica.utils.exceptions import ClinicaBIDSError, ClinicaCAPSError
from clinica.utils.inputs import DatasetType
from clinica.utils.stream import log_and_raise
from clinica.utils.stream import log_and_raise, log_and_warn

__all__ = [
"CAPS_VERSION",
Expand Down Expand Up @@ -210,9 +209,12 @@ def add_processing(
processing_name, processing_output_path, processing_input_path
)
if (existing_processing := self.get_processing(processing_name)) is not None:
warnings.warn(
f"The CAPS dataset '{self.name}' already has a processing named {processing_name}:\n"
f"{existing_processing}\nIt will be overwritten with the following:\n{new_processing}"
log_and_warn(
(
f"The CAPS dataset '{self.name}' already has a processing named {processing_name}:\n"
f"{existing_processing}\nIt will be overwritten with the following:\n{new_processing}"
),
UserWarning,
)
self.delete_processing(existing_processing.name)
self.processing.append(new_processing)
Expand Down Expand Up @@ -444,9 +446,12 @@ def build_caps_dataset_description(
try:
bids_version_from_input_dir = _get_bids_version(input_dir)
except ClinicaBIDSError:
warnings.warn(
f"Unable to retrieve the BIDS version from the input folder {input_dir}."
f"Please verify your input dataset. Clinica will assume a BIDS version of {BIDS_VERSION}."
log_and_warn(
(
f"Unable to retrieve the BIDS version from the input folder {input_dir}."
f"Please verify your input dataset. Clinica will assume a BIDS version of {BIDS_VERSION}."
),
UserWarning,
)
if (
bids_version is not None
Expand Down Expand Up @@ -481,9 +486,12 @@ def build_caps_dataset_description(
)
log_and_raise(msg, ClinicaCAPSError)
if previous_desc.name != new_desc.name:
warnings.warn(
f"The existing CAPS dataset, located at {output_dir} has a name '{previous_desc.name}' different "
f"from the new name '{new_desc.name}'. The old name will be kept."
log_and_warn(
(
f"The existing CAPS dataset, located at {output_dir} has a name '{previous_desc.name}' different "
f"from the new name '{new_desc.name}'. The old name will be kept."
),
UserWarning,
)
new_desc.name = previous_desc.name
for processing in previous_desc.processing:
Expand Down

0 comments on commit a81b4bb

Please sign in to comment.