fmu-settings 0.0.1__tar.gz → 0.2.0__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.0.1 → fmu_settings-0.2.0}/PKG-INFO +2 -2
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/pyproject.toml +1 -1
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/_fmu_dir.py +3 -3
- fmu_settings-0.2.0/src/fmu/settings/_resources/__init__.py +5 -0
- {fmu_settings-0.0.1/src/fmu/settings/resources → fmu_settings-0.2.0/src/fmu/settings/_resources}/config_managers.py +2 -2
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/_version.py +16 -3
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/models/_mappings.py +1 -1
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/models/project_config.py +8 -16
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/models/user_config.py +18 -4
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu_settings.egg-info/PKG-INFO +2 -2
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu_settings.egg-info/SOURCES.txt +3 -3
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu_settings.egg-info/requires.txt +1 -1
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/tests/conftest.py +27 -5
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/tests/test_fmu_dir.py +17 -6
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/tests/test_init.py +1 -1
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/tests/test_resources/test_project_config.py +80 -5
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/tests/test_resources/test_resource_managers.py +1 -1
- fmu_settings-0.0.1/src/fmu/settings/models/smda.py +0 -90
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/.coveragerc +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/.github/pull_request_template.md +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/.github/workflows/ci.yml +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/.github/workflows/codeql.yml +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/.github/workflows/publish.yml +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/.gitignore +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/CONTRIBUTING.md +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/LICENSE +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/README.md +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/SECURITY.md +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/setup.cfg +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/__init__.py +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/__init__.py +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/_init.py +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/_logging.py +0 -0
- /fmu_settings-0.0.1/src/fmu/settings/resources/managers.py → /fmu_settings-0.2.0/src/fmu/settings/_resources/pydantic_resource_manager.py +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/models/__init__.py +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/models/_enums.py +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/py.typed +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu/settings/types.py +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu_settings.egg-info/dependency_links.txt +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/src/fmu_settings.egg-info/top_level.txt +0 -0
- {fmu_settings-0.0.1 → fmu_settings-0.2.0}/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.0
|
|
3
|
+
Version: 0.2.0
|
|
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
|
|
@@ -18,7 +18,7 @@ Requires-Python: >=3.11
|
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
License-File: LICENSE
|
|
20
20
|
Requires-Dist: annotated_types
|
|
21
|
-
Requires-Dist: fmu-
|
|
21
|
+
Requires-Dist: fmu-datamodels
|
|
22
22
|
Requires-Dist: pydantic
|
|
23
23
|
Provides-Extra: dev
|
|
24
24
|
Requires-Dist: mypy; extra == "dev"
|
|
@@ -4,12 +4,12 @@ from pathlib import Path
|
|
|
4
4
|
from typing import Any, Final, Self, TypeAlias, cast
|
|
5
5
|
|
|
6
6
|
from ._logging import null_logger
|
|
7
|
-
from .
|
|
8
|
-
from .models.user_config import UserConfig
|
|
9
|
-
from .resources.config_managers import (
|
|
7
|
+
from ._resources.config_managers import (
|
|
10
8
|
ProjectConfigManager,
|
|
11
9
|
UserConfigManager,
|
|
12
10
|
)
|
|
11
|
+
from .models.project_config import ProjectConfig
|
|
12
|
+
from .models.user_config import UserConfig
|
|
13
13
|
|
|
14
14
|
logger: Final = null_logger(__name__)
|
|
15
15
|
|
|
@@ -13,7 +13,7 @@ from fmu.settings.models.project_config import ProjectConfig
|
|
|
13
13
|
from fmu.settings.models.user_config import UserConfig
|
|
14
14
|
from fmu.settings.types import ResettableBaseModel, VersionStr # noqa TC001
|
|
15
15
|
|
|
16
|
-
from .
|
|
16
|
+
from .pydantic_resource_manager import PydanticResourceManager
|
|
17
17
|
|
|
18
18
|
if TYPE_CHECKING:
|
|
19
19
|
# Avoid circular dependency for type hint in __init__ only
|
|
@@ -73,7 +73,7 @@ class ConfigManager(PydanticResourceManager[T]):
|
|
|
73
73
|
default: Value to return if key is not found. Default None
|
|
74
74
|
|
|
75
75
|
Returns:
|
|
76
|
-
The configuration value or
|
|
76
|
+
The configuration value or default
|
|
77
77
|
"""
|
|
78
78
|
try:
|
|
79
79
|
config = self.load()
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# file generated by setuptools-scm
|
|
2
2
|
# don't change, don't track in version control
|
|
3
3
|
|
|
4
|
-
__all__ = [
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
5
12
|
|
|
6
13
|
TYPE_CHECKING = False
|
|
7
14
|
if TYPE_CHECKING:
|
|
@@ -9,13 +16,19 @@ if TYPE_CHECKING:
|
|
|
9
16
|
from typing import Union
|
|
10
17
|
|
|
11
18
|
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
12
20
|
else:
|
|
13
21
|
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
14
23
|
|
|
15
24
|
version: str
|
|
16
25
|
__version__: str
|
|
17
26
|
__version_tuple__: VERSION_TUPLE
|
|
18
27
|
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
19
30
|
|
|
20
|
-
__version__ = version = '0.0
|
|
21
|
-
__version_tuple__ = version_tuple = (0,
|
|
31
|
+
__version__ = version = '0.2.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 2, 0)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = 'g944134f32'
|
|
@@ -3,25 +3,13 @@
|
|
|
3
3
|
import getpass
|
|
4
4
|
from datetime import UTC, datetime
|
|
5
5
|
from typing import Self
|
|
6
|
-
from uuid import UUID # noqa TC003
|
|
7
6
|
|
|
8
|
-
from pydantic import AwareDatetime,
|
|
7
|
+
from pydantic import AwareDatetime, Field
|
|
9
8
|
|
|
9
|
+
from fmu.datamodels.fmu_results.fields import Access, Masterdata, Model
|
|
10
10
|
from fmu.settings import __version__
|
|
11
11
|
from fmu.settings.types import ResettableBaseModel, VersionStr # noqa TC001
|
|
12
12
|
|
|
13
|
-
from .smda import Smda
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class Masterdata(BaseModel):
|
|
17
|
-
"""The ``masterdata`` block contains information related to masterdata.
|
|
18
|
-
|
|
19
|
-
Currently, SMDA holds the masterdata.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
smda: Smda | None = Field(default=None)
|
|
23
|
-
"""Block containing SMDA-related attributes. See :class:`Smda`."""
|
|
24
|
-
|
|
25
13
|
|
|
26
14
|
class ProjectConfig(ResettableBaseModel):
|
|
27
15
|
"""The configuration file in a .fmu directory.
|
|
@@ -32,7 +20,9 @@ class ProjectConfig(ResettableBaseModel):
|
|
|
32
20
|
version: VersionStr
|
|
33
21
|
created_at: AwareDatetime
|
|
34
22
|
created_by: str
|
|
35
|
-
masterdata: Masterdata
|
|
23
|
+
masterdata: Masterdata | None = Field(default=None)
|
|
24
|
+
model: Model | None = Field(default=None)
|
|
25
|
+
access: Access | None = Field(default=None)
|
|
36
26
|
|
|
37
27
|
@classmethod
|
|
38
28
|
def reset(cls: type[Self]) -> Self:
|
|
@@ -45,5 +35,7 @@ class ProjectConfig(ResettableBaseModel):
|
|
|
45
35
|
version=__version__,
|
|
46
36
|
created_at=datetime.now(UTC),
|
|
47
37
|
created_by=getpass.getuser(),
|
|
48
|
-
masterdata=
|
|
38
|
+
masterdata=None,
|
|
39
|
+
model=None,
|
|
40
|
+
access=None,
|
|
49
41
|
)
|
|
@@ -8,12 +8,18 @@ from typing import Annotated, Self
|
|
|
8
8
|
from uuid import UUID # noqa TC003
|
|
9
9
|
|
|
10
10
|
import annotated_types
|
|
11
|
-
from pydantic import
|
|
11
|
+
from pydantic import (
|
|
12
|
+
AwareDatetime,
|
|
13
|
+
BaseModel,
|
|
14
|
+
SecretStr,
|
|
15
|
+
field_serializer,
|
|
16
|
+
field_validator,
|
|
17
|
+
)
|
|
12
18
|
|
|
13
19
|
from fmu.settings import __version__
|
|
14
20
|
from fmu.settings.types import ResettableBaseModel, VersionStr # noqa TC001
|
|
15
21
|
|
|
16
|
-
|
|
22
|
+
RecentProjectDirectories = Annotated[list[Path], annotated_types.Len(0, 5)]
|
|
17
23
|
|
|
18
24
|
|
|
19
25
|
class UserAPIKeys(BaseModel):
|
|
@@ -38,7 +44,7 @@ class UserConfig(ResettableBaseModel):
|
|
|
38
44
|
version: VersionStr
|
|
39
45
|
created_at: AwareDatetime
|
|
40
46
|
user_api_keys: UserAPIKeys
|
|
41
|
-
|
|
47
|
+
recent_project_directories: RecentProjectDirectories
|
|
42
48
|
|
|
43
49
|
@classmethod
|
|
44
50
|
def reset(cls: type[Self]) -> Self:
|
|
@@ -47,9 +53,17 @@ class UserConfig(ResettableBaseModel):
|
|
|
47
53
|
version=__version__,
|
|
48
54
|
created_at=datetime.now(UTC),
|
|
49
55
|
user_api_keys=UserAPIKeys(),
|
|
50
|
-
|
|
56
|
+
recent_project_directories=[],
|
|
51
57
|
)
|
|
52
58
|
|
|
59
|
+
@field_validator("recent_project_directories", mode="before")
|
|
60
|
+
@classmethod
|
|
61
|
+
def ensure_unique(cls, recent_projects: list[Path]) -> list[Path]:
|
|
62
|
+
"""Ensures that recent_project_directories contains unique entries."""
|
|
63
|
+
if len(recent_projects) != len(set(recent_projects)):
|
|
64
|
+
raise ValueError("recent_project_directories must contain unique entries")
|
|
65
|
+
return recent_projects
|
|
66
|
+
|
|
53
67
|
def obfuscate_secrets(self: Self) -> Self:
|
|
54
68
|
"""Returns a copy of the model with obfuscated secrets.
|
|
55
69
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fmu-settings
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 0.2.0
|
|
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
|
|
@@ -18,7 +18,7 @@ Requires-Python: >=3.11
|
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
License-File: LICENSE
|
|
20
20
|
Requires-Dist: annotated_types
|
|
21
|
-
Requires-Dist: fmu-
|
|
21
|
+
Requires-Dist: fmu-datamodels
|
|
22
22
|
Requires-Dist: pydantic
|
|
23
23
|
Provides-Extra: dev
|
|
24
24
|
Requires-Dist: mypy; extra == "dev"
|
|
@@ -17,14 +17,14 @@ src/fmu/settings/_logging.py
|
|
|
17
17
|
src/fmu/settings/_version.py
|
|
18
18
|
src/fmu/settings/py.typed
|
|
19
19
|
src/fmu/settings/types.py
|
|
20
|
+
src/fmu/settings/_resources/__init__.py
|
|
21
|
+
src/fmu/settings/_resources/config_managers.py
|
|
22
|
+
src/fmu/settings/_resources/pydantic_resource_manager.py
|
|
20
23
|
src/fmu/settings/models/__init__.py
|
|
21
24
|
src/fmu/settings/models/_enums.py
|
|
22
25
|
src/fmu/settings/models/_mappings.py
|
|
23
26
|
src/fmu/settings/models/project_config.py
|
|
24
|
-
src/fmu/settings/models/smda.py
|
|
25
27
|
src/fmu/settings/models/user_config.py
|
|
26
|
-
src/fmu/settings/resources/config_managers.py
|
|
27
|
-
src/fmu/settings/resources/managers.py
|
|
28
28
|
src/fmu_settings.egg-info/PKG-INFO
|
|
29
29
|
src/fmu_settings.egg-info/SOURCES.txt
|
|
30
30
|
src/fmu_settings.egg-info/dependency_links.txt
|
|
@@ -27,9 +27,9 @@ def config_dict(unix_epoch_utc: datetime) -> dict[str, Any]:
|
|
|
27
27
|
"version": __version__,
|
|
28
28
|
"created_at": unix_epoch_utc,
|
|
29
29
|
"created_by": "user",
|
|
30
|
-
"masterdata":
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
"masterdata": None,
|
|
31
|
+
"model": None,
|
|
32
|
+
"access": None,
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
|
|
@@ -68,9 +68,30 @@ def masterdata_dict() -> dict[str, Any]:
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
|
|
71
|
+
@pytest.fixture
|
|
72
|
+
def model_dict() -> dict[str, Any]:
|
|
73
|
+
"""Example model information."""
|
|
74
|
+
return {
|
|
75
|
+
"name": "Drogon",
|
|
76
|
+
"revision": "21.0.0",
|
|
77
|
+
"description": None,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@pytest.fixture
|
|
82
|
+
def access_dict() -> dict[str, Any]:
|
|
83
|
+
"""Example access information."""
|
|
84
|
+
return {
|
|
85
|
+
"asset": {"name": "Drogon"},
|
|
86
|
+
"classification": "internal",
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
71
90
|
@pytest.fixture
|
|
72
91
|
def config_dict_with_masterdata(
|
|
73
|
-
unix_epoch_utc: datetime,
|
|
92
|
+
unix_epoch_utc: datetime,
|
|
93
|
+
masterdata_dict: dict[str, Any],
|
|
94
|
+
model_dict: dict[str, Any],
|
|
74
95
|
) -> dict[str, Any]:
|
|
75
96
|
"""A dictionary representing a .fmu config."""
|
|
76
97
|
return {
|
|
@@ -78,6 +99,7 @@ def config_dict_with_masterdata(
|
|
|
78
99
|
"created_at": unix_epoch_utc,
|
|
79
100
|
"created_by": "user",
|
|
80
101
|
"masterdata": masterdata_dict,
|
|
102
|
+
"model": model_dict,
|
|
81
103
|
}
|
|
82
104
|
|
|
83
105
|
|
|
@@ -104,7 +126,7 @@ def user_config_dict(unix_epoch_utc: datetime) -> dict[str, Any]:
|
|
|
104
126
|
"user_api_keys": {
|
|
105
127
|
"smda_subscription": None,
|
|
106
128
|
},
|
|
107
|
-
"
|
|
129
|
+
"recent_project_directories": [],
|
|
108
130
|
}
|
|
109
131
|
|
|
110
132
|
|
|
@@ -288,30 +288,41 @@ def test_update_user_config(user_fmu_dir: UserFMUDirectory) -> None:
|
|
|
288
288
|
"""Tests update_config updates and saves the user config for multiple values."""
|
|
289
289
|
recent_dir = "/foo/bar"
|
|
290
290
|
updated_config = user_fmu_dir.update_config(
|
|
291
|
-
{"version": "2.0.0", "
|
|
291
|
+
{"version": "2.0.0", "recent_project_directories": [recent_dir]}
|
|
292
292
|
)
|
|
293
293
|
|
|
294
294
|
assert updated_config.version == "2.0.0"
|
|
295
|
-
assert updated_config.
|
|
295
|
+
assert updated_config.recent_project_directories == [Path(recent_dir)]
|
|
296
296
|
|
|
297
297
|
assert user_fmu_dir.config.load() is not None
|
|
298
298
|
assert user_fmu_dir.get_config_value("version", None) == "2.0.0"
|
|
299
|
-
assert user_fmu_dir.get_config_value("
|
|
299
|
+
assert user_fmu_dir.get_config_value("recent_project_directories") == [
|
|
300
|
+
Path(recent_dir)
|
|
301
|
+
]
|
|
300
302
|
|
|
301
303
|
config_file = user_fmu_dir.config.path
|
|
302
304
|
with open(config_file, encoding="utf-8") as f:
|
|
303
305
|
saved_config = json.load(f)
|
|
304
306
|
|
|
305
307
|
assert saved_config["version"] == "2.0.0"
|
|
306
|
-
assert saved_config["
|
|
308
|
+
assert saved_config["recent_project_directories"] == [recent_dir]
|
|
307
309
|
|
|
308
310
|
|
|
309
311
|
def test_update_user_config_invalid_data(user_fmu_dir: UserFMUDirectory) -> None:
|
|
310
312
|
"""Tests that update_config raises ValidationError on bad data."""
|
|
311
|
-
updates = {"
|
|
313
|
+
updates = {"recent_project_directories": [123]}
|
|
312
314
|
with pytest.raises(
|
|
313
315
|
ValueError,
|
|
314
316
|
match="Invalid value set for 'UserConfigManager' with updates "
|
|
315
|
-
"'{'
|
|
317
|
+
"'{'recent_project_directories':",
|
|
316
318
|
):
|
|
317
319
|
user_fmu_dir.update_config(updates)
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def test_update_user_config_non_unique_recent_projects(
|
|
323
|
+
user_fmu_dir: UserFMUDirectory,
|
|
324
|
+
) -> None:
|
|
325
|
+
"""Tests that update_config raises on non-unique recent_project_directories."""
|
|
326
|
+
updates = {"recent_project_directories": [Path("/foo/bar"), Path("/foo/bar")]}
|
|
327
|
+
with pytest.raises(ValueError, match="unique entries"):
|
|
328
|
+
user_fmu_dir.update_config(updates)
|
|
@@ -134,7 +134,7 @@ def test_init_user_fmu_directory(
|
|
|
134
134
|
assert config_json["version"] == __version__
|
|
135
135
|
assert config_json["created_at"] != str(unix_epoch_utc)
|
|
136
136
|
assert config_json["user_api_keys"] == {"smda_subscription": None}
|
|
137
|
-
assert config_json["
|
|
137
|
+
assert config_json["recent_project_directories"] == []
|
|
138
138
|
|
|
139
139
|
created_at = datetime.fromisoformat(config_json["created_at"])
|
|
140
140
|
now = datetime.now(UTC)
|
|
@@ -7,14 +7,14 @@ from typing import Any
|
|
|
7
7
|
|
|
8
8
|
import pytest
|
|
9
9
|
|
|
10
|
+
from fmu.datamodels.fmu_results.fields import Access, Model, Smda
|
|
10
11
|
from fmu.settings._fmu_dir import ProjectFMUDirectory, UserFMUDirectory
|
|
11
|
-
from fmu.settings.
|
|
12
|
-
from fmu.settings.models.smda import Smda
|
|
13
|
-
from fmu.settings.models.user_config import UserConfig
|
|
14
|
-
from fmu.settings.resources.config_managers import (
|
|
12
|
+
from fmu.settings._resources.config_managers import (
|
|
15
13
|
ProjectConfigManager,
|
|
16
14
|
UserConfigManager,
|
|
17
15
|
)
|
|
16
|
+
from fmu.settings.models.project_config import ProjectConfig
|
|
17
|
+
from fmu.settings.models.user_config import UserConfig
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
@pytest.fixture
|
|
@@ -238,7 +238,7 @@ def test_set_smda(
|
|
|
238
238
|
assert fmu_dir.config.get("masterdata.smda") is None
|
|
239
239
|
with open(fmu_dir.path / fmu_dir.config.relative_path, encoding="utf-8") as f:
|
|
240
240
|
config_on_disk = json.loads(f.read())
|
|
241
|
-
assert config_on_disk["masterdata"]
|
|
241
|
+
assert config_on_disk["masterdata"] is None
|
|
242
242
|
|
|
243
243
|
fmu_dir.set_config_value("masterdata", masterdata_dict)
|
|
244
244
|
|
|
@@ -250,10 +250,85 @@ def test_set_smda(
|
|
|
250
250
|
|
|
251
251
|
config_on_disk_model = ProjectConfig.model_validate(config_on_disk)
|
|
252
252
|
assert fmu_dir.config._cache is not None
|
|
253
|
+
assert fmu_dir.config._cache.masterdata is not None
|
|
253
254
|
assert fmu_dir.config._cache.masterdata.smda == smda_model
|
|
254
255
|
assert config_on_disk_model == fmu_dir.config._cache
|
|
255
256
|
|
|
256
257
|
|
|
258
|
+
def test_set_model_invalid_fails(
|
|
259
|
+
fmu_dir: ProjectFMUDirectory, model_dict: dict[str, Any]
|
|
260
|
+
) -> None:
|
|
261
|
+
"""Tests setting the model value in the config using an invalid dictionary."""
|
|
262
|
+
assert fmu_dir.config.get("model") is None
|
|
263
|
+
|
|
264
|
+
# drop model.name to test validation
|
|
265
|
+
model_dict.pop("name")
|
|
266
|
+
|
|
267
|
+
with pytest.raises(ValueError, match="model.name"):
|
|
268
|
+
fmu_dir.set_config_value("model", model_dict)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def test_set_model(fmu_dir: ProjectFMUDirectory, model_dict: dict[str, Any]) -> None:
|
|
272
|
+
"""Tests setting the model value in the config."""
|
|
273
|
+
assert fmu_dir.config.get("model") is None
|
|
274
|
+
with open(fmu_dir.path / fmu_dir.config.relative_path, encoding="utf-8") as f:
|
|
275
|
+
config_on_disk = json.loads(f.read())
|
|
276
|
+
assert config_on_disk["model"] is None
|
|
277
|
+
|
|
278
|
+
fmu_dir.set_config_value("model", model_dict)
|
|
279
|
+
|
|
280
|
+
model = Model.model_validate(model_dict)
|
|
281
|
+
|
|
282
|
+
assert fmu_dir.get_config_value("model") == model
|
|
283
|
+
assert fmu_dir.get_config_value("model.revision") == "21.0.0"
|
|
284
|
+
assert fmu_dir.get_config_value("model.name") == "Drogon"
|
|
285
|
+
|
|
286
|
+
with open(fmu_dir.path / fmu_dir.config.relative_path, encoding="utf-8") as f:
|
|
287
|
+
config_on_disk = json.loads(f.read())
|
|
288
|
+
|
|
289
|
+
config_on_disk_model = ProjectConfig.model_validate(config_on_disk)
|
|
290
|
+
assert fmu_dir.config._cache is not None
|
|
291
|
+
assert fmu_dir.config._cache.model == model
|
|
292
|
+
assert config_on_disk_model == fmu_dir.config._cache
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def test_set_access_invalid_fails(
|
|
296
|
+
fmu_dir: ProjectFMUDirectory, access_dict: dict[str, Any]
|
|
297
|
+
) -> None:
|
|
298
|
+
"""Tests setting the access value in the config using an invalid dictionary."""
|
|
299
|
+
assert fmu_dir.config.get("access") is None
|
|
300
|
+
|
|
301
|
+
# drop access.asset to test validation
|
|
302
|
+
access_dict.pop("asset")
|
|
303
|
+
|
|
304
|
+
with pytest.raises(ValueError, match="access.asset"):
|
|
305
|
+
fmu_dir.set_config_value("access", access_dict)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def test_set_access(fmu_dir: ProjectFMUDirectory, access_dict: dict[str, Any]) -> None:
|
|
309
|
+
"""Tests setting the access value in the config."""
|
|
310
|
+
assert fmu_dir.config.get("access") is None
|
|
311
|
+
with open(fmu_dir.path / fmu_dir.config.relative_path, encoding="utf-8") as f:
|
|
312
|
+
config_on_disk = json.loads(f.read())
|
|
313
|
+
assert config_on_disk["access"] is None
|
|
314
|
+
|
|
315
|
+
fmu_dir.set_config_value("access", access_dict)
|
|
316
|
+
|
|
317
|
+
access = Access.model_validate(access_dict)
|
|
318
|
+
|
|
319
|
+
assert fmu_dir.get_config_value("access") == access
|
|
320
|
+
assert fmu_dir.get_config_value("access.classification") == "internal"
|
|
321
|
+
assert fmu_dir.get_config_value("access.asset.name") == "Drogon"
|
|
322
|
+
|
|
323
|
+
with open(fmu_dir.path / fmu_dir.config.relative_path, encoding="utf-8") as f:
|
|
324
|
+
config_on_disk = json.loads(f.read())
|
|
325
|
+
|
|
326
|
+
config_on_disk_model = ProjectConfig.model_validate(config_on_disk)
|
|
327
|
+
assert fmu_dir.config._cache is not None
|
|
328
|
+
assert fmu_dir.config._cache.access == access
|
|
329
|
+
assert config_on_disk_model == fmu_dir.config._cache
|
|
330
|
+
|
|
331
|
+
|
|
257
332
|
def test_update_config_when_it_does_not_exist(tmp_path: Path) -> None:
|
|
258
333
|
"""Tests getting a key when the config is missing."""
|
|
259
334
|
empty_fmu_dir = tmp_path / ".fmu"
|
|
@@ -8,7 +8,7 @@ import pytest
|
|
|
8
8
|
from pydantic import BaseModel
|
|
9
9
|
|
|
10
10
|
from fmu.settings._fmu_dir import ProjectFMUDirectory
|
|
11
|
-
from fmu.settings.
|
|
11
|
+
from fmu.settings._resources.pydantic_resource_manager import PydanticResourceManager
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class A(BaseModel):
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"""Models for SMDA masterdata."""
|
|
2
|
-
|
|
3
|
-
from uuid import UUID
|
|
4
|
-
|
|
5
|
-
from pydantic import BaseModel, Field
|
|
6
|
-
|
|
7
|
-
from fmu.settings.types import VersionStr # noqa TC001
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class SmdaIdentifier(BaseModel):
|
|
11
|
-
"""The identifier for something known to SMDA."""
|
|
12
|
-
|
|
13
|
-
identifier: str
|
|
14
|
-
"""Identifier known to SMDA."""
|
|
15
|
-
|
|
16
|
-
uuid: UUID
|
|
17
|
-
"""Identifier known to SMDA."""
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class CountryItem(SmdaIdentifier):
|
|
21
|
-
"""A single country in the list of countries known to SMDA."""
|
|
22
|
-
|
|
23
|
-
identifier: str = Field(examples=["Norway"])
|
|
24
|
-
"""Identifier known to SMDA."""
|
|
25
|
-
|
|
26
|
-
uuid: UUID = Field(examples=["15ce3b84-766f-4c93-9050-b154861f9100"])
|
|
27
|
-
"""Identifier known to SMDA."""
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class FieldItem(SmdaIdentifier):
|
|
31
|
-
"""A single field in the list of fields known to SMDA."""
|
|
32
|
-
|
|
33
|
-
identifier: str = Field(examples=["OseFax"])
|
|
34
|
-
"""Identifier known to SMDA."""
|
|
35
|
-
|
|
36
|
-
uuid: UUID = Field(examples=["15ce3b84-766f-4c93-9050-b154861f9100"])
|
|
37
|
-
"""Identifier known to SMDA."""
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class CoordinateSystem(SmdaIdentifier):
|
|
41
|
-
"""Contains the coordinate system known to SMDA."""
|
|
42
|
-
|
|
43
|
-
identifier: str = Field(examples=["ST_WGS84_UTM37N_P32637"])
|
|
44
|
-
"""Identifier known to SMDA."""
|
|
45
|
-
|
|
46
|
-
uuid: UUID = Field(examples=["15ce3b84-766f-4c93-9050-b154861f9100"])
|
|
47
|
-
"""Identifier known to SMDA."""
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class StratigraphicColumn(SmdaIdentifier):
|
|
51
|
-
"""Contains the stratigraphic column known to SMDA."""
|
|
52
|
-
|
|
53
|
-
identifier: str = Field(examples=["DROGON_2020"])
|
|
54
|
-
"""Identifier known to SMDA."""
|
|
55
|
-
|
|
56
|
-
uuid: UUID = Field(examples=["15ce3b84-766f-4c93-9050-b154861f9100"])
|
|
57
|
-
"""Identifier known to SMDA."""
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
class DiscoveryItem(BaseModel):
|
|
61
|
-
"""A single discovery in the list of discoveries known to SMDA."""
|
|
62
|
-
|
|
63
|
-
short_identifier: str = Field(examples=["SomeDiscovery"])
|
|
64
|
-
"""Identifier known to SMDA."""
|
|
65
|
-
|
|
66
|
-
uuid: UUID = Field(examples=["15ce3b84-766f-4c93-9050-b154861f9100"])
|
|
67
|
-
"""Identifier known to SMDA."""
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
class Smda(BaseModel):
|
|
71
|
-
"""Contains SMDA-related attributes."""
|
|
72
|
-
|
|
73
|
-
coordinate_system: CoordinateSystem
|
|
74
|
-
"""Reference to coordinate system known to SMDA. See :class:`CoordinateSystem`."""
|
|
75
|
-
|
|
76
|
-
country: list[CountryItem]
|
|
77
|
-
"""A list referring to countries known to SMDA. First item is primary.
|
|
78
|
-
See :class:`CountryItem`."""
|
|
79
|
-
|
|
80
|
-
discovery: list[DiscoveryItem]
|
|
81
|
-
"""A list referring to discoveries known to SMDA. First item is primary.
|
|
82
|
-
See :class:`DiscoveryItem`."""
|
|
83
|
-
|
|
84
|
-
field: list[FieldItem]
|
|
85
|
-
"""A list referring to fields known to SMDA. First item is primary.
|
|
86
|
-
See :class:`FieldItem`."""
|
|
87
|
-
|
|
88
|
-
stratigraphic_column: StratigraphicColumn
|
|
89
|
-
"""Reference to stratigraphic column known to SMDA.
|
|
90
|
-
See :class:`StratigraphicColumn`."""
|
|
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
|