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

[FEAT] Improved handling of configuration values #62

Open
1 task done
jchonig opened this issue Oct 24, 2024 · 1 comment
Open
1 task done

[FEAT] Improved handling of configuration values #62

jchonig opened this issue Oct 24, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jchonig
Copy link

jchonig commented Oct 24, 2024

Is this a new feature request?

  • I have searched the existing issues

Wanted change

Add the ability to specify configuration variables w/o hand editting configuration.py.

This may relate to #59

Reason for change

I manage my containers with CM (puppet) and strongly dislike having to hand edit files in a container. I haven't found any tools that allow an easy way to update python configuration files.

Proposed code change

I tried to specify another configuration script (config.py) which reads configuration.py and also reads a yaml file. But could not get that to work properly. I'm probably missing some subtle issue with python importlib.

What I ended up doing that worked was appending the following code to the end of configuration.py and then writing my configuration into a yaml file called config.yaml. This allows anything set in configuration.py to be used, but values in config.yaml override it.

This could be expanded to write one YAML file for data passed in from the environment and another for additional configuration written by the user.

import yaml
import sys

print("Reading /config/config.yaml")
with open("/config/config.yaml", "r") as fp:
    config = yaml.safe_load(fp)

for key, value in config.items():
    setattr(sys.modules[__name__], key, value)

Thoughts?

@jchonig jchonig added the enhancement New feature or request label Oct 24, 2024
Copy link

Thanks for opening your first issue here! Be sure to follow the relevant issue templates, or risk having this issue marked as invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Issues
Development

No branches or pull requests

1 participant