fmu-settings 0.5.0__py3-none-any.whl → 0.5.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.
@@ -145,16 +145,18 @@ def load_global_configuration_if_present(
145
145
  fmu_load: Whether or not to load in the custom 'fmu' format. Default False.
146
146
 
147
147
  Returns:
148
- GlobalConfiguration instance or None.
148
+ GlobalConfiguration instance or None if file cannot be loaded.
149
+
150
+ Raises:
151
+ ValidationError: If the file is loaded but has invalid schema.
149
152
  """
150
153
  loader = "fmu" if fmu_load else "standard"
151
154
  try:
152
155
  global_variables_dict = yaml_load(path, loader=loader)
153
156
  global_config = GlobalConfiguration.model_validate(global_variables_dict)
154
157
  logger.debug(f"Global variables at {path} has valid settings data")
155
- except ValidationError as e:
156
- logger.debug(f"Global variables at {path} failed validation: {e}")
157
- return None
158
+ except ValidationError:
159
+ raise
158
160
  except Exception as e:
159
161
  logger.debug(
160
162
  f"Failed to load global variables at {path}: {type(e).__name__}: {e}"
@@ -173,6 +175,9 @@ def _find_global_variables_file(paths: list[Path]) -> GlobalConfiguration | None
173
175
 
174
176
  Returns:
175
177
  A validated GlobalConfiguration or None.
178
+
179
+ Raises:
180
+ ValidationError: If a file is found but has invalid schema.
176
181
  """
177
182
  for path in paths:
178
183
  if not path.exists():
@@ -204,6 +209,9 @@ def _find_global_config_file(paths: list[Path]) -> GlobalConfiguration | None:
204
209
 
205
210
  Returns:
206
211
  A validated GlobalConfiguration or None.
212
+
213
+ Raises:
214
+ ValidationError: If a file is found but has invalid schema.
207
215
  """
208
216
  for path in paths:
209
217
  if not path.exists():
@@ -241,6 +249,11 @@ def find_global_config(
241
249
 
242
250
  Returns:
243
251
  A valid GlobalConfiguration instance, or None.
252
+
253
+ Raises:
254
+ ValidationError: If a configuration file is found but has invalid schema.
255
+ InvalidGlobalConfigurationError: If strict=True and configuration contains
256
+ disallowed content (e.g., Drogon data).
244
257
  """
245
258
  base_path = Path(base_path)
246
259
 
@@ -194,6 +194,8 @@ class LockManager(PydanticResourceManager[LockInfo]):
194
194
  LockError: If we don't hold the lock or it's invalid
195
195
  """
196
196
  if not self.exists:
197
+ if self.is_acquired():
198
+ self.release()
197
199
  raise LockError("Cannot refresh: lock file does not exist")
198
200
 
199
201
  lock_info = self._safe_load()
@@ -112,21 +112,21 @@ class PydanticResourceManager(Generic[PydanticResource]):
112
112
 
113
113
 
114
114
  class MutablePydanticResourceManager(PydanticResourceManager[MutablePydanticResource]):
115
- """Manages the .fmu configuration file."""
115
+ """Manages the .fmu resource file."""
116
116
 
117
117
  def __init__(
118
- self: Self, fmu_dir: FMUDirectoryBase, config: type[MutablePydanticResource]
118
+ self: Self, fmu_dir: FMUDirectoryBase, resource: type[MutablePydanticResource]
119
119
  ) -> None:
120
- """Initializes the Config resource manager."""
121
- super().__init__(fmu_dir, config)
120
+ """Initializes the resource manager."""
121
+ super().__init__(fmu_dir, resource)
122
122
 
123
123
  def _get_dot_notation_key(
124
- self: Self, config_dict: dict[str, Any], key: str, default: Any = None
124
+ self: Self, resource_dict: dict[str, Any], key: str, default: Any = None
125
125
  ) -> Any:
126
126
  """Sets the value to a dot-notation key.
127
127
 
128
128
  Args:
129
- config_dict: The configuration dictionary we are modifying (by reference)
129
+ resource_dict: The resource dictionary we are modifying (by reference)
130
130
  key: The key to set
131
131
  default: Value to return if key is not found. Default None
132
132
 
@@ -134,7 +134,7 @@ class MutablePydanticResourceManager(PydanticResourceManager[MutablePydanticReso
134
134
  The value or default
135
135
  """
136
136
  parts = key.split(".")
137
- value = config_dict
137
+ value = resource_dict
138
138
  for part in parts:
139
139
  if isinstance(value, dict) and part in value:
140
140
  value = value[part]
@@ -144,28 +144,28 @@ class MutablePydanticResourceManager(PydanticResourceManager[MutablePydanticReso
144
144
  return value
145
145
 
146
146
  def get(self: Self, key: str, default: Any = None) -> Any:
147
- """Gets a configuration value by key.
147
+ """Gets a resource value by key.
148
148
 
149
149
  Supports dot notation for nested values (e.g., "foo.bar")
150
150
 
151
151
  Args:
152
- key: The configuration key
152
+ key: The resource key
153
153
  default: Value to return if key is not found. Default None
154
154
 
155
155
  Returns:
156
- The configuration value or default
156
+ The resource value or default
157
157
  """
158
158
  try:
159
- config = self.load()
159
+ resource = self.load()
160
160
 
161
161
  if "." in key:
162
- return self._get_dot_notation_key(config.model_dump(), key, default)
162
+ return self._get_dot_notation_key(resource.model_dump(), key, default)
163
163
 
164
- if hasattr(config, key):
165
- return getattr(config, key)
164
+ if hasattr(resource, key):
165
+ return getattr(resource, key)
166
166
 
167
- config_dict = config.model_dump()
168
- return config_dict.get(key, default)
167
+ resource_dict = resource.model_dump()
168
+ return resource_dict.get(key, default)
169
169
  except FileNotFoundError as e:
170
170
  raise FileNotFoundError(
171
171
  f"Resource file for '{self.__class__.__name__}' not found "
@@ -173,17 +173,17 @@ class MutablePydanticResourceManager(PydanticResourceManager[MutablePydanticReso
173
173
  ) from e
174
174
 
175
175
  def _set_dot_notation_key(
176
- self: Self, config_dict: dict[str, Any], key: str, value: Any
176
+ self: Self, resource_dict: dict[str, Any], key: str, value: Any
177
177
  ) -> None:
178
178
  """Sets the value to a dot-notation key.
179
179
 
180
180
  Args:
181
- config_dict: The configuration dictionary we are modifying (by reference)
181
+ resource_dict: The resource dictionary we are modifying (by reference)
182
182
  key: The key to set
183
183
  value: The value to set
184
184
  """
185
185
  parts = key.split(".")
186
- target = config_dict
186
+ target = resource_dict
187
187
 
188
188
  for part in parts[:-1]:
189
189
  if part not in target or not isinstance(target[part], dict):
@@ -193,27 +193,27 @@ class MutablePydanticResourceManager(PydanticResourceManager[MutablePydanticReso
193
193
  target[parts[-1]] = value
194
194
 
195
195
  def set(self: Self, key: str, value: Any) -> None:
196
- """Sets a configuration value by key.
196
+ """Sets a resource value by key.
197
197
 
198
198
  Args:
199
- key: The configuration key
199
+ key: The resource key
200
200
  value: The value to set
201
201
 
202
202
  Raises:
203
- FileNotFoundError: If config file doesn't exist
204
- ValueError: If the updated config is invalid
203
+ FileNotFoundError: If resource file doesn't exist
204
+ ValueError: If the updated resource is invalid
205
205
  """
206
206
  try:
207
- config = self.load()
208
- config_dict = config.model_dump()
207
+ resource = self.load()
208
+ resource_dict = resource.model_dump()
209
209
 
210
210
  if "." in key:
211
- self._set_dot_notation_key(config_dict, key, value)
211
+ self._set_dot_notation_key(resource_dict, key, value)
212
212
  else:
213
- config_dict[key] = value
213
+ resource_dict[key] = value
214
214
 
215
- updated_config = config.model_validate(config_dict)
216
- self.save(updated_config)
215
+ updated_resource = resource.model_validate(resource_dict)
216
+ self.save(updated_resource)
217
217
  except ValidationError as e:
218
218
  raise ValueError(
219
219
  f"Invalid value set for '{self.__class__.__name__}' with "
@@ -226,31 +226,31 @@ class MutablePydanticResourceManager(PydanticResourceManager[MutablePydanticReso
226
226
  ) from e
227
227
 
228
228
  def update(self: Self, updates: dict[str, Any]) -> MutablePydanticResource:
229
- """Updates multiple configuration values at once.
229
+ """Updates multiple resource values at once.
230
230
 
231
231
  Args:
232
232
  updates: Dictionary of key-value pairs to update
233
233
 
234
234
  Returns:
235
- The updated Config object
235
+ The updated Resource object
236
236
 
237
237
  Raises:
238
- FileNotFoundError: If config file doesn't exist
239
- ValueError: If the updates config is invalid
238
+ FileNotFoundError: If resource file doesn't exist
239
+ ValueError: If the updates resource is invalid
240
240
  """
241
241
  try:
242
- config = self.load()
243
- config_dict = config.model_dump()
242
+ resource = self.load()
243
+ resource_dict = resource.model_dump()
244
244
 
245
245
  flat_updates = {k: v for k, v in updates.items() if "." not in k}
246
- config_dict.update(flat_updates)
246
+ resource_dict.update(flat_updates)
247
247
 
248
248
  for key, value in updates.items():
249
249
  if "." in key:
250
- self._set_dot_notation_key(config_dict, key, value)
250
+ self._set_dot_notation_key(resource_dict, key, value)
251
251
 
252
- updated_config = config.model_validate(config_dict)
253
- self.save(updated_config)
252
+ updated_resource = resource.model_validate(resource_dict)
253
+ self.save(updated_resource)
254
254
  except ValidationError as e:
255
255
  raise ValueError(
256
256
  f"Invalid value set for '{self.__class__.__name__}' with "
@@ -262,14 +262,14 @@ class MutablePydanticResourceManager(PydanticResourceManager[MutablePydanticReso
262
262
  f"at: '{self.path}' when setting updates {updates}"
263
263
  ) from e
264
264
 
265
- return updated_config
265
+ return updated_resource
266
266
 
267
267
  def reset(self: Self) -> MutablePydanticResource:
268
- """Resets the configuration to defaults.
268
+ """Resets the resources to defaults.
269
269
 
270
270
  Returns:
271
- The new default config object
271
+ The new default resource object
272
272
  """
273
- config = self.model_class.reset()
274
- self.save(config)
275
- return config
273
+ resource = self.model_class.reset()
274
+ self.save(resource)
275
+ return resource
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.5.0'
32
- __version_tuple__ = version_tuple = (0, 5, 0)
31
+ __version__ = version = '0.5.2'
32
+ __version_tuple__ = version_tuple = (0, 5, 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.5.0
3
+ Version: 0.5.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
@@ -1,24 +1,24 @@
1
1
  fmu/__init__.py,sha256=htx6HlMme77I6pZ8U256-2B2cMJuELsu3JN3YM2Efh4,144
2
2
  fmu/settings/__init__.py,sha256=CkEE7al_uBCQO1lxBKN5LzyCwzzH5Aq6kkEIR7f-zTw,336
3
3
  fmu/settings/_fmu_dir.py,sha256=XeZjec78q0IUOpBq-VMkKoWtzXwBeQi2qWRIh_SIFwU,10859
4
- fmu/settings/_global_config.py,sha256=tYSQH_48cknaEeo8C_uraEaPXZrrN7cHYZOCX9G39yM,8916
4
+ fmu/settings/_global_config.py,sha256=C0_o99OhOc49ynz4h6ygbbHHH8OOI5lcVFr-9FCwD0c,9331
5
5
  fmu/settings/_init.py,sha256=ucueS0BlEsM3MkX7IaRISloH4vF7-_ZKSphrORbHgJ4,4381
6
6
  fmu/settings/_logging.py,sha256=nEdmZlNCBsB1GfDmFMKCjZmeuRp3CRlbz1EYUemc95Y,1104
7
- fmu/settings/_version.py,sha256=fvHpBU3KZKRinkriKdtAt3crenOyysELF-M9y3ozg3U,704
7
+ fmu/settings/_version.py,sha256=LGYtjQ6cyPZC_N0AovMIeSYYDK21050nm3HYgDanQBM,704
8
8
  fmu/settings/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  fmu/settings/types.py,sha256=aeXEsznBTT1YRRY_LSRqK1j2gmMmyLYYTGYl3a9fweU,513
10
10
  fmu/settings/_resources/__init__.py,sha256=LHYR_F7lNGdv8N6R3cEwds5CJQpkOthXFqsEs24vgF8,118
11
11
  fmu/settings/_resources/config_managers.py,sha256=QcCLlSw8KdJKrkhGax5teFJzjgQG3ym7Ljs1DykjFbc,1570
12
- fmu/settings/_resources/lock_manager.py,sha256=zdv1BZJlgB1BO9NepAdjY-YZ1-57HEJcTApE4UVS-8M,9995
13
- fmu/settings/_resources/pydantic_resource_manager.py,sha256=AVvBUPnYOzmFYo9k5cA9QUme6ZOu0Q3IoLx_le7Mq20,9264
12
+ fmu/settings/_resources/lock_manager.py,sha256=ekGE5mTcjEWRyoBSIeqaX1r53-WStpYeJYepkOPYi3Q,10061
13
+ fmu/settings/_resources/pydantic_resource_manager.py,sha256=BUWO6IHSoT0Ma6QgseweEf7uiGeMwHBEoCyGYPYYFdA,9290
14
14
  fmu/settings/models/__init__.py,sha256=lRlXgl55ba2upmDzdvzx8N30JMq2Osnm8aa_xxTZn8A,112
15
15
  fmu/settings/models/_enums.py,sha256=SQUZ-2mQcTx4F0oefPFfuQzMKsKTSFSB-wq_CH7TBRE,734
16
16
  fmu/settings/models/_mappings.py,sha256=Z4Ex7MtmajBr6FjaNzmwDRwtJlaZZ8YKh9NDmZHRKPI,2832
17
17
  fmu/settings/models/lock_info.py,sha256=-oHDF9v9bDLCoFvEg4S6XXYLeo19zRAZ8HynCv75VWg,711
18
18
  fmu/settings/models/project_config.py,sha256=pxb54JmpXNMVAFUu_yJ89dNrYEk6hrPuFfFUpf84Jh0,1099
19
19
  fmu/settings/models/user_config.py,sha256=dWFTcZY6UnEgNTuGqB-izraJ657PecsW0e0Nt9GBDhI,2666
20
- fmu_settings-0.5.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
21
- fmu_settings-0.5.0.dist-info/METADATA,sha256=5Ff9Xfr_KsWUptwWt4HlKIkfnmME7D2UqclD-qzgrSo,2116
22
- fmu_settings-0.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- fmu_settings-0.5.0.dist-info/top_level.txt,sha256=Z-FIY3pxn0UK2Wxi9IJ7fKoLSraaxuNGi1eokiE0ShM,4
24
- fmu_settings-0.5.0.dist-info/RECORD,,
20
+ fmu_settings-0.5.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
21
+ fmu_settings-0.5.2.dist-info/METADATA,sha256=dxi2pe4SgYJwTY6beiEPoLx7lEqjzZWq9UcpX3gir_s,2116
22
+ fmu_settings-0.5.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ fmu_settings-0.5.2.dist-info/top_level.txt,sha256=Z-FIY3pxn0UK2Wxi9IJ7fKoLSraaxuNGi1eokiE0ShM,4
24
+ fmu_settings-0.5.2.dist-info/RECORD,,