Skip to content

Commit

Permalink
fix(hydra/utils): simplify search_path creation
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia committed Jul 22, 2023
1 parent 26e3d7e commit a7d5bec
Showing 1 changed file with 56 additions and 50 deletions.
106 changes: 56 additions & 50 deletions src/hyfi/core/hydra/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from hydra.types import TaskFunction

from hyfi.core import __config_module_path__
from hyfi.core.hydra import get_caller_config_module_path
from hyfi.core.hydra import create_config_search_path

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -52,55 +52,61 @@ def _run_hydra(
) = detect_calling_file_or_module_from_stack_frame(caller_stack_depth + 1)
task_name = detect_task_name(calling_file, calling_module)

validate_config_path(config_path)

search_path = create_automatic_config_search_path(
calling_file, calling_module, config_path
)

def add_conf_dir() -> None:
if args.config_dir is not None:
abs_config_dir = os.path.abspath(args.config_dir)
if not os.path.isdir(abs_config_dir):
raise SearchPathException(
f"Additional config directory '{abs_config_dir}' not found"
)
search_path.prepend(
provider="command-line",
path=f"file://{abs_config_dir}",
anchor=SearchPathQuery(provider="schema"),
)

run_and_report(add_conf_dir)

def add_hyfi_conf() -> None:
path = f"pkg://{__config_module_path__}"
for sp_item in search_path.get_path():
if sp_item.path == path:
log.debug("HyFI config path already in search path")
return
log.debug("Adding hyfi to the config search path")
search_path.prepend(
provider="hyfi",
path=path,
)

run_and_report(add_hyfi_conf)

def add_caller_conf() -> None:
caller_config_path = get_caller_config_module_path()
path = f"pkg://{caller_config_path}"
for sp_item in search_path.get_path():
if sp_item.path == path:
log.debug("Caller config path already in search path")
return
log.debug("Adding %s to the config search path", caller_config_path)
search_path.prepend(
provider="caller",
path=path,
)

run_and_report(add_caller_conf)
abs_config_dir = None
calling_module_path = None
if args.config_dir:
abs_config_dir = os.path.abspath(args.config_dir)
if calling_module:
calling_module_path = f"{calling_module.split('.')[0]}.{config_path}"
search_path = create_config_search_path(calling_module_path, abs_config_dir)
# validate_config_path(config_path)
# search_path = create_automatic_config_search_path(
# calling_file, calling_module, config_path
# )

# def add_conf_dir() -> None:
# if args.config_dir is not None:
# abs_config_dir = os.path.abspath(args.config_dir)
# if not os.path.isdir(abs_config_dir):
# raise SearchPathException(
# f"Additional config directory '{abs_config_dir}' not found"
# )
# search_path.prepend(
# provider="command-line",
# path=f"file://{abs_config_dir}",
# anchor=SearchPathQuery(provider="schema"),
# )

# run_and_report(add_conf_dir)

# def add_hyfi_conf() -> None:
# path = f"pkg://{__config_module_path__}"
# for sp_item in search_path.get_path():
# if sp_item.path == path:
# log.debug("HyFI config path already in search path")
# return
# log.debug("Adding hyfi to the config search path")
# search_path.prepend(
# provider="hyfi",
# path=path,
# )

# run_and_report(add_hyfi_conf)

# def add_caller_conf() -> None:
# caller_config_path = get_caller_config_module_path()
# path = f"pkg://{caller_config_path}"
# for sp_item in search_path.get_path():
# if sp_item.path == path:
# log.debug("Caller config path already in search path")
# return
# log.debug("Adding %s to the config search path", caller_config_path)
# search_path.prepend(
# provider="caller",
# path=path,
# )

# run_and_report(add_caller_conf)

hydra = run_and_report(
lambda: Hydra.create_main_hydra2(
Expand Down

0 comments on commit a7d5bec

Please sign in to comment.