Skip to content

Commit

Permalink
update & rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
camillebrianceau committed Mar 19, 2024
1 parent ec48a69 commit bd7afde
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 96 deletions.
4 changes: 2 additions & 2 deletions clinicadl/hugging_face/hugging_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ def create_readme(
config_dict = toml.load(config_path)

train_dict = read_json(config_file)
train_dict = change_str_to_path(train_dict)
# train_dict = change_str_to_path(train_dict)

task = train_dict["network_task"]

config_dict = remove_unused_tasks(config_dict, task)
config_dict = change_str_to_path(config_dict)
# config_dict = change_str_to_path(config_dict)

file = open("tmp_README.md", "w")
list_lines = []
Expand Down
3 changes: 1 addition & 2 deletions clinicadl/utils/maps_manager/maps_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
)
from clinicadl.utils.maps_manager.ddp import DDP, cluster, init_ddp
from clinicadl.utils.maps_manager.logwriter import LogWriter
from clinicadl.utils.maps_manager.maps_manager_utils import (
from clinicadl.utils.maps_manager.maps_manager_utils import ( # change_str_to_path,
add_default_values,
change_str_to_path,
read_json,
)
from clinicadl.utils.metric_module import RetainBest
Expand Down
184 changes: 92 additions & 92 deletions clinicadl/utils/maps_manager/maps_manager_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,95 +175,95 @@ def remove_unused_tasks(
return toml_dict


def change_str_to_path(
toml_dict: Dict[str, Dict[str, Any]]
) -> Dict[str, Dict[str, Any]]:
"""
For all paths in the dictionnary, it changes the type from str to pathlib.Path.
Paramaters
----------
toml_dict: Dict[str, Dict[str, Any]]
Dictionary of options as written in a TOML file, with type(path)=str
Returns
-------
Updated TOML dictionary with type(path)=pathlib.Path
"""
for key, value in toml_dict.items():
if type(value) == Dict:
for key2, value2 in value.items():
if (
key2.endswith("tsv")
or key2.endswith("dir")
or key2.endswith("directory")
or key2.endswith("path")
or key2.endswith("json")
or key2.endswith("location")
):
if value2 == "":
toml_dict[value][key2] = False
else:
toml_dict[value][key2] = Path(value2)
else:
if (
key.endswith("tsv")
or key.endswith("dir")
or key.endswith("directory")
or key.endswith("path")
or key.endswith("json")
or key.endswith("location")
):
if value == "" or value is False:
toml_dict[key] = False
else:
toml_dict[key] = Path(value)
return toml_dict


def change_path_to_str(
toml_dict: Dict[str, Dict[str, Any]]
) -> Dict[str, Dict[str, Any]]:
"""
For all paths in the dictionnary, it changes the type from pathlib.Path to str.
Paramaters
----------
toml_dict: Dict[str, Dict[str, Any]]
Dictionary of options as written in a TOML file, with type(path)=pathlib.Path
Returns
-------
Updated TOML dictionary with type(path)=str
"""
for key, value in toml_dict.items():
if type(value) == Dict:
for key2, value2 in value.items():
if (
key2.endswith("tsv")
or key2.endswith("dir")
or key2.endswith("directory")
or key2.endswith("path")
or key2.endswith("json")
or key2.endswith("location")
):
if value2 == False:
toml_dict[value][key2] = ""
elif isinstance(value2, Path):
toml_dict[value][key2] = value2.as_posix()
else:
if (
key.endswith("tsv")
or key.endswith("dir")
or key.endswith("directory")
or key.endswith("path")
or key.endswith("json")
or key.endswith("location")
):
if value == False:
toml_dict[key] = ""
elif isinstance(value, Path):
toml_dict[key] = value.as_posix()
if isinstance(value, Path):
toml_dict[key] = value.as_posix()
return toml_dict
# def change_str_to_path(
# toml_dict: Dict[str, Dict[str, Any]]
# ) -> Dict[str, Dict[str, Any]]:
# """
# For all paths in the dictionnary, it changes the type from str to pathlib.Path.

# Paramaters
# ----------
# toml_dict: Dict[str, Dict[str, Any]]
# Dictionary of options as written in a TOML file, with type(path)=str

# Returns
# -------
# Updated TOML dictionary with type(path)=pathlib.Path
# """
# for key, value in toml_dict.items():
# if type(value) == Dict:
# for key2, value2 in value.items():
# if (
# key2.endswith("tsv")
# or key2.endswith("dir")
# or key2.endswith("directory")
# or key2.endswith("path")
# or key2.endswith("json")
# or key2.endswith("location")
# ):
# if value2 == "":
# toml_dict[value][key2] = False
# else:
# toml_dict[value][key2] = Path(value2)
# else:
# if (
# key.endswith("tsv")
# or key.endswith("dir")
# or key.endswith("directory")
# or key.endswith("path")
# or key.endswith("json")
# or key.endswith("location")
# ):
# if value == "" or value is False:
# toml_dict[key] = False
# else:
# toml_dict[key] = Path(value)
# return toml_dict


# def change_path_to_str(
# toml_dict: Dict[str, Dict[str, Any]]
# ) -> Dict[str, Dict[str, Any]]:
# """
# For all paths in the dictionnary, it changes the type from pathlib.Path to str.

# Paramaters
# ----------
# toml_dict: Dict[str, Dict[str, Any]]
# Dictionary of options as written in a TOML file, with type(path)=pathlib.Path

# Returns
# -------
# Updated TOML dictionary with type(path)=str
# """
# for key, value in toml_dict.items():
# if type(value) == Dict:
# for key2, value2 in value.items():
# if (
# key2.endswith("tsv")
# or key2.endswith("dir")
# or key2.endswith("directory")
# or key2.endswith("path")
# or key2.endswith("json")
# or key2.endswith("location")
# ):
# if value2 == False:
# toml_dict[value][key2] = ""
# elif isinstance(value2, Path):
# toml_dict[value][key2] = value2.as_posix()
# else:
# if (
# key.endswith("tsv")
# or key.endswith("dir")
# or key.endswith("directory")
# or key.endswith("path")
# or key.endswith("json")
# or key.endswith("location")
# ):
# if value == False:
# toml_dict[key] = ""
# elif isinstance(value, Path):
# toml_dict[key] = value.as_posix()
# if isinstance(value, Path):
# toml_dict[key] = value.as_posix()
# return toml_dict

0 comments on commit bd7afde

Please sign in to comment.