tracdap-runtime 0.8.0b1__py3-none-any.whl → 0.8.0b3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. tracdap/rt/_impl/core/__init__.py +14 -0
  2. tracdap/rt/_impl/{config_parser.py → core/config_parser.py} +14 -7
  3. tracdap/rt/_impl/{data.py → core/data.py} +3 -3
  4. tracdap/rt/_impl/core/logging.py +195 -0
  5. tracdap/rt/_impl/{models.py → core/models.py} +7 -6
  6. tracdap/rt/_impl/{repos.py → core/repos.py} +5 -3
  7. tracdap/rt/_impl/{schemas.py → core/schemas.py} +5 -5
  8. tracdap/rt/_impl/{shim.py → core/shim.py} +5 -4
  9. tracdap/rt/_impl/{storage.py → core/storage.py} +7 -6
  10. tracdap/rt/_impl/{util.py → core/util.py} +0 -110
  11. tracdap/rt/_impl/{validation.py → core/validation.py} +4 -3
  12. tracdap/rt/_impl/exec/__init__.py +14 -0
  13. tracdap/rt/{_exec → _impl/exec}/actors.py +12 -14
  14. tracdap/rt/{_exec → _impl/exec}/context.py +30 -14
  15. tracdap/rt/{_exec → _impl/exec}/dev_mode.py +8 -7
  16. tracdap/rt/{_exec → _impl/exec}/engine.py +227 -104
  17. tracdap/rt/{_exec → _impl/exec}/functions.py +36 -57
  18. tracdap/rt/{_exec → _impl/exec}/graph.py +2 -21
  19. tracdap/rt/{_exec → _impl/exec}/graph_builder.py +33 -19
  20. tracdap/rt/{_exec → _impl/grpc}/server.py +7 -6
  21. tracdap/rt/_impl/grpc/tracdap/metadata/job_pb2.py +64 -62
  22. tracdap/rt/_impl/grpc/tracdap/metadata/job_pb2.pyi +16 -2
  23. tracdap/rt/_impl/grpc/tracdap/metadata/object_id_pb2.py +3 -3
  24. tracdap/rt/_impl/grpc/tracdap/metadata/object_id_pb2.pyi +2 -0
  25. tracdap/rt/_impl/grpc/tracdap/metadata/object_pb2.py +4 -4
  26. tracdap/rt/_impl/grpc/tracdap/metadata/object_pb2.pyi +4 -2
  27. tracdap/rt/{_exec → _impl}/runtime.py +13 -12
  28. tracdap/rt/_impl/static_api.py +4 -4
  29. tracdap/rt/_plugins/format_csv.py +1 -1
  30. tracdap/rt/_plugins/storage_sql.py +1 -1
  31. tracdap/rt/_version.py +1 -1
  32. tracdap/rt/config/__init__.py +1 -0
  33. tracdap/rt/config/platform.py +8 -0
  34. tracdap/rt/ext/embed.py +2 -2
  35. tracdap/rt/ext/plugins.py +3 -3
  36. tracdap/rt/launch/launch.py +3 -3
  37. tracdap/rt/metadata/__init__.py +1 -0
  38. tracdap/rt/metadata/job.py +16 -0
  39. tracdap/rt/metadata/object.py +2 -0
  40. tracdap/rt/metadata/object_id.py +2 -0
  41. {tracdap_runtime-0.8.0b1.dist-info → tracdap_runtime-0.8.0b3.dist-info}/METADATA +2 -2
  42. {tracdap_runtime-0.8.0b1.dist-info → tracdap_runtime-0.8.0b3.dist-info}/RECORD +47 -45
  43. {tracdap_runtime-0.8.0b1.dist-info → tracdap_runtime-0.8.0b3.dist-info}/WHEEL +1 -1
  44. tracdap/rt/_exec/__init__.py +0 -0
  45. /tracdap/rt/_impl/{guard_rails.py → core/guard_rails.py} +0 -0
  46. /tracdap/rt/_impl/{type_system.py → core/type_system.py} +0 -0
  47. {tracdap_runtime-0.8.0b1.dist-info → tracdap_runtime-0.8.0b3.dist-info}/LICENSE +0 -0
  48. {tracdap_runtime-0.8.0b1.dist-info → tracdap_runtime-0.8.0b3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,14 @@
1
+ # Licensed to the Fintech Open Source Foundation (FINOS) under one or
2
+ # more contributor license agreements. See the NOTICE file distributed
3
+ # with this work for additional information regarding copyright ownership.
4
+ # FINOS licenses this file to you under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
@@ -12,8 +12,14 @@
12
12
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
-
16
- from __future__ import annotations
15
+ #
16
+ # http://www.apache.org/licenses/LICENSE-2.0
17
+ #
18
+ # Unless required by applicable law or agreed to in writing, software
19
+ # distributed under the License is distributed on an "AS IS" BASIS,
20
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ # See the License for the specific language governing permissions and
22
+ # limitations under the License.
17
23
 
18
24
  import dataclasses as _dc
19
25
  import decimal
@@ -32,7 +38,8 @@ import tracdap.rt.config as _config
32
38
  import tracdap.rt.exceptions as _ex
33
39
  import tracdap.rt.ext.plugins as _plugins
34
40
  import tracdap.rt.ext.config as _config_ext
35
- import tracdap.rt._impl.util as _util
41
+ import tracdap.rt._impl.core.logging as _logging
42
+ import tracdap.rt._impl.core.util as _util
36
43
 
37
44
  import yaml
38
45
  import yaml.parser
@@ -43,7 +50,7 @@ _T = tp.TypeVar('_T')
43
50
  class ConfigManager:
44
51
 
45
52
  @classmethod
46
- def for_root_config(cls, root_config_file: tp.Union[str, pathlib.Path, None]) -> ConfigManager:
53
+ def for_root_config(cls, root_config_file: tp.Union[str, pathlib.Path, None]) -> "ConfigManager":
47
54
 
48
55
  if isinstance(root_config_file, pathlib.Path):
49
56
  root_file_path = cls._resolve_scheme(root_config_file)
@@ -69,7 +76,7 @@ class ConfigManager:
69
76
  return ConfigManager(working_dir_url, None)
70
77
 
71
78
  @classmethod
72
- def for_root_dir(cls, root_config_dir: tp.Union[str, pathlib.Path]) -> ConfigManager:
79
+ def for_root_dir(cls, root_config_dir: tp.Union[str, pathlib.Path]) -> "ConfigManager":
73
80
 
74
81
  if isinstance(root_config_dir, pathlib.Path):
75
82
  root_dir_path = cls._resolve_scheme(root_config_dir)
@@ -103,7 +110,7 @@ class ConfigManager:
103
110
  return raw_url
104
111
 
105
112
  def __init__(self, root_dir_url: _urlp.ParseResult, root_file_url: tp.Optional[_urlp.ParseResult]):
106
- self._log = _util.logger_for_object(self)
113
+ self._log = _logging.logger_for_object(self)
107
114
  self._root_dir_url = root_dir_url
108
115
  self._root_file_url = root_file_url
109
116
 
@@ -294,7 +301,7 @@ class ConfigParser(tp.Generic[_T]):
294
301
  }
295
302
 
296
303
  def __init__(self, config_class: _T.__class__, dev_mode_locations: tp.List[str] = None):
297
- self._log = _util.logger_for_object(self)
304
+ self._log = _logging.logger_for_object(self)
298
305
  self._config_class = config_class
299
306
  self._dev_mode_locations = dev_mode_locations or []
300
307
  self._errors = []
@@ -37,7 +37,7 @@ except ModuleNotFoundError:
37
37
  import tracdap.rt.api.experimental as _api
38
38
  import tracdap.rt.metadata as _meta
39
39
  import tracdap.rt.exceptions as _ex
40
- import tracdap.rt._impl.util as _util
40
+ import tracdap.rt._impl.core.logging as _log
41
41
 
42
42
 
43
43
  @dc.dataclass(frozen=True)
@@ -188,7 +188,7 @@ class DataMapping:
188
188
  :py:class:`TypeMapping <tracdap.rt.impl.type_system.MetadataCodec>`.
189
189
  """
190
190
 
191
- __log = _util.logger_for_namespace(_DataInternal.__module__ + ".DataMapping")
191
+ __log = _log.logger_for_namespace(_DataInternal.__module__ + ".DataMapping")
192
192
 
193
193
  # Matches TRAC_ARROW_TYPE_MAPPING in ArrowSchema, tracdap-lib-data
194
194
 
@@ -715,7 +715,7 @@ class DataConformance:
715
715
  Check and/or apply conformance between datasets and schemas.
716
716
  """
717
717
 
718
- __log = _util.logger_for_namespace(_DataInternal.__module__ + ".DataConformance")
718
+ __log = _log.logger_for_namespace(_DataInternal.__module__ + ".DataConformance")
719
719
 
720
720
  __E_FIELD_MISSING = \
721
721
  "Field [{field_name}] is missing from the data"
@@ -0,0 +1,195 @@
1
+ # Licensed to the Fintech Open Source Foundation (FINOS) under one or
2
+ # more contributor license agreements. See the NOTICE file distributed
3
+ # with this work for additional information regarding copyright ownership.
4
+ # FINOS licenses this file to you under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import io as _io
17
+ import sys as _sys
18
+ import typing as _tp
19
+
20
+ from logging import *
21
+
22
+
23
+ class PlainFormatter(Formatter):
24
+
25
+ FORMAT = f"%(asctime)s [%(threadName)s] %(levelname)s %(name)s" + \
26
+ f" - %(message)s"
27
+
28
+ def __init__(self):
29
+ super().__init__(self.FORMAT)
30
+
31
+
32
+ class ColorFormatter(Formatter):
33
+
34
+ _BLACK, _RED, _GREEN, _YELLOW, _BLUE, _MAGENTA, _CYAN, _WHITE, _DEFAULT_WHITE = range(9)
35
+ _DARK_BASE = 30
36
+ _LIGHT_BASE = 90
37
+
38
+ # DARK_BASE + WHITE = light grey
39
+ # DARK_BASE + DEFAULT_WHITE = regular console white
40
+ # LIGHT_BASE + WHITE = bright white (0xffffff), very bright!
41
+
42
+ def __init__(self, is_bright: bool):
43
+
44
+ super().__init__(self._base_fmt(is_bright))
45
+ self._level_colors = self._make_level_colors(is_bright)
46
+ self._default_color = self._make_default_color(is_bright)
47
+
48
+ def format(self, record):
49
+
50
+ level_name = record.levelname
51
+ level_color = self._level_colors.get(level_name)
52
+
53
+ if level_color:
54
+ record.levelname = level_color
55
+ else:
56
+ record.levelname = self._default_color + level_name
57
+
58
+ return Formatter.format(self, record)
59
+
60
+ def _base_fmt(self, is_bright: bool):
61
+
62
+ if is_bright:
63
+ base_color = self._make_ansi_code(self._DARK_BASE, self._DEFAULT_WHITE, is_bold=False)
64
+ message_color = self._make_ansi_code(self._LIGHT_BASE, self._CYAN, is_bold=False)
65
+ else:
66
+ base_color = self._make_ansi_code(self._DARK_BASE, self._WHITE, is_bold=False)
67
+ message_color = self._make_ansi_code(self._DARK_BASE, self._CYAN, is_bold=False)
68
+
69
+ return f"{base_color}%(asctime)s [%(threadName)s] %(levelname)s{base_color} %(name)s" + \
70
+ f" - {message_color}%(message)s"
71
+
72
+ def _make_level_colors(self, is_bright: bool):
73
+
74
+ base_code = self._LIGHT_BASE if is_bright else self._DARK_BASE
75
+
76
+ green = self._make_ansi_code(base_code, self._GREEN, is_bold=is_bright)
77
+ yellow = self._make_ansi_code(base_code, self._YELLOW, is_bold=is_bright)
78
+ red = self._make_ansi_code(base_code, self._RED, is_bold=is_bright)
79
+
80
+ level_colors = {
81
+ 'CRITICAL': f"{red}CRITICAL",
82
+ 'ERROR': f"{red}ERROR",
83
+ 'WARNING': f"{yellow}WARNING",
84
+ 'INFO': f"{green}INFO"
85
+ }
86
+
87
+ return level_colors
88
+
89
+ def _make_default_color(self, is_bright: bool):
90
+
91
+ base_code = self._LIGHT_BASE if is_bright else self._DARK_BASE
92
+ blue = self._make_ansi_code(base_code, self._BLUE, is_bold=is_bright)
93
+
94
+ return blue
95
+
96
+ @classmethod
97
+ def _make_ansi_code(cls, base_code: int, color_offset: int, is_bold: bool):
98
+ return f"\033[{1 if is_bold else 0};{base_code + color_offset}m"
99
+
100
+
101
+ def configure_logging(enable_debug=False):
102
+
103
+ root_logger = getLogger()
104
+ log_level = DEBUG if enable_debug else INFO
105
+
106
+ if not root_logger.hasHandlers():
107
+
108
+ console_formatter = ColorFormatter(is_bright=True)
109
+ console_handler = StreamHandler(_sys.stdout)
110
+ console_handler.setFormatter(console_formatter)
111
+ console_handler.setLevel(INFO)
112
+ root_logger.addHandler(console_handler)
113
+ root_logger.setLevel(log_level)
114
+
115
+ # Use is_bright=False for logs from the TRAC runtime, so model logs stand out
116
+
117
+ trac_logger = getLogger("tracdap.rt")
118
+
119
+ console_formatter = ColorFormatter(is_bright=False)
120
+ console_handler = StreamHandler(_sys.stdout)
121
+ console_handler.setFormatter(console_formatter)
122
+ console_handler.setLevel(log_level)
123
+ trac_logger.addHandler(console_handler)
124
+ trac_logger.propagate = False
125
+
126
+
127
+ def logger_for_object(obj: object) -> Logger:
128
+ return logger_for_class(obj.__class__)
129
+
130
+
131
+ def logger_for_class(clazz: type) -> Logger:
132
+ qualified_class_name = f"{clazz.__module__}.{clazz.__name__}"
133
+ return getLogger(qualified_class_name)
134
+
135
+
136
+ def logger_for_namespace(namespace: str) -> Logger:
137
+ return getLogger(namespace)
138
+
139
+
140
+ class JobLogger(Logger):
141
+
142
+ def __init__(self, sys_log: Logger, *handlers: Handler):
143
+
144
+ super().__init__(sys_log.name, sys_log.level)
145
+ self._sys_log = sys_log._log
146
+ self._job_log = super()._log
147
+
148
+ for handler in handlers:
149
+ self.addHandler(handler)
150
+
151
+ def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False, stacklevel=1):
152
+
153
+ self._sys_log(level, msg, args, exc_info, extra, stack_info, stacklevel)
154
+ self._job_log(level, msg, args, exc_info, extra, stack_info, stacklevel)
155
+
156
+
157
+ class LogProvider:
158
+
159
+ def logger_for_object(self, obj: object) -> Logger:
160
+ return logger_for_object(obj)
161
+
162
+ def logger_for_class(self, clazz: type) -> Logger:
163
+ return logger_for_class(clazz)
164
+
165
+ def logger_for_namespace(self, namespace: str) -> Logger:
166
+ return logger_for_namespace(namespace)
167
+
168
+
169
+ class JobLogProvider(LogProvider):
170
+
171
+ def __init__(self, *handlers: Handler):
172
+ self.__handlers = handlers
173
+
174
+ def logger_for_object(self, obj: object) -> Logger:
175
+ base_logger = logger_for_object(obj)
176
+ return JobLogger(base_logger, *self.__handlers)
177
+
178
+ def logger_for_class(self, clazz: type) -> Logger:
179
+ base_logger = logger_for_class(clazz)
180
+ return JobLogger(base_logger, *self.__handlers)
181
+
182
+ def logger_for_namespace(self, namespace: str) -> Logger:
183
+ base_logger = logger_for_namespace(namespace)
184
+ return JobLogger(base_logger, *self.__handlers)
185
+
186
+
187
+ def job_log_provider(target: _tp.BinaryIO) -> JobLogProvider:
188
+
189
+ stream = _io.TextIOWrapper(target, newline="\r\n")
190
+ formatter = PlainFormatter()
191
+
192
+ handler = StreamHandler(stream)
193
+ handler.setFormatter(formatter)
194
+
195
+ return JobLogProvider(handler)
@@ -25,11 +25,12 @@ import tracdap.rt.metadata as _meta
25
25
  import tracdap.rt.config as _cfg
26
26
  import tracdap.rt.exceptions as _ex
27
27
 
28
- import tracdap.rt._impl.type_system as _types
29
- import tracdap.rt._impl.repos as _repos
30
- import tracdap.rt._impl.shim as _shim
31
- import tracdap.rt._impl.util as _util
32
- import tracdap.rt._impl.validation as _val
28
+ import tracdap.rt._impl.core.logging as _logging
29
+ import tracdap.rt._impl.core.repos as _repos
30
+ import tracdap.rt._impl.core.shim as _shim
31
+ import tracdap.rt._impl.core.type_system as _types
32
+ import tracdap.rt._impl.core.util as _util
33
+ import tracdap.rt._impl.core.validation as _val
33
34
 
34
35
 
35
36
  class ModelLoader:
@@ -43,7 +44,7 @@ class ModelLoader:
43
44
 
44
45
  def __init__(self, sys_config: _cfg.RuntimeConfig, scratch_dir: pathlib.Path):
45
46
 
46
- self.__log = _util.logger_for_object(self)
47
+ self.__log = _logging.logger_for_object(self)
47
48
 
48
49
  self.__scratch_dir = scratch_dir.joinpath("models")
49
50
  self.__repos = _repos.RepositoryManager(sys_config)
@@ -13,10 +13,12 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ import typing as _tp
17
+
16
18
  import tracdap.rt.ext.plugins as plugins
17
19
  import tracdap.rt.config as cfg
18
20
  import tracdap.rt.exceptions as ex
19
- import tracdap.rt._impl.util as util
21
+ import tracdap.rt._impl.core.logging as _logging
20
22
 
21
23
  # Import repo interfaces
22
24
  from tracdap.rt.ext.repos import *
@@ -26,8 +28,8 @@ class RepositoryManager:
26
28
 
27
29
  def __init__(self, sys_config: cfg.RuntimeConfig):
28
30
 
29
- self._log = util.logger_for_object(self)
30
- self._repos: tp.Dict[str, IModelRepository] = dict()
31
+ self._log = _logging.logger_for_object(self)
32
+ self._repos: _tp.Dict[str, IModelRepository] = dict()
31
33
 
32
34
  # Initialize all repos in the system config
33
35
  # Any errors for missing repo types (plugins) will be raised during startup
@@ -21,10 +21,10 @@ import pyarrow as pa
21
21
 
22
22
  import tracdap.rt.metadata as _meta
23
23
  import tracdap.rt.exceptions as _ex
24
- import tracdap.rt._impl.data as _data
25
- import tracdap.rt._impl.storage as _storage
26
- import tracdap.rt._impl.shim as _shim
27
- import tracdap.rt._impl.util as _util
24
+ import tracdap.rt._impl.core.data as _data
25
+ import tracdap.rt._impl.core.logging as _log
26
+ import tracdap.rt._impl.core.storage as _storage
27
+ import tracdap.rt._impl.core.shim as _shim
28
28
 
29
29
 
30
30
  class SchemaLoader:
@@ -169,4 +169,4 @@ class SchemaLoader:
169
169
  raise _ex.EDataConformance(err)
170
170
 
171
171
 
172
- SchemaLoader._log = _util.logger_for_class(SchemaLoader)
172
+ SchemaLoader._log = _log.logger_for_class(SchemaLoader)
@@ -30,8 +30,9 @@ import importlib.machinery as _ilm
30
30
  import importlib.resources as _ilr
31
31
 
32
32
  import tracdap.rt.exceptions as _ex
33
- import tracdap.rt._impl.guard_rails as _guard
34
- import tracdap.rt._impl.util as _util
33
+ import tracdap.rt._impl.core.guard_rails as _guard
34
+ import tracdap.rt._impl.core.logging as _log
35
+ import tracdap.rt._impl.core.util as _util
35
36
 
36
37
 
37
38
  class _Shim:
@@ -138,7 +139,7 @@ class _NamespaceShimFinder(_ila.MetaPathFinder):
138
139
  def __init__(self, shim_map: tp.Dict[str, _Shim], active_shim: _ActiveShim):
139
140
  self.__shim_map = shim_map
140
141
  self.__active_shim = active_shim
141
- self._log = _util.logger_for_class(ShimLoader)
142
+ self._log = _log.logger_for_class(ShimLoader)
142
143
 
143
144
  def find_spec(
144
145
  self, fullname: str,
@@ -561,5 +562,5 @@ class ShimLoader:
561
562
  raise _ex.ERuntimeValidation(err)
562
563
 
563
564
 
564
- ShimLoader._log = _util.logger_for_class(ShimLoader)
565
+ ShimLoader._log = _log.logger_for_class(ShimLoader)
565
566
  ShimLoader._init() # noqa
@@ -29,9 +29,10 @@ import tracdap.rt.metadata as _meta
29
29
  import tracdap.rt.config as _cfg
30
30
  import tracdap.rt.exceptions as _ex
31
31
  import tracdap.rt.ext.plugins as plugins
32
- import tracdap.rt._impl.data as _data
33
- import tracdap.rt._impl.util as _util
34
- import tracdap.rt._impl.validation as _val
32
+ import tracdap.rt._impl.core.data as _data
33
+ import tracdap.rt._impl.core.logging as _logging
34
+ import tracdap.rt._impl.core.util as _util
35
+ import tracdap.rt._impl.core.validation as _val
35
36
 
36
37
  # Import storage interfaces (using the internal version, it has extra bits that are not public)
37
38
  from tracdap.rt._impl.ext.storage import *
@@ -76,7 +77,7 @@ class StorageManager:
76
77
 
77
78
  def __init__(self, sys_config: _cfg.RuntimeConfig):
78
79
 
79
- self.__log = _util.logger_for_object(self)
80
+ self.__log = _logging.logger_for_object(self)
80
81
  self.__file_storage: tp.Dict[str, IFileStorage] = dict()
81
82
  self.__data_storage: tp.Dict[str, IDataStorage] = dict()
82
83
  self.__external: tp.List[str] = list()
@@ -224,7 +225,7 @@ class CommonFileStorage(IFileStorage):
224
225
 
225
226
  def __init__(self, storage_key: str, storage_config: _cfg.PluginConfig, fs: pa_fs.SubTreeFileSystem):
226
227
 
227
- self._log = _util.logger_for_object(self)
228
+ self._log = _logging.logger_for_object(self)
228
229
  self._key = storage_key
229
230
  self._config = storage_config
230
231
  self._fs = fs
@@ -731,7 +732,7 @@ class CommonDataStorage(IDataStorage):
731
732
  self, config: _cfg.PluginConfig, file_storage: IFileStorage,
732
733
  pushdown_pandas: bool = False, pushdown_spark: bool = False):
733
734
 
734
- self.__log = _util.logger_for_object(self)
735
+ self.__log = _logging.logger_for_object(self)
735
736
 
736
737
  self.__config = config
737
738
  self.__file_storage = file_storage
@@ -14,11 +14,9 @@
14
14
  # limitations under the License.
15
15
 
16
16
  import datetime as dt
17
- import logging
18
17
  import pathlib
19
18
  import platform
20
19
 
21
- import sys
22
20
  import typing as tp
23
21
  import uuid
24
22
 
@@ -38,114 +36,6 @@ def is_windows():
38
36
  return __IS_WINDOWS
39
37
 
40
38
 
41
- class ColorFormatter(logging.Formatter):
42
-
43
- _BLACK, _RED, _GREEN, _YELLOW, _BLUE, _MAGENTA, _CYAN, _WHITE, _DEFAULT_WHITE = range(9)
44
- _DARK_BASE = 30
45
- _LIGHT_BASE = 90
46
-
47
- # DARK_BASE + WHITE = light grey
48
- # DARK_BASE + DEFAULT_WHITE = regular console white
49
- # LIGHT_BASE + WHITE = bright white (0xffffff), very bright!
50
-
51
- def __init__(self, is_bright: bool):
52
-
53
- super().__init__(self._base_fmt(is_bright))
54
- self._level_colors = self._make_level_colors(is_bright)
55
- self._default_color = self._make_default_color(is_bright)
56
-
57
- def format(self, record):
58
-
59
- level_name = record.levelname
60
- level_color = self._level_colors.get(level_name)
61
-
62
- if level_color:
63
- record.levelname = level_color
64
- else:
65
- record.levelname = self._default_color + level_name
66
-
67
- return logging.Formatter.format(self, record)
68
-
69
- def _base_fmt(self, is_bright: bool):
70
-
71
- if is_bright:
72
- base_color = self._make_ansi_code(self._DARK_BASE, self._DEFAULT_WHITE, is_bold=False)
73
- message_color = self._make_ansi_code(self._LIGHT_BASE, self._CYAN, is_bold=False)
74
- else:
75
- base_color = self._make_ansi_code(self._DARK_BASE, self._WHITE, is_bold=False)
76
- message_color = self._make_ansi_code(self._DARK_BASE, self._CYAN, is_bold=False)
77
-
78
- return f"{base_color}%(asctime)s [%(threadName)s] %(levelname)s{base_color} %(name)s" + \
79
- f" - {message_color}%(message)s"
80
-
81
- def _make_level_colors(self, is_bright: bool):
82
-
83
- base_code = self._LIGHT_BASE if is_bright else self._DARK_BASE
84
-
85
- green = self._make_ansi_code(base_code, self._GREEN, is_bold=is_bright)
86
- yellow = self._make_ansi_code(base_code, self._YELLOW, is_bold=is_bright)
87
- red = self._make_ansi_code(base_code, self._RED, is_bold=is_bright)
88
-
89
- level_colors = {
90
- 'CRITICAL': f"{red}CRITICAL",
91
- 'ERROR': f"{red}ERROR",
92
- 'WARNING': f"{yellow}WARNING",
93
- 'INFO': f"{green}INFO"
94
- }
95
-
96
- return level_colors
97
-
98
- def _make_default_color(self, is_bright: bool):
99
-
100
- base_code = self._LIGHT_BASE if is_bright else self._DARK_BASE
101
- blue = self._make_ansi_code(base_code, self._BLUE, is_bold=is_bright)
102
-
103
- return blue
104
-
105
- @classmethod
106
- def _make_ansi_code(cls, base_code: int, color_offset: int, is_bold: bool):
107
- return f"\033[{1 if is_bold else 0};{base_code + color_offset}m"
108
-
109
-
110
- def configure_logging(enable_debug=False):
111
-
112
- root_logger = logging.getLogger()
113
- log_level = logging.DEBUG if enable_debug else logging.INFO
114
-
115
- if not root_logger.hasHandlers():
116
-
117
- console_formatter = ColorFormatter(is_bright=True)
118
- console_handler = logging.StreamHandler(sys.stdout)
119
- console_handler.setFormatter(console_formatter)
120
- console_handler.setLevel(logging.INFO)
121
- root_logger.addHandler(console_handler)
122
- root_logger.setLevel(log_level)
123
-
124
- # Use is_bright=False for logs from the TRAC runtime, so model logs stand out
125
-
126
- trac_logger = logging.getLogger("tracdap.rt")
127
-
128
- console_formatter = ColorFormatter(is_bright=False)
129
- console_handler = logging.StreamHandler(sys.stdout)
130
- console_handler.setFormatter(console_formatter)
131
- console_handler.setLevel(log_level)
132
- trac_logger.addHandler(console_handler)
133
- trac_logger.propagate = False
134
-
135
-
136
- def logger_for_object(obj: object) -> logging.Logger:
137
- return logger_for_class(obj.__class__)
138
-
139
-
140
- def logger_for_class(clazz: type) -> logging.Logger:
141
- qualified_class_name = f"{clazz.__module__}.{clazz.__name__}"
142
- return logging.getLogger(qualified_class_name)
143
-
144
-
145
- def logger_for_namespace(namespace: str) -> logging.Logger:
146
- return logging.getLogger(namespace)
147
-
148
-
149
39
  def format_file_size(size: int) -> str:
150
40
 
151
41
  if size < 1024:
@@ -22,7 +22,8 @@ import pathlib
22
22
 
23
23
  import tracdap.rt.metadata as meta
24
24
  import tracdap.rt.exceptions as ex
25
- import tracdap.rt._impl.util as util
25
+ import tracdap.rt._impl.core.logging as log
26
+ import tracdap.rt._impl.core.util as util
26
27
 
27
28
  # _Named placeholder type from API hook is needed for API type checking
28
29
  from tracdap.rt.api.hook import _Named # noqa
@@ -74,7 +75,7 @@ class _TypeValidator:
74
75
  # Inspecting a function signature can take ~ half a second in Python 3.7
75
76
  __method_cache: tp.Dict[str, tp.Tuple[inspect.Signature, tp.Any]] = dict()
76
77
 
77
- _log: logging.Logger = util.logger_for_namespace(__name__)
78
+ _log: logging.Logger = log.logger_for_namespace(__name__)
78
79
 
79
80
  @classmethod
80
81
  def validate_signature(cls, method: tp.Callable, *args, **kwargs):
@@ -324,7 +325,7 @@ class StaticValidator:
324
325
  meta.BasicType.INTEGER,
325
326
  meta.BasicType.DATE]
326
327
 
327
- _log: logging.Logger = util.logger_for_namespace(__name__)
328
+ _log: logging.Logger = log.logger_for_namespace(__name__)
328
329
 
329
330
  @classmethod
330
331
  def is_primitive_type(cls, basic_type: meta.BasicType) -> bool:
@@ -0,0 +1,14 @@
1
+ # Licensed to the Fintech Open Source Foundation (FINOS) under one or
2
+ # more contributor license agreements. See the NOTICE file distributed
3
+ # with this work for additional information regarding copyright ownership.
4
+ # FINOS licenses this file to you under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.