This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to override configs (#7)
- Loading branch information
1 parent
91c0393
commit 30f3ecf
Showing
12 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# Ahcore | ||
additional_config/* | ||
scripts/* | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
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
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
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,4 @@ | ||
"""Hydra plugins for ahcore.""" | ||
from .additional_configs import register_additional_config_search_path | ||
|
||
__all__ = ("register_additional_config_search_path",) |
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,53 @@ | ||
import warnings | ||
from pathlib import Path | ||
|
||
from hydra.core.config_search_path import ConfigSearchPath | ||
from hydra.core.plugins import Plugins | ||
from hydra.plugins.search_path_plugin import SearchPathPlugin | ||
|
||
from ahcore.exceptions import ConfigurationError | ||
from ahcore.utils.io import get_logger | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class AdditionalSearchPathPlugin(SearchPathPlugin): | ||
"""This plugin allows to overwrite the ahcore configurations without needed to fork the repository.""" | ||
|
||
def manipulate_search_path(self, search_path: ConfigSearchPath) -> None: | ||
additional_path = Path(__file__).parent.parent.parent / "additional_config" | ||
if additional_path.is_file(): | ||
raise ConfigurationError("Found additional_config file, but expected a folder.") | ||
|
||
elif additional_path.is_dir(): | ||
if not list(additional_path.glob("*")): | ||
warnings.warn( | ||
f"Found additional_config folder in {additional_path}, without any configuration files. " | ||
"If you want to overwrite the default ahcore configs, " | ||
"please add these to the additional_config folder. " | ||
"You can symlink your additional configuration to this folder. " | ||
"See the documentation at https://docs.aiforoncology.nl/ahcore/configuration.html " | ||
"for more information." | ||
) | ||
else: | ||
# Add additional search path for configs | ||
logger.info(f"Adding additional search path for configs: file://{additional_path}") | ||
search_path.prepend(provider="hydra-ahcore", path=f"file://{additional_path}") | ||
else: | ||
logger.info( | ||
"No additional_config folder found. Will use standard ahcore configurations." | ||
"If you want to overwrite or extend the default ahcore configs, you can add these to the " | ||
"additional_config folder. You could also symlink your additional configuration to this folder." | ||
"See the documentation at https://docs.aiforoncology.nl/ahcore/configuration.html." | ||
) | ||
|
||
|
||
def register_additional_config_search_path() -> None: | ||
""" | ||
Register the additional_config folder as a search path for hydra. | ||
Returns | ||
------- | ||
None | ||
""" | ||
Plugins.instance().register(AdditionalSearchPathPlugin) |
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
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,9 @@ | ||
Configuration | ||
============= | ||
|
||
Ahcore is configured using Hydra. In the ahcore main folder there is a folder `config`, | ||
these contain the standard configuration files. The configuration files are in YAML format according | ||
to the Hydra specification. | ||
|
||
If you want to add your own configuration files, you can do so by creating a new folder in the `additional_config` | ||
folder. The configuration files here will override the standard configuration files. |
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
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
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
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
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