commonlib-reader 1.4.0__tar.gz → 1.4.1__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,12 +1,11 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: commonlib-reader
3
- Version: 1.4.0
3
+ Version: 1.4.1
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>
7
7
  License: MIT
8
- Requires-Dist: pandas>=2.1.4
9
- Requires-Dist: eq-api-connector>=1.1.0,<2.0.0
8
+ Requires-Dist: eq-api-connector>=1.2.0,<2.0.0
10
9
  Requires-Python: >=3.10, <4.0.0
11
10
  Project-URL: Repository, https://github.com/equinor/commonlib-reader.git
12
11
  Description-Content-Type: text/markdown
@@ -1,13 +1,10 @@
1
1
  [project]
2
2
  name = "commonlib-reader"
3
- version = "1.4.0"
3
+ version = "1.4.1"
4
4
  description = "Reader for Equinor commonlib api."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10,<4.0.0"
7
- dependencies = [
8
- "pandas>=2.1.4",
9
- "eq-api-connector (>=1.1.0,<2.0.0)",
10
- ]
7
+ dependencies = ["eq-api-connector (>=1.2.0,<2.0.0)"]
11
8
 
12
9
  [[project.authors]]
13
10
  name = "Åsmund Våge Fannemel"
@@ -21,11 +18,11 @@ Repository = "https://github.com/equinor/commonlib-reader.git"
21
18
 
22
19
  [dependency-groups]
23
20
  dev = [
24
- "pytest>=7.4.4,<10.0.0",
21
+ "pytest>=9.2.0,<10.0.0",
25
22
  "pytest-cov>=7.0.0,<8.0.0",
26
- "black>=24.1.1,<27.0.0",
23
+ "black>=26.10.0,<27.0.0",
27
24
  ]
28
25
 
29
26
  [build-system]
30
- requires = ["uv_build>=0.11.16,<0.13"]
27
+ requires = ["uv_build>=0.11.16,<0.14"]
31
28
  build-backend = "uv_build"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "commonlib-reader"
3
- version = "1.4.0"
3
+ version = "1.4.1"
4
4
  description = "Reader for Equinor commonlib api."
5
5
  authors = [
6
6
  { name = "Åsmund Våge Fannemel", email = "asmf@equinor.com" }
@@ -10,17 +10,16 @@ license = { text = "MIT" }
10
10
  urls = {"Repository" = "https://github.com/equinor/commonlib-reader.git"}
11
11
  requires-python = ">=3.10,<4.0.0"
12
12
  dependencies = [
13
- "pandas>=2.1.4",
14
- "eq-api-connector (>=1.1.0,<2.0.0)"
13
+ "eq-api-connector (>=1.2.0,<2.0.0)"
15
14
  ]
16
15
 
17
16
  [dependency-groups]
18
17
  dev = [
19
- "pytest>=7.4.4,<10.0.0",
18
+ "pytest>=9.2.0,<10.0.0",
20
19
  "pytest-cov>=7.0.0,<8.0.0",
21
- "black>=24.1.1,<27.0.0"
20
+ "black>=26.10.0,<27.0.0"
22
21
  ]
23
22
 
24
23
  [build-system]
25
- requires = ["uv_build>=0.11.16,<0.13"]
24
+ requires = ["uv_build>=0.11.16,<0.14"]
26
25
  build-backend = "uv_build"
@@ -1,3 +1,5 @@
1
+ from collections.abc import Mapping
2
+ from types import MappingProxyType
1
3
  from typing import List, Union
2
4
 
3
5
  from commonlib_reader.code import Code
@@ -147,11 +149,39 @@ class Unit(Code):
147
149
  """Get internal maintenance comments, if provided."""
148
150
  return self.attributes.get("InternalComments", "")
149
151
 
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
+
150
175
  @classmethod
151
176
  def _get_conversion_codes(cls):
152
177
  if cls._conversion_codes is None:
153
178
  codes = Code.get_codes("UnitOfMeasureConversion")
154
- cls._conversion_codes = {code.identity: code for code in codes}
179
+ cls._conversion_codes = MappingProxyType(
180
+ {
181
+ code.identity: cls._freeze_cache_value(code.attributes)
182
+ for code in codes
183
+ }
184
+ )
155
185
  return cls._conversion_codes
156
186
 
157
187
  def _get_conversion_factors(self):
@@ -162,15 +192,15 @@ class Unit(Code):
162
192
  the inverse is ``base_value * FactorA + FactorB``.
163
193
  """
164
194
  reference = self.conversion
165
- conversion_code = self._get_conversion_codes().get(reference)
166
- if conversion_code is None:
195
+ conversion_attributes = self._get_conversion_codes().get(reference)
196
+ if conversion_attributes is None:
167
197
  raise ValueError(
168
198
  f"No conversion factors found for unit {self.name} ({reference})."
169
199
  )
170
200
 
171
201
  try:
172
- factor_a = float(conversion_code.attributes["FactorA"])
173
- factor_b = float(conversion_code.attributes["FactorB"])
202
+ factor_a = float(conversion_attributes["FactorA"])
203
+ factor_b = float(conversion_attributes["FactorB"])
174
204
  except (KeyError, TypeError, ValueError):
175
205
  raise ValueError(
176
206
  f"Invalid conversion factors for unit {self.name} ({reference})."
@@ -280,6 +310,7 @@ class Unit(Code):
280
310
  List[Unit]: List of Unit objects from entries in code library.
281
311
  """
282
312
  if cls._units is None:
283
- cls._units = Code._get_code_data("UnitOfMeasure")
313
+ units = Code._get_code_data("UnitOfMeasure")
314
+ cls._units = tuple(cls._freeze_cache_value(unit) for unit in units)
284
315
 
285
- return [cls(x) for x in cls._units]
316
+ return [cls(cls._thaw_cache_value(unit)) for unit in cls._units]