Skip to content
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 to OmegaConf.load() and OmegaConf.save() #158

Merged
merged 4 commits into from
Feb 28, 2020
Merged

Add support for pathlib.Path to OmegaConf.load() and OmegaConf.save() #158

merged 4 commits into from
Feb 28, 2020

Conversation

alexvicegrab
Copy link
Contributor

@alexvicegrab alexvicegrab commented Feb 28, 2020

Addresses issue #159

Test for pathlib.Path added.

Copy link
Owner

@omry omry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
A few requests:

  1. Create an issue describing this (the one you linked to is talking about adding pathlib.Path as a supported type inside the config objects, not to the load and save API).
  2. Add a news fragment file (in news) referencing your new issue. (see this for context, OmegaConf uses the same pattern)

Note that your change will be released with OmegaConf 2.0 which is coming soon.

@@ -37,6 +38,20 @@ def save_load_from_filename(conf: Container, resolve: bool, expected: Any) -> No
os.unlink(fp.name)


def save_load_from_pathlib_path(conf: Container, resolve: bool, expected: Any) -> None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of duplicating the other function please parametrize it with pytest.mark.parametrize()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @omry.

I was able to implement the other suggestions, and while I would like to keep things DRY, I'm not quite sure how to parametrise using the original save_load_from_filename. Could you please point me in the right direction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made an implementation. Hopefully this is reasonably elegant :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good, and trickier than usual because you can't construct the object outside due to the temp file.
good job :).

@@ -183,7 +184,7 @@ def create( # noqa F811
def load(file_: Union[str, IO[bytes]]) -> Union[DictConfig, ListConfig]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the typing information on save and load to reflect this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@omry omry merged commit bd74455 into omry:master Feb 28, 2020
@omry
Copy link
Owner

omry commented Feb 28, 2020

Thanks for the fix!

@omry
Copy link
Owner

omry commented Feb 28, 2020

whoops, failed lint.
unclear to me why CI didn't run for your PR.

For next time:
you can trigger the CI logic locally by running nox.

@alexvicegrab
Copy link
Contributor Author

Oops, strange. I ran only pytest. Will run nox also next time.

Thanks for the quick responses and help!

@alexvicegrab alexvicegrab deleted the pathlib_support branch February 29, 2020 19:05
@omry
Copy link
Owner

omry commented Feb 29, 2020

cheers and thanks for the PR!

@omry omry changed the title Add support for pathlib.Path Add support for pathlib.Path to OmegaConf.load() and OmegaConf.save() Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants