|
5 | 5 | import os |
6 | 6 | import sys |
7 | 7 | from pathlib import Path |
8 | | -from typing import TYPE_CHECKING |
| 8 | +from typing import TYPE_CHECKING, Any |
9 | 9 |
|
10 | 10 | from duty import duty |
11 | 11 | from duty.callables import black, blacken_docs, coverage, lazy, mkdocs, mypy, pytest, ruff, safety |
@@ -35,7 +35,29 @@ def pyprefix(title: str) -> str: # noqa: D103 |
35 | 35 | return title |
36 | 36 |
|
37 | 37 |
|
| 38 | +def merge(d1: Any, d2: Any) -> Any: # noqa: D103 |
| 39 | + basic_types = (int, float, str, bool, complex) |
| 40 | + if isinstance(d1, dict) and isinstance(d2, dict): |
| 41 | + for key, value in d2.items(): |
| 42 | + if key in d1: |
| 43 | + if isinstance(d1[key], basic_types): |
| 44 | + d1[key] = value |
| 45 | + else: |
| 46 | + d1[key] = merge(d1[key], value) |
| 47 | + else: |
| 48 | + d1[key] = value |
| 49 | + return d1 |
| 50 | + if isinstance(d1, list) and isinstance(d2, list): |
| 51 | + return d1 + d2 |
| 52 | + return d2 |
| 53 | + |
| 54 | + |
38 | 55 | def mkdocs_config() -> str: # noqa: D103 |
| 56 | + from mkdocs import utils |
| 57 | + |
| 58 | + # patch YAML loader to merge arrays |
| 59 | + utils.merge = merge |
| 60 | + |
39 | 61 | if "+insiders" in pkgversion("mkdocs-material"): |
40 | 62 | return "mkdocs.insiders.yml" |
41 | 63 | return "mkdocs.yml" |
@@ -83,6 +105,7 @@ def check_quality(ctx: Context) -> None: |
83 | 105 | Parameters: |
84 | 106 | ctx: The context instance (passed automatically). |
85 | 107 | """ |
| 108 | + os.environ["MYPYPATH"] = "src" |
86 | 109 | ctx.run( |
87 | 110 | ruff.check(*PY_SRC_LIST, config="config/ruff.toml"), |
88 | 111 | title=pyprefix("Checking code quality"), |
@@ -125,7 +148,6 @@ def check_types(ctx: Context) -> None: |
125 | 148 | Parameters: |
126 | 149 | ctx: The context instance (passed automatically). |
127 | 150 | """ |
128 | | - os.environ["MYPYPATH"] = "src" |
129 | 151 | ctx.run( |
130 | 152 | mypy.run(*PY_SRC_LIST, config_file="config/mypy.ini"), |
131 | 153 | title=pyprefix("Type-checking"), |
|
0 commit comments