Create an Options object that incorporates per-module options. NOTE: Once this method is called all Options objects should be considered read-only, else the caching might be incorrect.
(self, module: str)
| 591 | self._unused_configs.update(structured_keys) |
| 592 | |
| 593 | def clone_for_module(self, module: str) -> Options: |
| 594 | """Create an Options object that incorporates per-module options. |
| 595 | |
| 596 | NOTE: Once this method is called all Options objects should be |
| 597 | considered read-only, else the caching might be incorrect. |
| 598 | """ |
| 599 | if self._per_module_cache is None: |
| 600 | self.build_per_module_cache() |
| 601 | assert self._per_module_cache is not None |
| 602 | |
| 603 | # If the module just directly has a config entry, use it. |
| 604 | if module in self._per_module_cache: |
| 605 | self._unused_configs.discard(module) |
| 606 | return self._per_module_cache[module] |
| 607 | |
| 608 | # If not, search for glob paths at all the parents. So if we are looking for |
| 609 | # options for foo.bar.baz, we search foo.bar.baz.*, foo.bar.*, foo.*, |
| 610 | # in that order, looking for an entry. |
| 611 | # This is technically quadratic in the length of the path, but module paths |
| 612 | # don't actually get all that long. |
| 613 | options = self |
| 614 | path = module.split(".") |
| 615 | for i in range(len(path), 0, -1): |
| 616 | key = ".".join(path[:i] + ["*"]) |
| 617 | if key in self._per_module_cache: |
| 618 | self._unused_configs.discard(key) |
| 619 | options = self._per_module_cache[key] |
| 620 | break |
| 621 | |
| 622 | # OK and *now* we need to look for unstructured glob matches. |
| 623 | # We only do this for concrete modules, not structured wildcards. |
| 624 | if not module.endswith(".*"): |
| 625 | for key, pattern in self._glob_options: |
| 626 | if pattern.match(module): |
| 627 | self._unused_configs.discard(key) |
| 628 | options = options.apply_changes(self.per_module_options[key]) |
| 629 | |
| 630 | # We could update the cache to directly point to modules once |
| 631 | # they have been looked up, but in testing this made things |
| 632 | # slower and not faster, so we don't bother. |
| 633 | |
| 634 | return options |
| 635 | |
| 636 | def get_unused_configs(self) -> set[str]: |
| 637 | return self._unused_configs.copy() |
no test coverage detected