Best Practices
#
Config StructurePrograms with simple configuration options most likely only need a single config-file, or not even that if the config is defined in the program's main file. As the configurations become more complex, it's better to set up a system to organize them.
One good approach is to create a configs directory next to the program's main Python files and put all the config-files in that directory.
#
Git#
User ConfigsDifferent developers often want to configure their common projects slightly differently from one another. Adding those config changes to Git isn't appreciated by the other developers and can potentially cause merge conflicts.
A winning approach adopted by many systems is to apply user configs that override certain keys in the default config. If the user configs are untracked by Git there is no risk of unwanted config changes spilling over to others.
This can easily be implemented in Anyfig.
- Create one or several dedicated user config files.
- Wrap the main config classes inside the userconfigs.py
- Import the user config in the main program.
- Add the changes to Git and commit. Tell Git that further changes to the user config files shouldn't be tracked with the command
git update-index --skip-worktree configs/userconfigs.py
. The developers can now put their custom overrides in the user config files.
Easily Run the Main Config
Seamlessly switch between user config and main config by returning before overriding user config values based on a flag.
#
Sensitive InformationSensitive information such as passwords should most likely not be put into files tracked by git for security reasons. This creates a dilemma if one wants to track Anyfig config-class files but not the sensitive information within.
A workaround would be to put the sensitive information in a file, have git ignore the file and point to the file from Anyfig.
It's also possible to create a function to read the password from the file directly in an Anyfig config-class. If you prefer this approach, be careful for if you save the config, the password will be saved as well.