Find all components whose dict ID matches a wildcard pattern. Non-wildcard keys must match exactly. Wildcard keys are ignored.
(pattern: dict)
| 171 | |
| 172 | |
| 173 | def find_matching_components(pattern: dict) -> list[Component]: |
| 174 | """Find all components whose dict ID matches a wildcard pattern. |
| 175 | |
| 176 | Non-wildcard keys must match exactly. Wildcard keys are ignored. |
| 177 | """ |
| 178 | non_wildcard_keys = { |
| 179 | k: v |
| 180 | for k, v in pattern.items() |
| 181 | if not (isinstance(v, list) and len(v) == 1 and v[0] in _WILDCARD_VALUES) |
| 182 | } |
| 183 | matches = [] |
| 184 | for comp, _ in traverse(): |
| 185 | comp_id = getattr(comp, "id", None) |
| 186 | if not isinstance(comp_id, dict): |
| 187 | continue |
| 188 | if all(comp_id.get(k) == v for k, v in non_wildcard_keys.items()): |
| 189 | matches.append(comp) |
| 190 | return matches |
| 191 | |
| 192 | |
| 193 | def extract_text(component: Component) -> str: |
no test coverage detected
searching dependent graphs…