Skip to content

Commit

Permalink
fix(composer): add method to check if configuration is composable
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia committed Jul 21, 2023
1 parent c33f55a commit f414c9f
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/hyfi/composer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import re
from enum import Enum
from typing import Any, Callable, Dict, List, Mapping, Set, Tuple, Union
from typing import Any, Callable, Dict, List, Mapping, Set, Tuple, Union, Optional

import hydra
from hydra.core.global_hydra import GlobalHydra
Expand Down Expand Up @@ -216,6 +216,32 @@ def hydra_compose(
cfg = hydra.compose(config_name=root_config_name, overrides=overrides)
return cfg

@staticmethod
def is_composable(
config_group: str,
config_module: Optional[str] = None,
) -> bool:
"""
Determines whether the input configuration object is composable.
Args:
config_group (str): The name of the configuration group to check.
config_module (Optional[str], optional): The name of the configuration module to check. Defaults to None.
Returns:
bool: True if the configuration object is composable, False otherwise.
"""
try:
cfg = Composer.hydra_compose(
root_config_name=config_group,
config_module=config_module,
overrides=[],
)
return cfg is not None
except Exception as e:
logger.error("Error composing config: %s", e)
return False

@staticmethod
def split_config_group(
config_group: Union[str, None] = None,
Expand Down

0 comments on commit f414c9f

Please sign in to comment.