Consider the following yaml file for hydra config:
a:
b: !!python/object/apply:pathlib.PosixPath
- /my/path/to/dir
How would I override a.b so that is stays PosixPath after providing a new path?
Running
python my_app.py ++a.b=/a/new/path
overrides a.b but it's obiously a string. Looking for a solution that not only works but preferably does not require a user to re-enter constructor information.
One way I found is this:
Then overriding is via
Here, I'm using instantiate API, the
_target_is a target class of object (pathlib is natively supported), and since constructor signature ispathlib.Path(*pathsegments)we need a list, if we would provide just a string, each letter would be a single segment.For those wondering why
filepathis required here:If we would supply value directly to
a.bthe instantiation is skipped (so it's stillstr, the same case as in the question)It might be skipped and
_args_might be used directly but it is not verbose for end-user (python ++a.b._args_=/a/new/path)