-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec6a374
commit da5fd45
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
50 changes: 50 additions & 0 deletions
50
src/hydra_plugins/anemoi_searchpath/anemoi_searchpath_plugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
from logging import getLogger | ||
from pathlib import Path | ||
|
||
from hydra.core.config_search_path import ConfigSearchPath | ||
from hydra.plugins.search_path_plugin import SearchPathPlugin | ||
|
||
LOGGER = getLogger(__name__) | ||
|
||
|
||
class AnemoiHomeSearchPathPlugin(SearchPathPlugin): | ||
"""Prepend the Anemoi home directory to the hydra searchpath.""" | ||
|
||
def manipulate_search_path(self, search_path: ConfigSearchPath) -> None: | ||
anemoi_home_path = Path(Path.home(), ".config", "anemoi", "training", "config") | ||
if anemoi_home_path.exists(): | ||
search_path.prepend( | ||
provider="anemoi-home-searchpath-plugin", | ||
path=str(anemoi_home_path), | ||
) | ||
LOGGER.info(f"Prepending {anemoi_home_path} to the search path.") | ||
LOGGER.debug(f"Search path is now: {search_path}") | ||
|
||
|
||
class AnemoiEnvSearchPathPlugin(SearchPathPlugin): | ||
"""Prepend the path env ANEMOI_CONFIG_PATH to hydra searchpath.""" | ||
|
||
def manipulate_search_path(self, search_path: ConfigSearchPath) -> None: | ||
anemoi_config_path = os.getenv("ANEMOI_CONFIG_PATH") | ||
if anemoi_config_path is not None and anemoi_config_path.exists(): | ||
search_path.prepend( | ||
provider="anemoi-env-searchpath-plugin", | ||
path=str(anemoi_config_path), | ||
) | ||
LOGGER.info(f"Appending {anemoi_config_path} to the search path.") | ||
LOGGER.debug(f"Search path is now: {search_path}") | ||
|
||
|
||
class UserCWDSearchPathPlugin(SearchPathPlugin): | ||
"""Prepend the current working directory to the hydra search path.""" | ||
|
||
def manipulate_search_path(self, search_path: ConfigSearchPath) -> None: | ||
cwd_path = Path(Path.cwd(), "config") | ||
if cwd_path.exists(): | ||
search_path.prepend( | ||
provider="anemoi-env-searchpath-plugin", | ||
path=str(cwd_path), | ||
) | ||
LOGGER.info(f"Appending {cwd_path} to the search path.") | ||
LOGGER.debug(f"Search path is now: {search_path}") |