Commit 4484c2b
authored
This PR adds a new argument to `load_config()` to allow passing a
`base_schema` to be used when loading the configuration. This is
necessary to be able to use custom fields in the schema, like the ones
provided by `frequenz.quantities`.
It also drops support for using `marshmallow_dataclas.dataclass`
directly. `marshmallow_dataclass.dataclass` is intended to be used only
when using `my_dataclass.Schema` to get the schema. But using this is
not very convenient when using type hints as they are not well-supported
by `marshmallow`, as the `load()` function can't have hints.
This is actually why `load_config()` exists in the first place, so we
are using `class_schema()` instead, so we don't really need that our
types are decorated with `marshmallow_dataclass`, we can use the
built-in `dataclass` instead, we just need to add the appropriate
metadata if we want more complex validation.
Using `class_shema()` is also necessary to be able to pass a
`base_schema`, which we'll need when we want to use schemas with custom
fields, like the ones provided by `frequenz.quantities`.
Finally, it improves `load_config` documentation to make it more
explicit that this is just a wrapper to external libraries, so users
should read their documentation in full and which functions are used
exactly.
File tree
3 files changed
+65
-35
lines changed- src/frequenz/sdk/config
- tests/config
3 files changed
+65
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
12 | 28 | | |
13 | 29 | | |
14 | 30 | | |
15 | 31 | | |
16 | | - | |
| 32 | + | |
17 | 33 | | |
18 | 34 | | |
| 35 | + | |
19 | 36 | | |
20 | | - | |
| 37 | + | |
21 | 38 | | |
22 | 39 | | |
23 | 40 | | |
24 | 41 | | |
25 | | - | |
| 42 | + | |
| 43 | + | |
26 | 44 | | |
27 | | - | |
28 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
29 | 48 | | |
30 | 49 | | |
31 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
32 | 58 | | |
33 | 59 | | |
34 | 60 | | |
35 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
36 | 65 | | |
37 | 66 | | |
38 | 67 | | |
39 | 68 | | |
40 | 69 | | |
41 | 70 | | |
42 | | - | |
| 71 | + | |
43 | 72 | | |
44 | 73 | | |
45 | | - | |
| 74 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | 20 | | |
30 | 21 | | |
31 | 22 | | |
| |||
37 | 28 | | |
38 | 29 | | |
39 | 30 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | 31 | | |
52 | 32 | | |
53 | | - | |
| 33 | + | |
54 | 34 | | |
55 | 35 | | |
56 | 36 | | |
57 | 37 | | |
58 | 38 | | |
59 | 39 | | |
60 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
0 commit comments