Question
How to get a Hydra config without using @hydra.main()
Let's say we have following setup (copied & shortened from the Hydra docs):
Configuration file: config.yaml
db:
driver: mysql
user: omry
pass: secret
Python file: my_app.py
import hydra
@hydra.main(config_path="config.yaml")
def my_app(cfg):
print(cfg.pretty())
if __name__ == "__main__":
my_app()
This works well when we can use a decorator on the function my_app
. Now I would like (for small scripts and testing purposes, but that is not important) to get this cfg
object outside of any function, just in a plain python script. From what I understand how decorators work, it should be possible to call
import hydra
cfg = hydra.main(config_path="config.yaml")(lambda x: x)()
print(cfg.pretty())
but then cfg
is just None
and not the desired configuration object. So it seems that the decorator does not pass on the returned values. Is there another way to get to that cfg
?