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

Refactor YAML loading into YamlSource class #106

Merged
merged 4 commits into from
Aug 19, 2020
Merged

Refactor YAML loading into YamlSource class #106

merged 4 commits into from
Aug 19, 2020

Conversation

sampsyo
Copy link
Member

@sampsyo sampsyo commented Jul 25, 2020

This is the first step of #96 and @beasteers's approach to lazy source loading. (As a quick recap, that idea is to refactor laziness into the source instead of the configuration object, which is both cleaner and enables mixing-and-matching of lazy and eager sources within the same config.)

This step just consists of an innocuous but nice refactoring to use a YamlSource class to encapsulate the vagaries of loading configuration data from a file. The next step would be to introduce a lazy option here: either a lazy parameter to the YamlSource constructor or a separate LazyYamlSource class (or similar).

Simple refactoring that just simplifies some calls to
`yaml_util.load_yaml` at this point.
This seems to be just fine without it (these are the only names exported
here).
Removes the decision from the YamlSource call sites.
if optional and not os.path.isfile(filename):
value = {}
else:
value = yaml_util.load_yaml(filename, loader=loader) or {}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be in its own load method so it can be called later.

@beasteers
Copy link
Contributor

Sorry I'm not sure how I missed this. It looks good, but it's very bare bones so I'm just assuming that the plan is to add more in future PRs.

So I think it LGTM and we should move on to moving laziness into sources!

@sampsyo sampsyo merged commit 018fcb5 into master Aug 19, 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