fmu-settings 0.3.1__tar.gz → 0.3.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.

Potentially problematic release.


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

Files changed (43) hide show
  1. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/PKG-INFO +1 -1
  2. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_resources/pydantic_resource_manager.py +11 -4
  3. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_version.py +3 -3
  4. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu_settings.egg-info/PKG-INFO +1 -1
  5. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_resources/test_resource_managers.py +56 -0
  6. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.coveragerc +0 -0
  7. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.github/pull_request_template.md +0 -0
  8. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.github/workflows/ci.yml +0 -0
  9. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.github/workflows/codeql.yml +0 -0
  10. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.github/workflows/publish.yml +0 -0
  11. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.gitignore +0 -0
  12. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/CONTRIBUTING.md +0 -0
  13. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/LICENSE +0 -0
  14. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/README.md +0 -0
  15. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/SECURITY.md +0 -0
  16. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/pyproject.toml +0 -0
  17. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/setup.cfg +0 -0
  18. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/__init__.py +0 -0
  19. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/__init__.py +0 -0
  20. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_fmu_dir.py +0 -0
  21. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_init.py +0 -0
  22. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_logging.py +0 -0
  23. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_resources/__init__.py +0 -0
  24. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_resources/config_managers.py +0 -0
  25. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_resources/lock_manager.py +0 -0
  26. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/__init__.py +0 -0
  27. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/_enums.py +0 -0
  28. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/_mappings.py +0 -0
  29. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/lock_info.py +0 -0
  30. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/project_config.py +0 -0
  31. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/user_config.py +0 -0
  32. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/py.typed +0 -0
  33. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/types.py +0 -0
  34. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu_settings.egg-info/SOURCES.txt +0 -0
  35. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu_settings.egg-info/dependency_links.txt +0 -0
  36. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu_settings.egg-info/requires.txt +0 -0
  37. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu_settings.egg-info/top_level.txt +0 -0
  38. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/conftest.py +0 -0
  39. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_fmu_dir.py +0 -0
  40. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_init.py +0 -0
  41. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_resources/test_lock_manager.py +0 -0
  42. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_resources/test_project_config.py +0 -0
  43. {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_resources/test_user_config.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fmu-settings
3
- Version: 0.3.1
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
@@ -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__}: "
@@ -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.1'
32
- __version_tuple__ = version_tuple = (0, 3, 1)
31
+ __version__ = version = '0.3.2'
32
+ __version_tuple__ = version_tuple = (0, 3, 2)
33
33
 
34
- __commit_id__ = commit_id = 'g7197724f6'
34
+ __commit_id__ = commit_id = 'g9ea88b68f'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fmu-settings
3
- Version: 0.3.1
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
@@ -87,6 +87,62 @@ def test_pydantic_resource_manager_load(fmu_dir: ProjectFMUDirectory) -> None:
87
87
  assert a._cache == a_model
88
88
 
89
89
 
90
+ def test_pydantic_resource_manager_load_force_true(
91
+ fmu_dir: ProjectFMUDirectory,
92
+ ) -> None:
93
+ """Tests loading a Pydantic resource with force=True."""
94
+ a = AManager(fmu_dir)
95
+ a_model = A(foo="bar")
96
+ a.save(a_model)
97
+ assert a.load() == a_model
98
+ assert a._cache == a_model
99
+
100
+ a_shadow = AManager(fmu_dir)
101
+ a_shadow_model = A(foo="baz")
102
+ a_shadow.save(a_shadow_model)
103
+
104
+ assert a_shadow.load() == a_shadow_model
105
+ assert a_shadow._cache == a_shadow_model
106
+
107
+ assert a.load() == a_model
108
+ assert a._cache == a_model
109
+
110
+ assert a.load(force=True) == a_shadow_model
111
+ assert a._cache == a_shadow_model
112
+
113
+
114
+ def test_pydantic_resource_manager_load_cache_false(
115
+ fmu_dir: ProjectFMUDirectory,
116
+ ) -> None:
117
+ """Tests loading a Pydantic resource with cache=False."""
118
+ a = AManager(fmu_dir)
119
+ a_model = A(foo="bar")
120
+ a.save(a_model)
121
+
122
+ a_shadow = AManager(fmu_dir)
123
+ assert a_shadow.load(store_cache=False) == a_model
124
+ assert a_shadow._cache is None
125
+
126
+ assert a_shadow.load(store_cache=True) == a_model
127
+ assert a_shadow._cache == a_model
128
+
129
+
130
+ def test_pydantic_resource_manager_load_force_true_cache_false(
131
+ fmu_dir: ProjectFMUDirectory,
132
+ ) -> None:
133
+ """Tests loading a Pydantic resource with force=True, cache=False."""
134
+ a = AManager(fmu_dir)
135
+ a_model = A(foo="bar")
136
+ a.save(a_model)
137
+
138
+ a_shadow = AManager(fmu_dir)
139
+ a_shadow_model = A(foo="baz")
140
+ a_shadow.save(a_shadow_model)
141
+
142
+ assert a.load(force=True, store_cache=False) == a_shadow_model
143
+ assert a._cache is a_model
144
+
145
+
90
146
  def test_pydantic_resource_manager_loads_invalid_model(
91
147
  fmu_dir: ProjectFMUDirectory,
92
148
  ) -> None:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes