Introduction
In the
Subclass Configuration Properties
The developer starts the process by subclassing Configuration Properties as follows.
BASE_FILE_NAME: str = 'config.ini'
MODULE_NAME: str = 'version2properties'
class ConfigurationPropertiesVersion2(ConfigurationProperties, metaclass=SingletonV3):
def __init__(self):
self.logger: Logger = getLogger(LOGGER_NAME)
super().__init__(baseFileName=BASE_FILE_NAME, moduleName=MODULE_NAME, sections=CONFIGURATION_SECTIONS)
self._configParser.optionxform = self._toStr # type: ignore
self._loadConfiguration()
The call to super creates a fully qualified path to the configuration file. The code follows a subset of . See the support class
The result of the implementation left me satisfied as a consumer of the code. I was able to get and set typed properties. It did not remove as much code as I had initially hoped for. However, it did provide me with reusable code. However, it did prompt me to write a Live Template in PyCharm to get me over generating individual properties.
Advantages
- Easy type safe access to application properties
- Reusable parent class for different implementations
- Data structure driven code to add new sections and configuration keys
Disadvantages
- Still lots of boiler plate code
- I have feeling that using decorators was a misuse of them
My next post I implemented what I call dynamic properties. It entirely removed all the boiler plate code and still maintained the aforementioned advantages.
SOCIAL SHARE CARD GENERATOR