|
6 | 6 |
|
7 | 7 | # pylint: disable=invalid-name |
8 | 8 | import importlib.resources |
| 9 | +import json |
| 10 | +import numbers |
| 11 | +import os |
| 12 | +import re |
9 | 13 | from decimal import Decimal |
10 | | -from typing import Iterable, List, Union, Callable, Any, Dict, Set, NamedTuple, Tuple, Optional |
11 | | -from warnings import warn |
12 | 14 | from enum import Enum |
13 | 15 | from importlib import resources |
| 16 | +from functools import lru_cache, reduce |
| 17 | +from typing import (Any, Callable, Dict, Iterable, List, NamedTuple, Optional, |
| 18 | + Set, Tuple, Union) |
| 19 | + |
| 20 | +from hammer.logging import HammerVLSILogging, HammerVLSILoggingContext |
| 21 | +from hammer.utils import add_dicts, deepdict, topological_sort |
14 | 22 |
|
15 | | -from hammer.utils import deepdict, add_dicts, topological_sort |
16 | 23 | from .yaml2json import load_yaml # grumble grumble |
17 | 24 |
|
18 | | -from functools import reduce, lru_cache |
19 | | -import json |
20 | | -import numbers |
21 | | -import os |
22 | | -import re |
23 | 25 |
|
24 | 26 | # A helper class that writes Decimals as strings |
25 | 27 | # TODO(ucb-bar/hammer#378) get rid of this and serialize units |
@@ -693,6 +695,8 @@ def __init__(self) -> None: |
693 | 695 |
|
694 | 696 | self.defaults = {} # type: dict |
695 | 697 |
|
| 698 | + self.logger = HammerVLSILogging().context() # type: HammerVLSILoggingContext |
| 699 | + |
696 | 700 | @property |
697 | 701 | def runtime(self) -> List[dict]: |
698 | 702 | return [self._runtime] |
@@ -754,7 +758,7 @@ def get_setting(self, key: str, nullvalue: Any = None, check_type: bool = True) |
754 | 758 | if key not in self.get_config(): |
755 | 759 | raise KeyError("Key " + key + " is missing") |
756 | 760 | if key not in self.defaults: |
757 | | - warn(f"Key {key} does not have a default implementation") |
| 761 | + self.logger.warning(f"Key {key} does not have a default implementation") |
758 | 762 | if check_type: |
759 | 763 | self.check_setting(key) |
760 | 764 | value = self.get_config()[key] |
@@ -782,7 +786,7 @@ def get_setting_suffix(self, key: str, suffix: str, nullvalue: Any = None, check |
782 | 786 | raise KeyError(f"Both base key: {default} and overriden key: {override} are missing.") |
783 | 787 |
|
784 | 788 | if default not in self.defaults: |
785 | | - warn(f"Base key: {default} does not have a default implementation") |
| 789 | + self.logger.warning(f"Base key: {default} does not have a default implementation") |
786 | 790 | if check_type: |
787 | 791 | self.check_setting(default) |
788 | 792 | return nullvalue if value is None else value |
@@ -849,7 +853,7 @@ def check_setting(self, key: str, cfg: Optional[dict] = None) -> bool: |
849 | 853 | if cfg is None: |
850 | 854 | cfg = self.get_config() |
851 | 855 | if key not in self.get_config_types(): |
852 | | - warn(f"Key {key} is not associated with a type") |
| 856 | + self.logger.warning(f"Key {key} is not associated with a type") |
853 | 857 | return True |
854 | 858 | try: |
855 | 859 | exp_value_type = parse_setting_type(self.get_config_types()[key]) |
@@ -976,7 +980,7 @@ def update_types(self, config_types: List[dict], check_type: bool = True) -> Non |
976 | 980 | if check_type: |
977 | 981 | for k, v in loaded_cfg.items(): |
978 | 982 | if not self.has_setting(k): |
979 | | - warn(f"Key {k} has a type {v} is not yet implemented") |
| 983 | + self.logger.warning(f"Key {k} has a type {v} is not yet implemented") |
980 | 984 | elif k != "_config_path": |
981 | 985 | self.check_setting(k) |
982 | 986 |
|
|
0 commit comments