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.
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/PKG-INFO +1 -1
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/pyproject.toml +1 -1
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/pyproject.toml.orig +1 -1
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/unit.py +7 -38
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/README.md +0 -0
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/__init__.py +0 -0
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/code.py +0 -0
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/connector.py +0 -0
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/discipline.py +0 -0
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/facility.py +0 -0
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/ims.py +0 -0
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/library.py +0 -0
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/project.py +0 -0
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/tag.py +0 -0
- {commonlib_reader-1.4.1 → commonlib_reader-1.4.2}/src/commonlib_reader/utils.py +0 -0
|
@@ -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 =
|
|
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
|
-
|
|
196
|
-
if
|
|
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(
|
|
203
|
-
factor_b = float(
|
|
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
|
-
|
|
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(
|
|
285
|
+
return [cls(x) for x in cls._units]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|