Skip to content

Commit

Permalink
fix: searchpath plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
JesperDramsch committed Aug 2, 2024
1 parent 91f88d9 commit 1e98132
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
11 changes: 10 additions & 1 deletion src/hydra_plugins/anemoi_searchpath/anemoi_searchpath_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# (C) Copyright 2024 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

import logging
import os
from pathlib import Path
Expand All @@ -24,6 +32,7 @@ def manipulate_search_path(self, search_path: ConfigSearchPath) -> None:
----------
search_path : ConfigSearchPath
Hydra ConfigSearchPath object.
"""
for suffix in ("", "config"):
anemoi_home_path = Path(Path.home(), ".config", "anemoi", "training", suffix)
Expand All @@ -38,7 +47,7 @@ def manipulate_search_path(self, search_path: ConfigSearchPath) -> None:
for suffix in ("", "config"):
env_anemoi_config_path = os.getenv("ANEMOI_CONFIG_PATH")
if env_anemoi_config_path is None:
return
continue
anemoi_config_path = Path(env_anemoi_config_path)
if anemoi_config_path.exists() and not Path(anemoi_config_path, "config").exists():
search_path.prepend(
Expand Down
25 changes: 10 additions & 15 deletions tests/hydra/test_search_path_plugins.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
# (C) Copyright 2024 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

from hydra import initialize
from hydra.core.global_hydra import GlobalHydra
from hydra.core.plugins import Plugins
from hydra.plugins.search_path_plugin import SearchPathPlugin

from hydra_plugins.anemoi_searchpath.anemoi_searchpath_plugin import AnemoiEnvSearchPathPlugin
from hydra_plugins.anemoi_searchpath.anemoi_searchpath_plugin import AnemoiHomeSearchPathPlugin
from hydra_plugins.anemoi_searchpath.anemoi_searchpath_plugin import UserCWDSearchPathPlugin
from hydra_plugins.anemoi_searchpath.anemoi_searchpath_plugin import AnemoiSearchPathPlugin


def test_anemoi_home_searchpath_discovery() -> None:
# Tests that this plugin can be discovered via the plugins subsystem when looking at all Plugins
assert AnemoiHomeSearchPathPlugin.__name__ in [x.__name__ for x in Plugins.instance().discover(SearchPathPlugin)]


def test_anemoi_env_searchpath_discovery() -> None:
# Tests that this plugin can be discovered via the plugins subsystem when looking at all Plugins
assert AnemoiEnvSearchPathPlugin.__name__ in [x.__name__ for x in Plugins.instance().discover(SearchPathPlugin)]


def test_anemoi_cwd_searchpath_discovery() -> None:
# Tests that this plugin can be discovered via the plugins subsystem when looking at all Plugins
assert UserCWDSearchPathPlugin.__name__ in [x.__name__ for x in Plugins.instance().discover(SearchPathPlugin)]
assert AnemoiSearchPathPlugin.__name__ in [x.__name__ for x in Plugins.instance().discover(SearchPathPlugin)]


def test_config_installed() -> None:
Expand Down

0 comments on commit 1e98132

Please sign in to comment.