config.py 906 B

12345678910111213141516171819202122232425262728
  1. # mypy: allow-untyped-defs
  2. import logging
  3. import sys
  4. from types import ModuleType
  5. from typing import Set
  6. # log level (levels print what it says + all levels listed below it)
  7. # DEBUG print full traces <-- lowest level + print tracing of every instruction
  8. # INFO print compiler functions + distributed graphs
  9. # WARN print warnings
  10. # ERROR print exceptions
  11. log_level: int = logging.DEBUG
  12. # Verbose will print full stack traces on warnings and errors
  13. verbose = False
  14. # the name of a file to write the logs to
  15. log_file_name: None = None
  16. class _AccessLimitingConfig(ModuleType):
  17. def __setattr__(self, name, value) -> None:
  18. if name not in _allowed_config_names:
  19. raise AttributeError(f"{__name__}.{name} does not exist")
  20. return object.__setattr__(self, name, value)
  21. _allowed_config_names: Set[str] = {*globals().keys()}
  22. sys.modules[__name__].__class__ = _AccessLimitingConfig