14
14
import pathlib
15
15
from collections import abc
16
16
from copy import deepcopy
17
- from typing import TYPE_CHECKING , Any , Dict , Literal , Mapping , Optional , Type
17
+ from typing import TYPE_CHECKING , Any , Literal , cast
18
18
19
19
from aiida .common import exceptions
20
20
from aiida .common .lang import type_check
@@ -43,13 +43,13 @@ class Profile:
43
43
KEY_TEST_PROFILE : str = 'test_profile'
44
44
45
45
# keys that are expected to be in the parsed configuration
46
- REQUIRED_KEYS : tuple [Literal [ 'storage' ], Literal [ 'process_control' ] ] = (
46
+ REQUIRED_KEYS : tuple [str , str ] = (
47
47
KEY_STORAGE ,
48
48
KEY_PROCESS ,
49
49
)
50
50
51
51
def __init__ (
52
- self , name : str , config : Mapping [str , Any ], config_folder : pathlib .Path | None = None , validate : bool = True
52
+ self , name : str , config : abc . Mapping [str , Any ], config_folder : pathlib .Path | None = None , validate : bool = True
53
53
):
54
54
"""Load a profile with the profile configuration."""
55
55
_ = type_check (config , abc .Mapping )
@@ -59,7 +59,7 @@ def __init__(
59
59
)
60
60
61
61
self ._name : str = name
62
- self ._attributes : Dict [str , Any ] = deepcopy (config )
62
+ self ._attributes : dict [str , Any ] = cast ( dict [ str , Any ], deepcopy (config ) )
63
63
64
64
# Create a default UUID if not specified
65
65
if self ._attributes .get (self .KEY_UUID , None ) is None :
@@ -93,17 +93,13 @@ def config_path_resolver(self) -> AiiDAConfigPathResolver:
93
93
"""The config_path_resolver property."""
94
94
return self ._config_path_resolver
95
95
96
- @config_path_resolver .setter
97
- def config_path_resolver (self , value ):
98
- self ._config_path_resolver = value
99
-
100
96
@property
101
- def default_user_email (self ) -> Optional [ str ] :
97
+ def default_user_email (self ) -> str | None :
102
98
"""Return the default user email."""
103
99
return self ._attributes .get (self .KEY_DEFAULT_USER_EMAIL , None )
104
100
105
101
@default_user_email .setter
106
- def default_user_email (self , value : Optional [ str ] ) -> None :
102
+ def default_user_email (self , value : str | None ) -> None :
107
103
"""Set the default user email."""
108
104
self ._attributes [self .KEY_DEFAULT_USER_EMAIL ] = value
109
105
@@ -113,11 +109,11 @@ def storage_backend(self) -> str:
113
109
return self ._attributes [self .KEY_STORAGE ][self .KEY_STORAGE_BACKEND ]
114
110
115
111
@property
116
- def storage_config (self ) -> Dict [str , Any ]:
112
+ def storage_config (self ) -> dict [str , Any ]:
117
113
"""Return the configuration required by the storage backend."""
118
114
return self ._attributes [self .KEY_STORAGE ][self .KEY_STORAGE_CONFIG ]
119
115
120
- def set_storage (self , name : str , config : Dict [str , Any ]) -> None :
116
+ def set_storage (self , name : str , config : dict [str , Any ]) -> None :
121
117
"""Set the storage backend and its configuration.
122
118
123
119
:param name: the name of the storage backend
@@ -128,7 +124,7 @@ def set_storage(self, name: str, config: Dict[str, Any]) -> None:
128
124
self ._attributes [self .KEY_STORAGE ][self .KEY_STORAGE_CONFIG ] = config
129
125
130
126
@property
131
- def storage_cls (self ) -> Type ['StorageBackend' ]:
127
+ def storage_cls (self ) -> type ['StorageBackend' ]:
132
128
"""Return the storage backend class for this profile."""
133
129
from aiida .plugins import StorageFactory
134
130
@@ -140,11 +136,11 @@ def process_control_backend(self) -> str | None:
140
136
return self ._attributes [self .KEY_PROCESS ][self .KEY_PROCESS_BACKEND ]
141
137
142
138
@property
143
- def process_control_config (self ) -> Dict [str , Any ]:
139
+ def process_control_config (self ) -> dict [str , Any ]:
144
140
"""Return the configuration required by the process control backend."""
145
141
return self ._attributes [self .KEY_PROCESS ][self .KEY_PROCESS_CONFIG ] or {}
146
142
147
- def set_process_controller (self , name : str , config : Dict [str , Any ]) -> None :
143
+ def set_process_controller (self , name : str , config : dict [str , Any ]) -> None :
148
144
"""Set the process control backend and its configuration.
149
145
150
146
:param name: the name of the process backend
@@ -189,7 +185,7 @@ def name(self):
189
185
return self ._name
190
186
191
187
@property
192
- def dictionary (self ) -> Dict [str , Any ]:
188
+ def dictionary (self ) -> dict [str , Any ]:
193
189
"""Return the profile attributes as a dictionary with keys as it is stored in the config
194
190
195
191
:return: the profile configuration dictionary
0 commit comments