Templates do not resolve recursively
- Dominant language
- Python
- Stars
- 424
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to create a template for my config file using confuse but have trouble understanding how this works. Unfortunately I can't find much about it in the docs.
I am have the following sample in `MyApp.py`:
```
import confuse
template = {"api": {"token_file": confuse.templates.Filename()}}
config = confuse.Configuration("MyApp")
config.get(template)
print(config["api"]["token_file"])
print(config["api"].get(template["api"])["token_file"])
print(config["api"]["token_file"].as_filename())
```
If I then put the following in `~/.config/MyApp/config.yaml`
```
api:
token_file: ./my_token.pickle
```
This is the output of MyApp.py:
```
./my_token.pickle
/home/me/.config/MyApp/my_token.pickle
/home/me/.config/MyApp/my_token.pickle
```
As you can see the first print statement doesn't actually resolve the filename, even though the template specifies it as a filename, but the second and third version do resolve it correctly. Since I want my application to be ignorant wrt confuse, I just want it to use `config['api']['token_file']` without having to worry about the templates. So is there a way to have confuse recursively resolve the template types when I call `config.get(template)`, so the first print statement also resolves as I was expecting?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the example in MyApp.py and the ~/.config/MyApp/config.yaml configuration shown in the issue, then run the sample to compare config.get(template) with the nested lookups. Trace how confuse applies template types during config.get; done means config['api']['token_file'] resolves the relative filename without requiring callers to apply templates again.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100