|
23 | 23 | import os |
24 | 24 | import string |
25 | 25 | import yaml |
| 26 | +from dataclasses import dataclass |
26 | 27 | from collections import defaultdict |
| 28 | +from collections.abc import Mapping |
27 | 29 | from forest.export import export |
28 | 30 |
|
29 | 31 |
|
30 | 32 | __all__ = [] |
31 | 33 |
|
32 | 34 |
|
| 35 | +@dataclass |
| 36 | +class PluginSpec: |
| 37 | + """Data representation of plugin""" |
| 38 | + entry_point: str |
| 39 | + |
| 40 | + |
| 41 | +class Plugins(Mapping): |
| 42 | + """Specialist mapping between allowed keys and specs""" |
| 43 | + def __init__(self, data): |
| 44 | + allowed = ("feature",) |
| 45 | + self.data = {} |
| 46 | + for key, value in data.items(): |
| 47 | + if key in allowed: |
| 48 | + self.data[key] = PluginSpec(**value) |
| 49 | + else: |
| 50 | + msg = f"{key} not in {allowed}" |
| 51 | + raise Exception(msg) |
| 52 | + |
| 53 | + def __getitem__(self, *args, **kwargs): |
| 54 | + return self.data.__getitem__(*args, **kwargs) |
| 55 | + |
| 56 | + def __len__(self, *args, **kwargs): |
| 57 | + return self.data.__len__(*args, **kwargs) |
| 58 | + |
| 59 | + def __iter__(self, *args, **kwargs): |
| 60 | + return self.data.__iter__(*args, **kwargs) |
| 61 | + |
| 62 | + |
33 | 63 | class Viewport: |
34 | 64 | def __init__(self, lon_range, lat_range): |
35 | 65 | self.lon_range = lon_range |
@@ -68,6 +98,7 @@ class Config(object): |
68 | 98 | """ |
69 | 99 | def __init__(self, data): |
70 | 100 | self.data = data |
| 101 | + self.plugins = Plugins(self.data.get("plugins", {})) |
71 | 102 |
|
72 | 103 | def __repr__(self): |
73 | 104 | return "{}({})".format( |
|
0 commit comments