Skip to content

Commit

Permalink
changes due to learning from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwoer committed Jan 20, 2025
1 parent 3fdf027 commit 2f00b78
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
33 changes: 18 additions & 15 deletions alphadia/search_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def __init__(
self._config = self._init_config(
config, cli_config, extra_config, output_folder
)
self._config.to_yaml(os.path.join(output_folder, "frozen_config.yaml"))

logger.setLevel(logging.getLevelName(self._config["general"]["log_level"]))

self.raw_path_list = self._config[ConfigKeys.RAW_PATHS]
Expand All @@ -86,27 +88,18 @@ def _init_config(
) -> Config:
"""Initialize the config with default values and update with user defined values."""

default_config_path = os.path.join(
os.path.dirname(__file__), "constants", "default.yaml"
)
logger.info(f"loading config from {default_config_path}")
config = Config()
config.from_yaml(default_config_path)
config = SearchStep._load_default_config()

config_updates = []

if user_config:
logger.info("loading additional config provided via CLI")
# load update config from dict
if isinstance(user_config, dict):
user_config_update = Config(user_config, name=USER_DEFINED)
config_updates.append(user_config_update)
elif isinstance(user_config, Config):
if isinstance(user_config, Config):
config_updates.append(user_config)
else:
raise ValueError(
"'config' parameter must be of type 'dict' or 'Config'"
)
user_config_update = Config(user_config, name=USER_DEFINED)
config_updates.append(user_config_update)

if cli_config:
logger.info("loading additional config provided via CLI parameters")
Expand All @@ -120,13 +113,23 @@ def _init_config(
extra_config_update[ConfigKeys.OUTPUT_DIRECTORY] = output_folder
config_updates.append(extra_config_update)

config.update(config_updates, do_print=True)
if config_updates:
config.update(config_updates, do_print=True)

if config.get(ConfigKeys.OUTPUT_DIRECTORY, None) is None:
config[ConfigKeys.OUTPUT_DIRECTORY] = output_folder

config.to_yaml(os.path.join(output_folder, "frozen_config.yaml"))
return config

@staticmethod
def _load_default_config():
"""Load default config from file."""
default_config_path = os.path.join(
os.path.dirname(__file__), "constants", "default.yaml"
)
logger.info(f"loading config from {default_config_path}")
config = Config()
config.from_yaml(default_config_path)
return config

@property
Expand Down
3 changes: 3 additions & 0 deletions alphadia/workflow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def __setitem__(self, key, item):
def __delitem__(self, key):
raise NotImplementedError("Use update() to update the config.")

def copy(self):
raise NotImplementedError("Use deepcopy() to copy the config.")

def update(self, configs: list["Config"], do_print: bool = False):
"""
Updates the config with one or more other config objects.
Expand Down

0 comments on commit 2f00b78

Please sign in to comment.