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.
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/PKG-INFO +1 -1
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_resources/pydantic_resource_manager.py +11 -4
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_version.py +3 -3
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu_settings.egg-info/PKG-INFO +1 -1
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_resources/test_resource_managers.py +56 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.coveragerc +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.github/pull_request_template.md +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.github/workflows/ci.yml +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.github/workflows/codeql.yml +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.github/workflows/publish.yml +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/.gitignore +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/CONTRIBUTING.md +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/LICENSE +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/README.md +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/SECURITY.md +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/pyproject.toml +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/setup.cfg +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/__init__.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/__init__.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_fmu_dir.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_init.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_logging.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_resources/__init__.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_resources/config_managers.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_resources/lock_manager.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/__init__.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/_enums.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/_mappings.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/lock_info.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/project_config.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/models/user_config.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/py.typed +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/types.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu_settings.egg-info/SOURCES.txt +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu_settings.egg-info/dependency_links.txt +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu_settings.egg-info/requires.txt +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu_settings.egg-info/top_level.txt +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/conftest.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_fmu_dir.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_init.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_resources/test_lock_manager.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_resources/test_project_config.py +0 -0
- {fmu_settings-0.3.1 → fmu_settings-0.3.2}/tests/test_resources/test_user_config.py +0 -0
{fmu_settings-0.3.1 → fmu_settings-0.3.2}/src/fmu/settings/_resources/pydantic_resource_manager.py
RENAMED
|
@@ -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
|
|
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
|
-
|
|
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.
|
|
32
|
-
__version_tuple__ = version_tuple = (0, 3,
|
|
31
|
+
__version__ = version = '0.3.2'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 3, 2)
|
|
33
33
|
|
|
34
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'g9ea88b68f'
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|