lamindb_setup 1.9.1__py3-none-any.whl → 1.10.1__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.
- lamindb_setup/__init__.py +107 -107
- lamindb_setup/_cache.py +87 -87
- lamindb_setup/_check_setup.py +192 -166
- lamindb_setup/_connect_instance.py +430 -328
- lamindb_setup/_delete.py +144 -141
- lamindb_setup/_disconnect.py +35 -32
- lamindb_setup/_init_instance.py +430 -440
- lamindb_setup/_migrate.py +278 -266
- lamindb_setup/_register_instance.py +32 -35
- lamindb_setup/_schema_metadata.py +441 -441
- lamindb_setup/_set_managed_storage.py +69 -70
- lamindb_setup/_setup_user.py +172 -133
- lamindb_setup/core/__init__.py +21 -21
- lamindb_setup/core/_aws_options.py +223 -223
- lamindb_setup/core/_aws_storage.py +9 -1
- lamindb_setup/core/_deprecated.py +1 -1
- lamindb_setup/core/_hub_client.py +248 -248
- lamindb_setup/core/_hub_core.py +751 -665
- lamindb_setup/core/_hub_crud.py +247 -227
- lamindb_setup/core/_private_django_api.py +83 -83
- lamindb_setup/core/_settings.py +374 -377
- lamindb_setup/core/_settings_instance.py +609 -569
- lamindb_setup/core/_settings_load.py +141 -141
- lamindb_setup/core/_settings_save.py +95 -95
- lamindb_setup/core/_settings_storage.py +427 -429
- lamindb_setup/core/_settings_store.py +91 -91
- lamindb_setup/core/_settings_user.py +55 -55
- lamindb_setup/core/_setup_bionty_sources.py +44 -44
- lamindb_setup/core/cloud_sqlite_locker.py +240 -240
- lamindb_setup/core/django.py +311 -305
- lamindb_setup/core/exceptions.py +1 -1
- lamindb_setup/core/hashing.py +134 -134
- lamindb_setup/core/types.py +1 -1
- lamindb_setup/core/upath.py +1013 -1013
- lamindb_setup/errors.py +80 -70
- lamindb_setup/types.py +20 -20
- {lamindb_setup-1.9.1.dist-info → lamindb_setup-1.10.1.dist-info}/METADATA +4 -4
- lamindb_setup-1.10.1.dist-info/RECORD +50 -0
- lamindb_setup-1.9.1.dist-info/RECORD +0 -50
- {lamindb_setup-1.9.1.dist-info → lamindb_setup-1.10.1.dist-info}/LICENSE +0 -0
- {lamindb_setup-1.9.1.dist-info → lamindb_setup-1.10.1.dist-info}/WHEEL +0 -0
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
6
|
-
from uuid import UUID, uuid4
|
|
7
|
-
|
|
8
|
-
from dotenv import dotenv_values
|
|
9
|
-
from lamin_utils import logger
|
|
10
|
-
from pydantic import ValidationError
|
|
11
|
-
|
|
12
|
-
from lamindb_setup.errors import SettingsEnvFileOutdated
|
|
13
|
-
|
|
14
|
-
from ._settings_instance import InstanceSettings
|
|
15
|
-
from ._settings_storage import StorageSettings
|
|
16
|
-
from ._settings_store import (
|
|
17
|
-
InstanceSettingsStore,
|
|
18
|
-
UserSettingsStore,
|
|
19
|
-
current_instance_settings_file,
|
|
20
|
-
current_user_settings_file,
|
|
21
|
-
platform_user_storage_settings_file,
|
|
22
|
-
system_settings_file,
|
|
23
|
-
)
|
|
24
|
-
from ._settings_user import UserSettings
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def load_cache_path_from_settings(storage_settings: Path | None = None) -> Path | None:
|
|
28
|
-
if storage_settings is None:
|
|
29
|
-
paltform_user_storage_settings = platform_user_storage_settings_file()
|
|
30
|
-
if paltform_user_storage_settings.exists():
|
|
31
|
-
cache_path = dotenv_values(paltform_user_storage_settings).get(
|
|
32
|
-
"lamindb_cache_path", None
|
|
33
|
-
)
|
|
34
|
-
else:
|
|
35
|
-
cache_path = None
|
|
36
|
-
|
|
37
|
-
if cache_path in {None, "null", ""}:
|
|
38
|
-
storage_settings = system_settings_file()
|
|
39
|
-
else:
|
|
40
|
-
return Path(cache_path)
|
|
41
|
-
|
|
42
|
-
if storage_settings.exists():
|
|
43
|
-
cache_path = dotenv_values(storage_settings).get("lamindb_cache_path", None)
|
|
44
|
-
return Path(cache_path) if cache_path not in {None, "null", ""} else None
|
|
45
|
-
else:
|
|
46
|
-
return None
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def load_instance_settings(instance_settings_file: Path | None = None):
|
|
50
|
-
if instance_settings_file is None:
|
|
51
|
-
instance_settings_file = current_instance_settings_file()
|
|
52
|
-
if not instance_settings_file.exists():
|
|
53
|
-
raise
|
|
54
|
-
try:
|
|
55
|
-
settings_store = InstanceSettingsStore(_env_file=instance_settings_file)
|
|
56
|
-
except (ValidationError, TypeError) as error:
|
|
57
|
-
with open(instance_settings_file) as f:
|
|
58
|
-
content = f.read()
|
|
59
|
-
raise SettingsEnvFileOutdated(
|
|
60
|
-
f"\n\n{error}\n\nYour instance settings file with\n\n{content}\nis invalid"
|
|
61
|
-
f" (likely outdated), see validation error. Please delete {instance_settings_file} &"
|
|
62
|
-
" reload (remote) or re-initialize (local) the instance with the same name & storage location."
|
|
63
|
-
) from error
|
|
64
|
-
isettings = setup_instance_from_store(settings_store)
|
|
65
|
-
return isettings
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def load_or_create_user_settings(api_key: str | None = None) -> UserSettings:
|
|
69
|
-
"""Return current user settings.
|
|
70
|
-
|
|
71
|
-
Args:
|
|
72
|
-
api_key: if provided and there is no current user,
|
|
73
|
-
perform login and return the user settings.
|
|
74
|
-
"""
|
|
75
|
-
current_user_settings = current_user_settings_file()
|
|
76
|
-
if not current_user_settings.exists():
|
|
77
|
-
if api_key is not None:
|
|
78
|
-
from lamindb_setup._setup_user import login
|
|
79
|
-
|
|
80
|
-
return login(api_key=api_key)
|
|
81
|
-
else:
|
|
82
|
-
logger.warning("using anonymous user (to identify, call: lamin login)")
|
|
83
|
-
usettings = UserSettings(handle="anonymous", uid="00000000")
|
|
84
|
-
from ._settings_save import save_user_settings
|
|
85
|
-
|
|
86
|
-
save_user_settings(usettings)
|
|
87
|
-
else:
|
|
88
|
-
usettings = load_user_settings(current_user_settings)
|
|
89
|
-
return usettings
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def load_user_settings(user_settings_file: Path):
|
|
93
|
-
try:
|
|
94
|
-
settings_store = UserSettingsStore(_env_file=user_settings_file)
|
|
95
|
-
except (ValidationError, TypeError) as error:
|
|
96
|
-
msg = (
|
|
97
|
-
"Your user settings file is invalid, please delete"
|
|
98
|
-
f" {user_settings_file} and log in again."
|
|
99
|
-
)
|
|
100
|
-
print(msg)
|
|
101
|
-
raise SettingsEnvFileOutdated(msg) from error
|
|
102
|
-
settings = setup_user_from_store(settings_store)
|
|
103
|
-
return settings
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def _null_to_value(field, value=None):
|
|
107
|
-
return field if field != "null" else value
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def setup_instance_from_store(store: InstanceSettingsStore) -> InstanceSettings:
|
|
111
|
-
ssettings = StorageSettings(
|
|
112
|
-
root=store.storage_root,
|
|
113
|
-
region=_null_to_value(store.storage_region),
|
|
114
|
-
)
|
|
115
|
-
return InstanceSettings(
|
|
116
|
-
id=UUID(store.id),
|
|
117
|
-
owner=store.owner,
|
|
118
|
-
name=store.name,
|
|
119
|
-
storage=ssettings,
|
|
120
|
-
db=_null_to_value(store.db),
|
|
121
|
-
modules=_null_to_value(store.schema_str),
|
|
122
|
-
git_repo=_null_to_value(store.git_repo),
|
|
123
|
-
keep_artifacts_local=store.keep_artifacts_local, # type: ignore
|
|
124
|
-
api_url=_null_to_value(store.api_url),
|
|
125
|
-
schema_id=None if store.schema_id in {None, "null"} else UUID(store.schema_id),
|
|
126
|
-
fine_grained_access=store.fine_grained_access,
|
|
127
|
-
db_permissions=_null_to_value(store.db_permissions),
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def setup_user_from_store(store: UserSettingsStore) -> UserSettings:
|
|
132
|
-
settings = UserSettings()
|
|
133
|
-
settings.email = _null_to_value(store.email)
|
|
134
|
-
settings.password = _null_to_value(store.password)
|
|
135
|
-
settings.access_token = store.access_token
|
|
136
|
-
settings.api_key = _null_to_value(store.api_key)
|
|
137
|
-
settings.uid = store.uid
|
|
138
|
-
settings.handle = _null_to_value(store.handle, value="anonymous")
|
|
139
|
-
settings.name = _null_to_value(store.name)
|
|
140
|
-
settings._uuid = UUID(store.uuid) if store.uuid != "null" else None
|
|
141
|
-
return settings
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
from uuid import UUID, uuid4
|
|
7
|
+
|
|
8
|
+
from dotenv import dotenv_values
|
|
9
|
+
from lamin_utils import logger
|
|
10
|
+
from pydantic import ValidationError
|
|
11
|
+
|
|
12
|
+
from lamindb_setup.errors import CurrentInstanceNotConfigured, SettingsEnvFileOutdated
|
|
13
|
+
|
|
14
|
+
from ._settings_instance import InstanceSettings
|
|
15
|
+
from ._settings_storage import StorageSettings
|
|
16
|
+
from ._settings_store import (
|
|
17
|
+
InstanceSettingsStore,
|
|
18
|
+
UserSettingsStore,
|
|
19
|
+
current_instance_settings_file,
|
|
20
|
+
current_user_settings_file,
|
|
21
|
+
platform_user_storage_settings_file,
|
|
22
|
+
system_settings_file,
|
|
23
|
+
)
|
|
24
|
+
from ._settings_user import UserSettings
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def load_cache_path_from_settings(storage_settings: Path | None = None) -> Path | None:
|
|
28
|
+
if storage_settings is None:
|
|
29
|
+
paltform_user_storage_settings = platform_user_storage_settings_file()
|
|
30
|
+
if paltform_user_storage_settings.exists():
|
|
31
|
+
cache_path = dotenv_values(paltform_user_storage_settings).get(
|
|
32
|
+
"lamindb_cache_path", None
|
|
33
|
+
)
|
|
34
|
+
else:
|
|
35
|
+
cache_path = None
|
|
36
|
+
|
|
37
|
+
if cache_path in {None, "null", ""}:
|
|
38
|
+
storage_settings = system_settings_file()
|
|
39
|
+
else:
|
|
40
|
+
return Path(cache_path)
|
|
41
|
+
|
|
42
|
+
if storage_settings.exists():
|
|
43
|
+
cache_path = dotenv_values(storage_settings).get("lamindb_cache_path", None)
|
|
44
|
+
return Path(cache_path) if cache_path not in {None, "null", ""} else None
|
|
45
|
+
else:
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def load_instance_settings(instance_settings_file: Path | None = None):
|
|
50
|
+
if instance_settings_file is None:
|
|
51
|
+
instance_settings_file = current_instance_settings_file()
|
|
52
|
+
if not instance_settings_file.exists():
|
|
53
|
+
raise CurrentInstanceNotConfigured
|
|
54
|
+
try:
|
|
55
|
+
settings_store = InstanceSettingsStore(_env_file=instance_settings_file)
|
|
56
|
+
except (ValidationError, TypeError) as error:
|
|
57
|
+
with open(instance_settings_file) as f:
|
|
58
|
+
content = f.read()
|
|
59
|
+
raise SettingsEnvFileOutdated(
|
|
60
|
+
f"\n\n{error}\n\nYour instance settings file with\n\n{content}\nis invalid"
|
|
61
|
+
f" (likely outdated), see validation error. Please delete {instance_settings_file} &"
|
|
62
|
+
" reload (remote) or re-initialize (local) the instance with the same name & storage location."
|
|
63
|
+
) from error
|
|
64
|
+
isettings = setup_instance_from_store(settings_store)
|
|
65
|
+
return isettings
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def load_or_create_user_settings(api_key: str | None = None) -> UserSettings:
|
|
69
|
+
"""Return current user settings.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
api_key: if provided and there is no current user,
|
|
73
|
+
perform login and return the user settings.
|
|
74
|
+
"""
|
|
75
|
+
current_user_settings = current_user_settings_file()
|
|
76
|
+
if not current_user_settings.exists():
|
|
77
|
+
if api_key is not None:
|
|
78
|
+
from lamindb_setup._setup_user import login
|
|
79
|
+
|
|
80
|
+
return login(api_key=api_key)
|
|
81
|
+
else:
|
|
82
|
+
logger.warning("using anonymous user (to identify, call: lamin login)")
|
|
83
|
+
usettings = UserSettings(handle="anonymous", uid="00000000")
|
|
84
|
+
from ._settings_save import save_user_settings
|
|
85
|
+
|
|
86
|
+
save_user_settings(usettings)
|
|
87
|
+
else:
|
|
88
|
+
usettings = load_user_settings(current_user_settings)
|
|
89
|
+
return usettings
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def load_user_settings(user_settings_file: Path):
|
|
93
|
+
try:
|
|
94
|
+
settings_store = UserSettingsStore(_env_file=user_settings_file)
|
|
95
|
+
except (ValidationError, TypeError) as error:
|
|
96
|
+
msg = (
|
|
97
|
+
"Your user settings file is invalid, please delete"
|
|
98
|
+
f" {user_settings_file} and log in again."
|
|
99
|
+
)
|
|
100
|
+
print(msg)
|
|
101
|
+
raise SettingsEnvFileOutdated(msg) from error
|
|
102
|
+
settings = setup_user_from_store(settings_store)
|
|
103
|
+
return settings
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _null_to_value(field, value=None):
|
|
107
|
+
return field if field != "null" else value
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def setup_instance_from_store(store: InstanceSettingsStore) -> InstanceSettings:
|
|
111
|
+
ssettings = StorageSettings(
|
|
112
|
+
root=store.storage_root,
|
|
113
|
+
region=_null_to_value(store.storage_region),
|
|
114
|
+
)
|
|
115
|
+
return InstanceSettings(
|
|
116
|
+
id=UUID(store.id),
|
|
117
|
+
owner=store.owner,
|
|
118
|
+
name=store.name,
|
|
119
|
+
storage=ssettings,
|
|
120
|
+
db=_null_to_value(store.db),
|
|
121
|
+
modules=_null_to_value(store.schema_str),
|
|
122
|
+
git_repo=_null_to_value(store.git_repo),
|
|
123
|
+
keep_artifacts_local=store.keep_artifacts_local, # type: ignore
|
|
124
|
+
api_url=_null_to_value(store.api_url),
|
|
125
|
+
schema_id=None if store.schema_id in {None, "null"} else UUID(store.schema_id),
|
|
126
|
+
fine_grained_access=store.fine_grained_access,
|
|
127
|
+
db_permissions=_null_to_value(store.db_permissions),
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def setup_user_from_store(store: UserSettingsStore) -> UserSettings:
|
|
132
|
+
settings = UserSettings()
|
|
133
|
+
settings.email = _null_to_value(store.email)
|
|
134
|
+
settings.password = _null_to_value(store.password)
|
|
135
|
+
settings.access_token = store.access_token
|
|
136
|
+
settings.api_key = _null_to_value(store.api_key)
|
|
137
|
+
settings.uid = store.uid
|
|
138
|
+
settings.handle = _null_to_value(store.handle, value="anonymous")
|
|
139
|
+
settings.name = _null_to_value(store.name)
|
|
140
|
+
settings._uuid = UUID(store.uuid) if store.uuid != "null" else None
|
|
141
|
+
return settings
|
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import TYPE_CHECKING, Any, Optional, get_type_hints
|
|
5
|
-
from uuid import UUID
|
|
6
|
-
|
|
7
|
-
from ._settings_store import (
|
|
8
|
-
InstanceSettingsStore,
|
|
9
|
-
UserSettingsStore,
|
|
10
|
-
current_user_settings_file,
|
|
11
|
-
platform_user_storage_settings_file,
|
|
12
|
-
user_settings_file_email,
|
|
13
|
-
user_settings_file_handle,
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
if TYPE_CHECKING:
|
|
17
|
-
from lamindb_setup.types import UPathStr
|
|
18
|
-
|
|
19
|
-
from ._settings_user import UserSettings
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def save_user_settings(settings: UserSettings):
|
|
23
|
-
type_hints = get_type_hints(UserSettingsStore)
|
|
24
|
-
prefix = "lamin_user_"
|
|
25
|
-
save_settings(settings, current_user_settings_file(), type_hints, prefix)
|
|
26
|
-
if settings.email is not None:
|
|
27
|
-
save_settings(
|
|
28
|
-
settings, user_settings_file_email(settings.email), type_hints, prefix
|
|
29
|
-
)
|
|
30
|
-
if settings.handle is not None and settings.handle != "anonymous":
|
|
31
|
-
save_settings(
|
|
32
|
-
settings, user_settings_file_handle(settings.handle), type_hints, prefix
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def save_settings(
|
|
37
|
-
settings: Any,
|
|
38
|
-
settings_file: Path,
|
|
39
|
-
type_hints: dict[str, Any],
|
|
40
|
-
prefix: str,
|
|
41
|
-
):
|
|
42
|
-
with open(settings_file, "w") as f:
|
|
43
|
-
for store_key, type_ in type_hints.items():
|
|
44
|
-
if type_ == Optional[str]:
|
|
45
|
-
type_ = str
|
|
46
|
-
if type_ == Optional[bool]:
|
|
47
|
-
type_ = bool
|
|
48
|
-
if "__" not in store_key:
|
|
49
|
-
if store_key == "model_config":
|
|
50
|
-
continue
|
|
51
|
-
if store_key == "storage_root":
|
|
52
|
-
value = settings.storage.root_as_str
|
|
53
|
-
elif store_key == "storage_region":
|
|
54
|
-
value = settings.storage.region
|
|
55
|
-
else:
|
|
56
|
-
if store_key in {
|
|
57
|
-
"db",
|
|
58
|
-
"schema_str",
|
|
59
|
-
"name_",
|
|
60
|
-
"uuid",
|
|
61
|
-
"id",
|
|
62
|
-
"api_url",
|
|
63
|
-
"schema_id",
|
|
64
|
-
"fine_grained_access",
|
|
65
|
-
"db_permissions",
|
|
66
|
-
}:
|
|
67
|
-
settings_key = f"_{store_key.rstrip('_')}"
|
|
68
|
-
else:
|
|
69
|
-
settings_key = store_key
|
|
70
|
-
value = getattr(settings, settings_key, None)
|
|
71
|
-
if value is None:
|
|
72
|
-
value = "null"
|
|
73
|
-
elif isinstance(value, UUID):
|
|
74
|
-
value = value.hex
|
|
75
|
-
else:
|
|
76
|
-
value = type_(value)
|
|
77
|
-
f.write(f"{prefix}{store_key}={value}\n")
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def save_instance_settings(settings: Any, settings_file: Path):
|
|
81
|
-
type_hints = get_type_hints(InstanceSettingsStore)
|
|
82
|
-
prefix = "lamindb_instance_"
|
|
83
|
-
save_settings(settings, settings_file, type_hints, prefix)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def save_platform_user_storage_settings(
|
|
87
|
-
cache_path: UPathStr | None, settings_file: UPathStr | None = None
|
|
88
|
-
):
|
|
89
|
-
cache_path = "null" if cache_path is None else cache_path
|
|
90
|
-
if isinstance(cache_path, Path): # also True for UPath
|
|
91
|
-
cache_path = cache_path.as_posix()
|
|
92
|
-
if settings_file is None:
|
|
93
|
-
settings_file = platform_user_storage_settings_file()
|
|
94
|
-
with open(settings_file, "w") as f:
|
|
95
|
-
f.write(f"lamindb_cache_path={cache_path}")
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Optional, get_type_hints
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
|
|
7
|
+
from ._settings_store import (
|
|
8
|
+
InstanceSettingsStore,
|
|
9
|
+
UserSettingsStore,
|
|
10
|
+
current_user_settings_file,
|
|
11
|
+
platform_user_storage_settings_file,
|
|
12
|
+
user_settings_file_email,
|
|
13
|
+
user_settings_file_handle,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from lamindb_setup.types import UPathStr
|
|
18
|
+
|
|
19
|
+
from ._settings_user import UserSettings
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def save_user_settings(settings: UserSettings):
|
|
23
|
+
type_hints = get_type_hints(UserSettingsStore)
|
|
24
|
+
prefix = "lamin_user_"
|
|
25
|
+
save_settings(settings, current_user_settings_file(), type_hints, prefix)
|
|
26
|
+
if settings.email is not None:
|
|
27
|
+
save_settings(
|
|
28
|
+
settings, user_settings_file_email(settings.email), type_hints, prefix
|
|
29
|
+
)
|
|
30
|
+
if settings.handle is not None and settings.handle != "anonymous":
|
|
31
|
+
save_settings(
|
|
32
|
+
settings, user_settings_file_handle(settings.handle), type_hints, prefix
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def save_settings(
|
|
37
|
+
settings: Any,
|
|
38
|
+
settings_file: Path,
|
|
39
|
+
type_hints: dict[str, Any],
|
|
40
|
+
prefix: str,
|
|
41
|
+
):
|
|
42
|
+
with open(settings_file, "w") as f:
|
|
43
|
+
for store_key, type_ in type_hints.items():
|
|
44
|
+
if type_ == Optional[str]:
|
|
45
|
+
type_ = str
|
|
46
|
+
if type_ == Optional[bool]:
|
|
47
|
+
type_ = bool
|
|
48
|
+
if "__" not in store_key:
|
|
49
|
+
if store_key == "model_config":
|
|
50
|
+
continue
|
|
51
|
+
if store_key == "storage_root":
|
|
52
|
+
value = settings.storage.root_as_str
|
|
53
|
+
elif store_key == "storage_region":
|
|
54
|
+
value = settings.storage.region
|
|
55
|
+
else:
|
|
56
|
+
if store_key in {
|
|
57
|
+
"db",
|
|
58
|
+
"schema_str",
|
|
59
|
+
"name_",
|
|
60
|
+
"uuid",
|
|
61
|
+
"id",
|
|
62
|
+
"api_url",
|
|
63
|
+
"schema_id",
|
|
64
|
+
"fine_grained_access",
|
|
65
|
+
"db_permissions",
|
|
66
|
+
}:
|
|
67
|
+
settings_key = f"_{store_key.rstrip('_')}"
|
|
68
|
+
else:
|
|
69
|
+
settings_key = store_key
|
|
70
|
+
value = getattr(settings, settings_key, None)
|
|
71
|
+
if value is None:
|
|
72
|
+
value = "null"
|
|
73
|
+
elif isinstance(value, UUID):
|
|
74
|
+
value = value.hex
|
|
75
|
+
else:
|
|
76
|
+
value = type_(value)
|
|
77
|
+
f.write(f"{prefix}{store_key}={value}\n")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def save_instance_settings(settings: Any, settings_file: Path):
|
|
81
|
+
type_hints = get_type_hints(InstanceSettingsStore)
|
|
82
|
+
prefix = "lamindb_instance_"
|
|
83
|
+
save_settings(settings, settings_file, type_hints, prefix)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def save_platform_user_storage_settings(
|
|
87
|
+
cache_path: UPathStr | None, settings_file: UPathStr | None = None
|
|
88
|
+
):
|
|
89
|
+
cache_path = "null" if cache_path is None else cache_path
|
|
90
|
+
if isinstance(cache_path, Path): # also True for UPath
|
|
91
|
+
cache_path = cache_path.as_posix()
|
|
92
|
+
if settings_file is None:
|
|
93
|
+
settings_file = platform_user_storage_settings_file()
|
|
94
|
+
with open(settings_file, "w") as f:
|
|
95
|
+
f.write(f"lamindb_cache_path={cache_path}")
|