Browse Source

chg: Add a settings singleton object

So that settings takes values from defaults and they can be changed at
run time, for example, when running tests.
gns
juga 1 year ago
parent
commit
7aadfa5da1
2 changed files with 20 additions and 0 deletions
  1. +2
    -0
      mixnet/__init__.py
  2. +18
    -0
      mixnet/settings.py

+ 2
- 0
mixnet/__init__.py View File

@ -1,5 +1,7 @@
from pkg_resources import DistributionNotFound, get_distribution
from .settings import settings # noqa F401 imported but unused
try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:


+ 18
- 0
mixnet/settings.py View File

@ -0,0 +1,18 @@
"""Create settings singleton.
That can be updated at run time.
"""
from . import defaults
class Settings:
def __init__(self) -> None:
"""Set attributes from the default constants."""
for default in dir(defaults):
if default.isupper():
setattr(self, default, getattr(defaults, default))
# Create the singleton settings object
settings = Settings()

Loading…
Cancel
Save