fmu-settings 0.3.0__py3-none-any.whl → 0.3.2__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.

Potentially problematic release.


This version of fmu-settings might be problematic. Click here for more details.

@@ -153,7 +153,17 @@ class LockManager(PydanticResourceManager[LockInfo]):
153
153
  temp_path.unlink()
154
154
 
155
155
  def is_locked(self: Self) -> bool:
156
- """Returns whether or not the lock is currently locked."""
156
+ """Returns whether or not the lock is locked by anyone.
157
+
158
+ This does a force load on the lock file.
159
+ """
160
+ lock_info = self._safe_load(force=True)
161
+ if not lock_info:
162
+ return False
163
+ return time.time() < lock_info.expires_at
164
+
165
+ def is_acquired(self: Self) -> bool:
166
+ """Returns whether or not the lock is currently acquired by this instance."""
157
167
  if self._cache is None or self._acquired_at is None:
158
168
  return False
159
169
  return self._is_mine(self._cache) and not self._is_stale()
@@ -219,13 +229,13 @@ class LockManager(PydanticResourceManager[LockInfo]):
219
229
  and lock_info.acquired_at == self._acquired_at
220
230
  )
221
231
 
222
- def _safe_load(self: Self) -> LockInfo | None:
232
+ def _safe_load(self: Self, force: bool = False) -> LockInfo | None:
223
233
  """Load lock info, returning None if corrupted.
224
234
 
225
235
  Because this file does not exist in a static state, wrap around loading it.
226
236
  """
227
237
  try:
228
- return self.load()
238
+ return self.load(force=force)
229
239
  except Exception:
230
240
  return None
231
241
 
@@ -48,11 +48,14 @@ class PydanticResourceManager(Generic[T]):
48
48
  """Returns whether or not the resource exists."""
49
49
  return self.path.exists()
50
50
 
51
- def load(self: Self, force: bool = False) -> T:
52
- """Loads the resources from disk and validates it as a Pydantic model.
51
+ def load(self: Self, force: bool = False, store_cache: bool = True) -> T:
52
+ """Loads the resource from disk and validates it as a Pydantic model.
53
53
 
54
54
  Args:
55
- force: Force a re-read even if the file is already cached
55
+ force: Force a re-read even if the file is already cached.
56
+ store_cache: Whether or not to cache the loaded model internally. This is
57
+ best used with 'force=True' because if a model is already stored in
58
+ _cache it will be returned without re-loading. Default True.
56
59
 
57
60
  Returns:
58
61
  Validated Pydantic model
@@ -71,7 +74,11 @@ class PydanticResourceManager(Generic[T]):
71
74
  try:
72
75
  content = self.fmu_dir.read_text_file(self.relative_path)
73
76
  data = json.loads(content)
74
- self._cache = self.model_class.model_validate(data)
77
+ validated_model = self.model_class.model_validate(data)
78
+ if store_cache:
79
+ self._cache = validated_model
80
+ else:
81
+ return validated_model
75
82
  except ValidationError as e:
76
83
  raise ValueError(
77
84
  f"Invalid content in resource file for '{self.__class__.__name__}: "
fmu/settings/_version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.3.0'
32
- __version_tuple__ = version_tuple = (0, 3, 0)
31
+ __version__ = version = '0.3.2'
32
+ __version_tuple__ = version_tuple = (0, 3, 2)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fmu-settings
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: A library for managing FMU settings
5
5
  Author-email: Equinor <fg-fmu_atlas@equinor.com>
6
6
  License: GPL-3.0
@@ -3,21 +3,21 @@ fmu/settings/__init__.py,sha256=CkEE7al_uBCQO1lxBKN5LzyCwzzH5Aq6kkEIR7f-zTw,336
3
3
  fmu/settings/_fmu_dir.py,sha256=Br_hcfAXshiuDyWqG_qx5VXFpsCBJO1XDMPzdxxesoE,10684
4
4
  fmu/settings/_init.py,sha256=5CT7tV2XHz5wuLh97XozyLiKpwogrsfjpxm2dpn7KWE,4097
5
5
  fmu/settings/_logging.py,sha256=nEdmZlNCBsB1GfDmFMKCjZmeuRp3CRlbz1EYUemc95Y,1104
6
- fmu/settings/_version.py,sha256=5zTqm8rgXsWYBpB2M3Zw_K1D-aV8wP7NsBLrmMKkrAQ,704
6
+ fmu/settings/_version.py,sha256=e8NqPtZ8fggRgk3GPrqZ_U_BDV8aSULw1u_Gn9NNbnk,704
7
7
  fmu/settings/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  fmu/settings/types.py,sha256=aeXEsznBTT1YRRY_LSRqK1j2gmMmyLYYTGYl3a9fweU,513
9
9
  fmu/settings/_resources/__init__.py,sha256=LHYR_F7lNGdv8N6R3cEwds5CJQpkOthXFqsEs24vgF8,118
10
10
  fmu/settings/_resources/config_managers.py,sha256=IjOtS2lSU55GE_TWqHjbBPAzE8xQyVBvpHcfm0hTSnI,6822
11
- fmu/settings/_resources/lock_manager.py,sha256=IS7V7W1kCD45v-0tnhZYw0GD1MLl_DatqOeF9xazllg,8838
12
- fmu/settings/_resources/pydantic_resource_manager.py,sha256=9zFcOUJKeapxbYvgerf3t2_9pL5acFU2rknri67pXt0,3131
11
+ fmu/settings/_resources/lock_manager.py,sha256=_xzSJNF_qcpKpo8AxMfEgOhPxKXl3fZ2lRi0_y2eUEg,9206
12
+ fmu/settings/_resources/pydantic_resource_manager.py,sha256=NV9qGnKaZ2RYt6o2NMaHvKyiZDIsxwD5y3y2a6QQtHw,3555
13
13
  fmu/settings/models/__init__.py,sha256=lRlXgl55ba2upmDzdvzx8N30JMq2Osnm8aa_xxTZn8A,112
14
14
  fmu/settings/models/_enums.py,sha256=SQUZ-2mQcTx4F0oefPFfuQzMKsKTSFSB-wq_CH7TBRE,734
15
15
  fmu/settings/models/_mappings.py,sha256=Z4Ex7MtmajBr6FjaNzmwDRwtJlaZZ8YKh9NDmZHRKPI,2832
16
16
  fmu/settings/models/lock_info.py,sha256=-oHDF9v9bDLCoFvEg4S6XXYLeo19zRAZ8HynCv75VWg,711
17
17
  fmu/settings/models/project_config.py,sha256=pxb54JmpXNMVAFUu_yJ89dNrYEk6hrPuFfFUpf84Jh0,1099
18
18
  fmu/settings/models/user_config.py,sha256=dWFTcZY6UnEgNTuGqB-izraJ657PecsW0e0Nt9GBDhI,2666
19
- fmu_settings-0.3.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
20
- fmu_settings-0.3.0.dist-info/METADATA,sha256=IQAnLz_3cQpmOvKXTb14y2V37Ozu9dHP3OxzgZPrv8Q,2024
21
- fmu_settings-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
- fmu_settings-0.3.0.dist-info/top_level.txt,sha256=Z-FIY3pxn0UK2Wxi9IJ7fKoLSraaxuNGi1eokiE0ShM,4
23
- fmu_settings-0.3.0.dist-info/RECORD,,
19
+ fmu_settings-0.3.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
20
+ fmu_settings-0.3.2.dist-info/METADATA,sha256=CC-jegtLPAS2vpUajvXTd3D_Fyow5q62Dwy4WDH4ypA,2024
21
+ fmu_settings-0.3.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
+ fmu_settings-0.3.2.dist-info/top_level.txt,sha256=Z-FIY3pxn0UK2Wxi9IJ7fKoLSraaxuNGi1eokiE0ShM,4
23
+ fmu_settings-0.3.2.dist-info/RECORD,,