Slim python library to manage yaml configuration files stored in project specific subdirectories of ~/.config/. Command line creation and editing functions beginning to be tinkered with, core usecase presently is programatic access of standardized config.yaml files with very little fuss.
- For MAC/Linux systems (though should be straightforward to port to Windows).
- Python >= 3.10 & pip
- You must have a
~/.configdirectory. Under this directory, eachproject_namemust have its own directory. Within eachproject_namedirectory, there must be a yaml file for eachproject_environment. In the following example, the project,myproj, has twoproject_environmentyaml filesprodanddevelop. Theproject_environmentallows configuration of multiple working environments for each project. The default asusmend project_environment isprod, but any name may be specified.
$HOME/.config/myproj/
├── myproj_develop.yaml
└── myproj_prod.yamlFrom the cloned yaml_config_day repo top directory.
mkdir -p ~/.config
cp -r etc/example_yaml/myproj ~/.config/myprojpip install yaml_config_day # should install the most recent tagged release!! Check to confirm!cd $yaml_config_day cloned repo
pip install .Using mamba (there is very little to this module, a venv may be overkill... but so it goes).
mamba env create -n DYAML -f DYAML.yamlconda activate DYAML- For each project you would like to set up distinct config for, create a new folder named for each project under
~/.config/named for the project. Within this directory, you can create a config file for each develop environment used by this project, files named as follows:
project='myproj';
devenv='dev'
mkdir -p ~/.config/$project
touch ~/.config/$project/$project_$devenv.yaml- Enter your config key-value pairs via a text editor in the file
~/.config/myproj_dev.yaml. ie:
---
access_key: aaa
secret_access_key: bbbb
username: myusername- Use in an python shell to fetch the
~/.config/myproj/myproj_dev.yamlconfig data as adict.
import yaml_config_day.config_manager as YCM
# READ CONFIG YAML
yconfig = YCM.ProjectConfigManager('myproj', 'dev')
# RETURN DICT of YAML CONFIG
yconfig.get_config()
# Out[3]: {'access_key': 'aaa', 'secret_access_key': 'bbbb', 'username': 'jmmmem'}
# CLEAR CONFIG
yconfig.clear_config()
yconfig.get_config()
# Out[5]: {}
# WRITE NEW YAML (will over-write all values presently, so must specify all)
yconfig.set_config(username='userNAME',access_key='AccessKey',secret_access_key='SecretAccessKey')
# GET NEW YAML AS DICT
yconfig.get_config()
Out[7]: {'access_key': 'AccessKey', 'secret_access_key': 'SecretAccessKey', 'username': 'userNAME'}And after re-writing the default config.yaml, the ~/.config/myproj/myproj_develop.yaml file now contains:
cat ~/.config/myproj/myproj_develop.yamlaccess_key: AccessKey
secret_access_key: SecretAccessKey
username: userNAME
- Currently, very simple project+environment yaml files are managed. Move to something that looks more like myproj_test.yaml.
- Update setup.py
python setup.py sdist bdist_wheeltwine upload dist/*