| Total Complexity | 8 | 
| Total Lines | 24 | 
| Duplicated Lines | 0 % | 
| Coverage | 94.44% | 
| Changes | 4 | ||
| Bugs | 0 | Features | 0 | 
| 1 | """Configuration module.""" | ||
| 10 | 1 | class Config: | |
| 11 | 1 |     __slots__ = ('debug',) | |
| 12 | 1 | def __init__(self, data=None): | |
| 13 | 1 | if not hasattr(self, 'config_path_variable') or \ | |
| 14 | not hasattr(self, 'parse_config'): | ||
| 15 | 1 |             raise NotImplementedError('Config class does not implement all ' | |
| 16 | 'required attributes.') | ||
| 17 | 1 | self.debug = True | |
| 18 | 1 | if not data: | |
| 19 | 1 | try: | |
| 20 | 1 | with open(self.get_config_path()) as fd: | |
| 21 | 1 | data = json.load(fd) | |
| 22 | 1 | except ValueError as exc: | |
| 23 | raise InvalidConfig(*exc.args) | ||
| 24 | 1 | self.parse_config(data) | |
| 25 | |||
| 26 | 1 | @classmethod | |
| 27 | def get_config_path(cls): | ||
| 28 | 1 | path = os.environ.get(cls.config_path_variable, '') | |
| 29 | 1 | if not path: | |
| 30 | 1 |             raise InvalidConfig('Could not find config file, please set ' | |
| 31 | 'environment variable $%s.' % | ||
| 32 | cls.config_path_variable) | ||
| 33 | 1 | return path | |
| 34 | |||
| 35 |