palazzem / econnect-python

API adapter used to control programmatically an Elmo alarm system
BSD 3-Clause "New" or "Revised" License
8 stars 5 forks source link

[config] add configuration system to define application settings #19

Closed palazzem closed 5 years ago

palazzem commented 5 years ago

Overview

Closes #17

Adds a conf module to define application settings. Each setting is defined with an Option class that includes built-in validators and is extendable to add more. Option initialization exposes the following kwargs:

Example

from elmo.conf.config import BaseConfig

class Settings(BaseConfig):
    url = Option(default="http://example.com", allow_null=False)
    home = Option()
    dry_run = Option(validators=[is_boolean])

settings = Settings()
settings.is_valid()  # executes all options validators
palazzem commented 5 years ago

This PR includes application settings via elmo.settings.Settings class. Application configs are available in the following module:

from elmo.conf import settings

settings.base_url = "https://example.com"