-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for pathlib.Path type #97
Comments
I am considering switching from
The direct and convenient translation to
However, I am getting the following error:
Would you consider allowing pathlib.Path et al types for |
Hi @soupault. Thanks for your patience. |
Out of curiosity, what would be easier: adding |
Gut feeling is that adding support for custom types would be harder. |
Clearing the milestone, 2.1 is already too much. we can revisit later. |
Taking advantage of It's not really a true solution, but it can provide a convenient workaround.
You can test it out yourself with Also, P.S. I'm new to this library. I wanted to say thank you for the very clean API and easily understandable docs! |
Just updating with a much simplified code-block that captures the essential functionality.
|
Any updates on this? |
Currently you can use the following resolver-based workaround: from dataclasses import dataclass
from pathlib import Path
from typing import Any
from omegaconf import OmegaConf
@dataclass
class Config:
model: str = "/path/to/model.pkl"
model_path: Any = "${path:${.model}}"
OmegaConf.register_new_resolver("path", Path, replace=True)
cfg = OmegaConf.structured(Config)
assert isinstance(cfg.model_path, Path) Edit: note that you could use a single variable, but it would be less convenient to override on the command line |
@odelalleau you might be interested in mit-ll-responsible-ai/hydra-zen#257 -- we are looking to let users add support for custom types in Hydra, but via hydra-zen. |
Thanks @rsokl, hydra-zen seems interesting! |
Once stronger typing is implemented in the library, consider adding support for the
pathlib.Path
type.Motivation: paths are often found in configs and
pathlib.Path
usage is spreading across the Python ecosystem.The text was updated successfully, but these errors were encountered: