Skip to content

Commit

Permalink
fix: add config check step to project
Browse files Browse the repository at this point in the history
  • Loading branch information
AngRodrigues committed Jan 8, 2025
1 parent b9663d6 commit 06ff551
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
25 changes: 0 additions & 25 deletions map2loop/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,31 +213,6 @@ def update_from_file(
err_string += "Check the contents for mismatched quotes or brackets!"
raise Exception(err_string)

@beartype.beartype
def validate_config_dictionary(self, config_dict: dict) -> None:
required_keys = {
"structure": {"dipdir_column", "dip_column"},
"geology": {"unitname_column", "alt_unitname_column"},
}

# Loop over "structure" and "geology"
for section, keys in required_keys.items():

# 1) Check that "section" exists
if section not in config_dict:
logger.error(f"Missing required section '{section}' in config dictionary.")
raise ValueError(f"Missing required section '{section}' in config dictionary.")

# 2) Check that each required key is in config_dict[section]
for key in keys:
if key not in config_dict[section]:
logger.error(
f"Missing required key '{key}' for '{section}' section of the config dictionary."
)
raise ValueError(
f"Missing required key '{key}' for '{section}' section of the config dictionary."
)


@beartype.beartype
def check_for_legacy_keys(self, config_dict: dict) -> None:
Expand Down
27 changes: 27 additions & 0 deletions map2loop/data_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,30 @@ def check_fault_fields_validity(mapdata) -> Tuple[bool, str]:
)

return (False, "")


@beartype.beartype
def validate_config_dictionary(config_dict: dict) -> None:

required_keys = {
"structure": {"dipdir_column", "dip_column"},
"geology": {"unitname_column", "alt_unitname_column"},
}

# Loop over "structure" and "geology"
for section, keys in required_keys.items():

# 1) Check that "section" exists
if section not in config_dict:
logger.error(f"Missing required section '{section}' in config dictionary.")
raise ValueError(f"Missing required section '{section}' in config dictionary.")

# 2) Check that each required key is in config_dict[section]
for key in keys:
if key not in config_dict[section]:
logger.error(
f"Missing required key '{key}' for '{section}' section of the config dictionary."
)
raise ValueError(
f"Missing required key '{key}' for '{section}' section of the config dictionary."
)
5 changes: 4 additions & 1 deletion map2loop/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .stratigraphic_column import StratigraphicColumn
from .deformation_history import DeformationHistory
from .map2model_wrapper import Map2ModelWrapper
from .data_checks import validate_config_dictionary

# external imports
import LoopProjectFile as LPF
Expand Down Expand Up @@ -231,8 +232,10 @@ def __init__(
self.map_data.set_config_filename(config_filename)

if config_dictionary != {}:
self.map_data.config.validate_config_dictionary(config_dictionary)
validate_config_dictionary(config_dictionary)
self.map_data.config.update_from_dictionary(config_dictionary)
# print(self.map_data.config)
# self.map_data.config.validate_config_dictionary(config_dictionary)

if clut_filename != "":
self.map_data.set_colour_filename(clut_filename)
Expand Down

0 comments on commit 06ff551

Please sign in to comment.