commonlib-reader 1.4.1__tar.gz → 1.4.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: commonlib-reader
3
- Version: 1.4.1
3
+ Version: 1.4.2
4
4
  Summary: Reader for Equinor commonlib api.
5
5
  Author: Åsmund Våge Fannemel
6
6
  Author-email: Åsmund Våge Fannemel <asmf@equinor.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "commonlib-reader"
3
- version = "1.4.1"
3
+ version = "1.4.2"
4
4
  description = "Reader for Equinor commonlib api."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10,<4.0.0"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "commonlib-reader"
3
- version = "1.4.1"
3
+ version = "1.4.2"
4
4
  description = "Reader for Equinor commonlib api."
5
5
  authors = [
6
6
  { name = "Åsmund Våge Fannemel", email = "asmf@equinor.com" }
@@ -1,5 +1,3 @@
1
- from collections.abc import Mapping
2
- from types import MappingProxyType
3
1
  from typing import List, Union
4
2
 
5
3
  from commonlib_reader.code import Code
@@ -149,39 +147,11 @@ class Unit(Code):
149
147
  """Get internal maintenance comments, if provided."""
150
148
  return self.attributes.get("InternalComments", "")
151
149
 
152
- @classmethod
153
- def _freeze_cache_value(cls, value):
154
- if isinstance(value, dict):
155
- return MappingProxyType(
156
- {
157
- key: cls._freeze_cache_value(item)
158
- for key, item in value.items()
159
- }
160
- )
161
- if isinstance(value, (list, tuple)):
162
- return tuple(cls._freeze_cache_value(item) for item in value)
163
- return value
164
-
165
- @classmethod
166
- def _thaw_cache_value(cls, value):
167
- if isinstance(value, Mapping):
168
- return {
169
- key: cls._thaw_cache_value(item) for key, item in value.items()
170
- }
171
- if isinstance(value, tuple):
172
- return [cls._thaw_cache_value(item) for item in value]
173
- return value
174
-
175
150
  @classmethod
176
151
  def _get_conversion_codes(cls):
177
152
  if cls._conversion_codes is None:
178
153
  codes = Code.get_codes("UnitOfMeasureConversion")
179
- cls._conversion_codes = MappingProxyType(
180
- {
181
- code.identity: cls._freeze_cache_value(code.attributes)
182
- for code in codes
183
- }
184
- )
154
+ cls._conversion_codes = {code.identity: code for code in codes}
185
155
  return cls._conversion_codes
186
156
 
187
157
  def _get_conversion_factors(self):
@@ -192,15 +162,15 @@ class Unit(Code):
192
162
  the inverse is ``base_value * FactorA + FactorB``.
193
163
  """
194
164
  reference = self.conversion
195
- conversion_attributes = self._get_conversion_codes().get(reference)
196
- if conversion_attributes is None:
165
+ conversion_code = self._get_conversion_codes().get(reference)
166
+ if conversion_code is None:
197
167
  raise ValueError(
198
168
  f"No conversion factors found for unit {self.name} ({reference})."
199
169
  )
200
170
 
201
171
  try:
202
- factor_a = float(conversion_attributes["FactorA"])
203
- factor_b = float(conversion_attributes["FactorB"])
172
+ factor_a = float(conversion_code.attributes["FactorA"])
173
+ factor_b = float(conversion_code.attributes["FactorB"])
204
174
  except (KeyError, TypeError, ValueError):
205
175
  raise ValueError(
206
176
  f"Invalid conversion factors for unit {self.name} ({reference})."
@@ -310,7 +280,6 @@ class Unit(Code):
310
280
  List[Unit]: List of Unit objects from entries in code library.
311
281
  """
312
282
  if cls._units is None:
313
- units = Code._get_code_data("UnitOfMeasure")
314
- cls._units = tuple(cls._freeze_cache_value(unit) for unit in units)
283
+ cls._units = Code._get_code_data("UnitOfMeasure")
315
284
 
316
- return [cls(cls._thaw_cache_value(unit)) for unit in cls._units]
285
+ return [cls(x) for x in cls._units]