-
Notifications
You must be signed in to change notification settings - Fork 51
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
adding config files as a Configuration argument #80
base: main
Are you sure you want to change the base?
Conversation
Awesome; this seems like it's on the right track to me. My gut reaction is that changing the time at which we do the search is probably the right thing to do. But what about one small change: the directory creation could still happen in Without this, unless I'm mistaken, |
True! that's a good point that I hadn't considered. It shouldn't be a difficult thing to do tho. On a related note, I'm having a little trouble understanding the lazy config. What does splicing sources out of I was thinking that you could extend ConfigSource to encapsulate the data loading so it will load only before you try to access the dict contents (i.e. but basically to demonstrate usage: # equivalent
c = ConfigSource.of('asdf.yml')
c = YamlSource('asdf.yml')
# lazy loading
c = ConfigSource.of('asdfa.yml')
print('unloaded', c)
print('a =', c['a'])
print('loaded', c) outputs
Sorry I feel weird coming in and proposing a bunch of changes so please feel free to push back if you don't like an idea. 😝 |
Good question—this is a little subtle. The idea is to let applications create the in-memory part of their configuration without touching the filesystem, but to have the same effect as loading everything up front. So if you were to do something like this with the normal, eager config = Config('myapp', __name__)
config.set(A)
config.add(B) Then the resulting "stack" of configuration bits would look like:
We want
I like this idea! It's nice in the way that we get to keep track of "loadedness" state locally for a given source rather than globally for the entire configuration. That seems cool! I can't really think. of any downsides with respect to the way that the current (It still might be nice to have an eager version, I guess?? At least transitionally? Maybe it would be more predictable in some circumstances?) Anyway, if you're interested, maybe we should work on that in a separate PR? We could get that right, and then maybe the implementation of this bit could be a little simpler because we don't have to worry about laziness anymore. |
Great! I'll submit a PR! And thanks for the explanation, that makes sense. I was having some trouble with load order so I think that'll be the one thing we need to figure out in this next PR.
|
Ok so I figured I would pump this out tonight so that I can continue on with other things tomorrow :)
Summary of things:
Configuration('myapp', source='~/mypkg')
Configuration('myapp', source='~/mypkg/settings.yml')
Configuration('myapp', source=['~/mypkg', '/etc/mypkg/settings.yml'])
MYAPPDIR=~/mypkg/
,MYAPPDIR=~/mypkg/app.yml
config.set_file('~/mypkg', default=True) # ~/mypkg/config_default.yaml
config_filename
anddefault_filename
as arguments as well (cuz why not?)One bigger change - system files are searched for in
__init__
instead of every timeconfig_dir
is called.config_dir()
will now iterate over the loaded (or unloaded) sources and take the first config that has a filename as the config directory. This means the environment variable must be set before instantiating (which is how one might expect anyways)I'm open to more discussion about this, but to me it feels a bit unstable to have the detected system config potentially change mid program. This way, the only time
config_dir
may change is if you call.set()
.