Skip to content

Commit

Permalink
print out hydra.searchpath value if available (#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
jieru-hu authored Apr 14, 2021
1 parent ce6add4 commit c1ffab5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
17 changes: 13 additions & 4 deletions hydra/_internal/hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,29 @@ def _print_search_path(

box: List[List[str]] = [["Provider", "Search path"]]

for sp in self.config_loader.get_sources():
box.append([sp.provider, sp.full_path()])
cfg = self._get_cfg(
config_name=config_name,
overrides=overrides,
cfg_type="hydra",
with_log_configuration=False,
)

sources = cfg.hydra.runtime.config_sources

for sp in sources:
box.append([sp.provider, f"{sp.schema}://{sp.path}"])

provider_pad, search_path_pad = get_column_widths(box)
header = "| {} | {} |".format(
"Provider".ljust(provider_pad), "Search path".ljust(search_path_pad)
)
self._log_header(header=header, filler="-")

for source in self.config_loader.get_sources():
for source in sources:
log.debug(
"| {} | {} |".format(
source.provider.ljust(provider_pad),
source.full_path().ljust(search_path_pad),
f"{source.schema}://{source.path}".ljust(search_path_pad),
)
)
self._log_footer(header=header, filler="-")
Expand Down
27 changes: 27 additions & 0 deletions tests/test_hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,33 @@ def test_help(
assert_text_same(result, expected.format(script=script))


@mark.parametrize(
"script,overrides,expected",
[
param(
"examples/tutorials/basic/your_first_hydra_app/1_simple_cli/my_app.py",
["hydra.searchpath=['pkg://fakeconf']"],
r".*hydra.searchpath in command-line\s+|\s+pkg://fakeconf.*",
id="searchpath config from command-line",
),
param(
"examples/advanced/config_search_path/my_app.py",
[],
r".*hydra.searchpath in main\s+|\s+pkg://additonal_conf.*",
id="searchpath config from config file",
),
],
)
def test_searchpath_config(
tmpdir: Path, script: str, overrides: List[str], expected: str
) -> None:
cmd = [script, "--info", "searchpath"]
cmd.extend(overrides)
cmd.extend(["hydra.run.dir=" + str(tmpdir)])
result, _err = run_python_script(cmd)
assert re.match(expected, result, re.DOTALL)


@mark.parametrize(
"calling_file, calling_module",
[
Expand Down

0 comments on commit c1ffab5

Please sign in to comment.