Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions hydra/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ def compute_search_path_dir(
calling_module: Optional[str],
config_path: Optional[str],
) -> Optional[str]:
if config_path is not None and os.path.isabs(config_path):
search_path_dir = config_path
elif calling_file is not None:
if config_path is not None:
if os.path.isabs(config_path):
return config_path
if config_path.startswith("pkg://"):
return config_path

if calling_file is not None:
abs_base_dir = realpath(dirname(calling_file))

if config_path is not None:
Expand Down
6 changes: 5 additions & 1 deletion hydra/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ def main(
version_base: Optional[str] = _UNSPECIFIED_,
) -> Callable[[TaskFunction], Any]:
"""
:param config_path: The config path, a directory relative to the declaring python file.
:param config_path: The config path, a directory where Hydra will search for
config files. This path is added to Hydra's searchpath.
Relative paths are interpreted relative to the declaring python
file. Alternatively, you can use the prefix `pkg://` to specify
a python package to add to the searchpath.
If config_path is None no directory is added to the Config search path.
:param config_name: The name of the config (usually the file name without the .yaml extension)
"""
Expand Down
1 change: 1 addition & 0 deletions news/2564.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow config_path to specify a non-relative module path, by starting with `pkg://`
1 change: 1 addition & 0 deletions tests/test_config_search_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def test_prepend(
"../conf",
realpath(os.path.join(os.getcwd(), "../conf")),
),
(None, "package.module", "pkg://some/conf", "pkg://some/conf"),
],
)
def test_compute_search_path_dir(
Expand Down