Skip to content

Commit c3a64a8

Browse files
author
Adam Simpkins
committed
Allow specifying a non-relative module name in config_path
When constructing the config search path, allow callers to directly pass in a non-relative module name starting with `pkg://`. This allows callers to bypass the relative name lookup, and always get consistent behavior regardless of the current environment variables at runtime. This addresses issue #2564.
1 parent 9a7a094 commit c3a64a8

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

hydra/_internal/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,13 @@ def compute_search_path_dir(
123123
calling_module: Optional[str],
124124
config_path: Optional[str],
125125
) -> Optional[str]:
126-
if config_path is not None and os.path.isabs(config_path):
127-
search_path_dir = config_path
128-
elif calling_file is not None:
126+
if config_path is not None:
127+
if os.path.isabs(config_path):
128+
return config_path
129+
if config_path.startswith("pkg://"):
130+
return config_path
131+
132+
if calling_file is not None:
129133
abs_base_dir = realpath(dirname(calling_file))
130134

131135
if config_path is not None:

news/2564.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow config_path to specify a non-relative module path, by starting with `pkg://`

tests/test_config_search_path.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def test_prepend(
172172
"../conf",
173173
realpath(os.path.join(os.getcwd(), "../conf")),
174174
),
175+
(None, "package.module", "pkg://some/conf", "pkg://some/conf"),
175176
],
176177
)
177178
def test_compute_search_path_dir(

0 commit comments

Comments
 (0)