lamindb_setup 0.77.4__py2.py3-none-any.whl → 0.77.6__py2.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 +1 -2
- lamindb_setup/_cache.py +34 -34
- lamindb_setup/_check.py +7 -7
- lamindb_setup/_check_setup.py +92 -79
- lamindb_setup/_close.py +35 -35
- lamindb_setup/_connect_instance.py +425 -444
- lamindb_setup/_django.py +41 -41
- lamindb_setup/_entry_points.py +22 -22
- lamindb_setup/_exportdb.py +68 -68
- lamindb_setup/_importdb.py +50 -50
- lamindb_setup/_init_instance.py +411 -374
- lamindb_setup/_migrate.py +239 -239
- lamindb_setup/_register_instance.py +36 -36
- lamindb_setup/_schema.py +27 -27
- lamindb_setup/_schema_metadata.py +411 -411
- lamindb_setup/_set_managed_storage.py +55 -55
- lamindb_setup/_setup_user.py +137 -137
- lamindb_setup/_silence_loggers.py +44 -44
- lamindb_setup/core/__init__.py +21 -21
- lamindb_setup/core/_aws_credentials.py +151 -151
- lamindb_setup/core/_aws_storage.py +48 -48
- lamindb_setup/core/_deprecated.py +55 -55
- lamindb_setup/core/_docs.py +14 -14
- lamindb_setup/core/_hub_client.py +1 -1
- lamindb_setup/core/_hub_core.py +615 -590
- lamindb_setup/core/_hub_crud.py +211 -211
- lamindb_setup/core/_hub_utils.py +109 -109
- lamindb_setup/core/_private_django_api.py +88 -88
- lamindb_setup/core/_settings.py +145 -138
- lamindb_setup/core/_settings_instance.py +480 -467
- lamindb_setup/core/_settings_load.py +105 -105
- lamindb_setup/core/_settings_save.py +81 -81
- lamindb_setup/core/_settings_storage.py +412 -405
- lamindb_setup/core/_settings_store.py +75 -75
- lamindb_setup/core/_settings_user.py +55 -53
- lamindb_setup/core/_setup_bionty_sources.py +101 -101
- lamindb_setup/core/cloud_sqlite_locker.py +237 -232
- lamindb_setup/core/django.py +115 -114
- lamindb_setup/core/exceptions.py +12 -12
- lamindb_setup/core/hashing.py +114 -114
- lamindb_setup/core/types.py +19 -19
- lamindb_setup/core/upath.py +779 -779
- {lamindb_setup-0.77.4.dist-info → lamindb_setup-0.77.6.dist-info}/METADATA +3 -2
- lamindb_setup-0.77.6.dist-info/RECORD +47 -0
- {lamindb_setup-0.77.4.dist-info → lamindb_setup-0.77.6.dist-info}/WHEEL +1 -1
- lamindb_setup-0.77.4.dist-info/RECORD +0 -47
- {lamindb_setup-0.77.4.dist-info → lamindb_setup-0.77.6.dist-info}/LICENSE +0 -0
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING, Optional
|
|
4
|
-
from uuid import UUID, uuid4
|
|
5
|
-
|
|
6
|
-
from lamin_utils import logger
|
|
7
|
-
from pydantic import ValidationError
|
|
8
|
-
|
|
9
|
-
from ._settings_instance import InstanceSettings
|
|
10
|
-
from ._settings_storage import StorageSettings
|
|
11
|
-
from ._settings_store import (
|
|
12
|
-
InstanceSettingsStore,
|
|
13
|
-
UserSettingsStore,
|
|
14
|
-
current_instance_settings_file,
|
|
15
|
-
current_user_settings_file,
|
|
16
|
-
)
|
|
17
|
-
from ._settings_user import UserSettings
|
|
18
|
-
|
|
19
|
-
if TYPE_CHECKING:
|
|
20
|
-
from pathlib import Path
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class SettingsEnvFileOutdated(Exception):
|
|
24
|
-
pass
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def load_instance_settings(instance_settings_file: Path | None = None):
|
|
28
|
-
if instance_settings_file is None:
|
|
29
|
-
instance_settings_file = current_instance_settings_file()
|
|
30
|
-
if not instance_settings_file.exists():
|
|
31
|
-
raise SystemExit("No instance is loaded! Call `lamin init` or `lamin load`")
|
|
32
|
-
try:
|
|
33
|
-
settings_store = InstanceSettingsStore(_env_file=instance_settings_file)
|
|
34
|
-
except (ValidationError, TypeError) as error:
|
|
35
|
-
with open(instance_settings_file) as f:
|
|
36
|
-
content = f.read()
|
|
37
|
-
raise SettingsEnvFileOutdated(
|
|
38
|
-
f"\n\n{error}\n\nYour instance settings file with\n\n{content}\nis invalid"
|
|
39
|
-
f" (likely outdated), see validation error. Please delete {instance_settings_file} &"
|
|
40
|
-
" reload (remote) or re-initialize (local) the instance with the same name & storage location."
|
|
41
|
-
) from error
|
|
42
|
-
isettings = setup_instance_from_store(settings_store)
|
|
43
|
-
return isettings
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def load_or_create_user_settings() -> UserSettings:
|
|
47
|
-
"""Return current user settings."""
|
|
48
|
-
current_user_settings = current_user_settings_file()
|
|
49
|
-
if not current_user_settings.exists():
|
|
50
|
-
logger.warning("using anonymous user (to identify, call: lamin login)")
|
|
51
|
-
usettings = UserSettings(handle="anonymous", uid="00000000")
|
|
52
|
-
from ._settings_save import save_user_settings
|
|
53
|
-
|
|
54
|
-
save_user_settings(usettings)
|
|
55
|
-
else:
|
|
56
|
-
usettings = load_user_settings(current_user_settings)
|
|
57
|
-
return usettings
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def load_user_settings(user_settings_file: Path):
|
|
61
|
-
try:
|
|
62
|
-
settings_store = UserSettingsStore(_env_file=user_settings_file)
|
|
63
|
-
except (ValidationError, TypeError) as error:
|
|
64
|
-
msg = (
|
|
65
|
-
"Your user settings file is invalid, please delete"
|
|
66
|
-
f" {user_settings_file} and log in again."
|
|
67
|
-
)
|
|
68
|
-
print(msg)
|
|
69
|
-
raise SettingsEnvFileOutdated(msg) from error
|
|
70
|
-
settings = setup_user_from_store(settings_store)
|
|
71
|
-
return settings
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def _null_to_value(field, value=None):
|
|
75
|
-
return field if field != "null" else value
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def setup_instance_from_store(store: InstanceSettingsStore) -> InstanceSettings:
|
|
79
|
-
ssettings = StorageSettings(
|
|
80
|
-
root=store.storage_root,
|
|
81
|
-
region=_null_to_value(store.storage_region),
|
|
82
|
-
)
|
|
83
|
-
return InstanceSettings(
|
|
84
|
-
id=UUID(store.id),
|
|
85
|
-
owner=store.owner,
|
|
86
|
-
name=store.name,
|
|
87
|
-
storage=ssettings,
|
|
88
|
-
db=_null_to_value(store.db),
|
|
89
|
-
schema=_null_to_value(store.schema_str),
|
|
90
|
-
git_repo=_null_to_value(store.git_repo),
|
|
91
|
-
keep_artifacts_local=store.keep_artifacts_local, # type: ignore
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def setup_user_from_store(store: UserSettingsStore) -> UserSettings:
|
|
96
|
-
settings = UserSettings()
|
|
97
|
-
settings.email = _null_to_value(store.email)
|
|
98
|
-
settings.password = _null_to_value(store.password)
|
|
99
|
-
settings.access_token = store.access_token
|
|
100
|
-
settings.api_key = _null_to_value(store.api_key)
|
|
101
|
-
settings.uid = store.uid
|
|
102
|
-
settings.handle = _null_to_value(store.handle, value="anonymous")
|
|
103
|
-
settings.name = _null_to_value(store.name)
|
|
104
|
-
settings._uuid = UUID(store.uuid) if store.uuid != "null" else None
|
|
105
|
-
return settings
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Optional
|
|
4
|
+
from uuid import UUID, uuid4
|
|
5
|
+
|
|
6
|
+
from lamin_utils import logger
|
|
7
|
+
from pydantic import ValidationError
|
|
8
|
+
|
|
9
|
+
from ._settings_instance import InstanceSettings
|
|
10
|
+
from ._settings_storage import StorageSettings
|
|
11
|
+
from ._settings_store import (
|
|
12
|
+
InstanceSettingsStore,
|
|
13
|
+
UserSettingsStore,
|
|
14
|
+
current_instance_settings_file,
|
|
15
|
+
current_user_settings_file,
|
|
16
|
+
)
|
|
17
|
+
from ._settings_user import UserSettings
|
|
18
|
+
|
|
19
|
+
if TYPE_CHECKING:
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class SettingsEnvFileOutdated(Exception):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def load_instance_settings(instance_settings_file: Path | None = None):
|
|
28
|
+
if instance_settings_file is None:
|
|
29
|
+
instance_settings_file = current_instance_settings_file()
|
|
30
|
+
if not instance_settings_file.exists():
|
|
31
|
+
raise SystemExit("No instance is loaded! Call `lamin init` or `lamin load`")
|
|
32
|
+
try:
|
|
33
|
+
settings_store = InstanceSettingsStore(_env_file=instance_settings_file)
|
|
34
|
+
except (ValidationError, TypeError) as error:
|
|
35
|
+
with open(instance_settings_file) as f:
|
|
36
|
+
content = f.read()
|
|
37
|
+
raise SettingsEnvFileOutdated(
|
|
38
|
+
f"\n\n{error}\n\nYour instance settings file with\n\n{content}\nis invalid"
|
|
39
|
+
f" (likely outdated), see validation error. Please delete {instance_settings_file} &"
|
|
40
|
+
" reload (remote) or re-initialize (local) the instance with the same name & storage location."
|
|
41
|
+
) from error
|
|
42
|
+
isettings = setup_instance_from_store(settings_store)
|
|
43
|
+
return isettings
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def load_or_create_user_settings() -> UserSettings:
|
|
47
|
+
"""Return current user settings."""
|
|
48
|
+
current_user_settings = current_user_settings_file()
|
|
49
|
+
if not current_user_settings.exists():
|
|
50
|
+
logger.warning("using anonymous user (to identify, call: lamin login)")
|
|
51
|
+
usettings = UserSettings(handle="anonymous", uid="00000000")
|
|
52
|
+
from ._settings_save import save_user_settings
|
|
53
|
+
|
|
54
|
+
save_user_settings(usettings)
|
|
55
|
+
else:
|
|
56
|
+
usettings = load_user_settings(current_user_settings)
|
|
57
|
+
return usettings
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def load_user_settings(user_settings_file: Path):
|
|
61
|
+
try:
|
|
62
|
+
settings_store = UserSettingsStore(_env_file=user_settings_file)
|
|
63
|
+
except (ValidationError, TypeError) as error:
|
|
64
|
+
msg = (
|
|
65
|
+
"Your user settings file is invalid, please delete"
|
|
66
|
+
f" {user_settings_file} and log in again."
|
|
67
|
+
)
|
|
68
|
+
print(msg)
|
|
69
|
+
raise SettingsEnvFileOutdated(msg) from error
|
|
70
|
+
settings = setup_user_from_store(settings_store)
|
|
71
|
+
return settings
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _null_to_value(field, value=None):
|
|
75
|
+
return field if field != "null" else value
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def setup_instance_from_store(store: InstanceSettingsStore) -> InstanceSettings:
|
|
79
|
+
ssettings = StorageSettings(
|
|
80
|
+
root=store.storage_root,
|
|
81
|
+
region=_null_to_value(store.storage_region),
|
|
82
|
+
)
|
|
83
|
+
return InstanceSettings(
|
|
84
|
+
id=UUID(store.id),
|
|
85
|
+
owner=store.owner,
|
|
86
|
+
name=store.name,
|
|
87
|
+
storage=ssettings,
|
|
88
|
+
db=_null_to_value(store.db),
|
|
89
|
+
schema=_null_to_value(store.schema_str),
|
|
90
|
+
git_repo=_null_to_value(store.git_repo),
|
|
91
|
+
keep_artifacts_local=store.keep_artifacts_local, # type: ignore
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def setup_user_from_store(store: UserSettingsStore) -> UserSettings:
|
|
96
|
+
settings = UserSettings()
|
|
97
|
+
settings.email = _null_to_value(store.email)
|
|
98
|
+
settings.password = _null_to_value(store.password)
|
|
99
|
+
settings.access_token = store.access_token
|
|
100
|
+
settings.api_key = _null_to_value(store.api_key)
|
|
101
|
+
settings.uid = store.uid
|
|
102
|
+
settings.handle = _null_to_value(store.handle, value="anonymous")
|
|
103
|
+
settings.name = _null_to_value(store.name)
|
|
104
|
+
settings._uuid = UUID(store.uuid) if store.uuid != "null" else None
|
|
105
|
+
return settings
|
|
@@ -1,81 +1,81 @@
|
|
|
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
|
-
user_settings_file_email,
|
|
12
|
-
user_settings_file_handle,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
if TYPE_CHECKING:
|
|
16
|
-
from ._settings_user import UserSettings
|
|
17
|
-
from .upath import UPath
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def save_user_settings(settings: UserSettings):
|
|
21
|
-
type_hints = get_type_hints(UserSettingsStore)
|
|
22
|
-
prefix = "lamin_user_"
|
|
23
|
-
save_settings(settings, current_user_settings_file(), type_hints, prefix)
|
|
24
|
-
if settings.email is not None:
|
|
25
|
-
save_settings(
|
|
26
|
-
settings, user_settings_file_email(settings.email), type_hints, prefix
|
|
27
|
-
)
|
|
28
|
-
if settings.handle is not None and settings.handle != "anonymous":
|
|
29
|
-
save_settings(
|
|
30
|
-
settings, user_settings_file_handle(settings.handle), type_hints, prefix
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def save_settings(
|
|
35
|
-
settings: Any,
|
|
36
|
-
settings_file: Path,
|
|
37
|
-
type_hints: dict[str, Any],
|
|
38
|
-
prefix: str,
|
|
39
|
-
):
|
|
40
|
-
with open(settings_file, "w") as f:
|
|
41
|
-
for store_key, type in type_hints.items():
|
|
42
|
-
if type == Optional[str]:
|
|
43
|
-
type = str
|
|
44
|
-
if type == Optional[bool]:
|
|
45
|
-
type = bool
|
|
46
|
-
if "__" not in store_key:
|
|
47
|
-
if store_key == "model_config":
|
|
48
|
-
continue
|
|
49
|
-
if store_key == "storage_root":
|
|
50
|
-
value = settings.storage.root_as_str
|
|
51
|
-
elif store_key == "storage_region":
|
|
52
|
-
value = settings.storage.region
|
|
53
|
-
else:
|
|
54
|
-
if store_key in {"db", "schema_str", "name_", "uuid", "id"}:
|
|
55
|
-
settings_key = f"_{store_key.rstrip('_')}"
|
|
56
|
-
else:
|
|
57
|
-
settings_key = store_key
|
|
58
|
-
value = getattr(settings, settings_key, None)
|
|
59
|
-
if value is None:
|
|
60
|
-
value = "null"
|
|
61
|
-
elif isinstance(value, UUID):
|
|
62
|
-
value = value.hex
|
|
63
|
-
else:
|
|
64
|
-
value = type(value)
|
|
65
|
-
f.write(f"{prefix}{store_key}={value}\n")
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def save_instance_settings(settings: Any, settings_file: Path):
|
|
69
|
-
type_hints = get_type_hints(InstanceSettingsStore)
|
|
70
|
-
prefix = "lamindb_instance_"
|
|
71
|
-
save_settings(settings, settings_file, type_hints, prefix)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def save_system_storage_settings(
|
|
75
|
-
cache_path: str | Path | UPath | None, settings_file: Path
|
|
76
|
-
):
|
|
77
|
-
cache_path = "null" if cache_path is None else cache_path
|
|
78
|
-
if isinstance(cache_path, Path): # also True for UPath
|
|
79
|
-
cache_path = cache_path.as_posix()
|
|
80
|
-
with open(settings_file, "w") as f:
|
|
81
|
-
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
|
+
user_settings_file_email,
|
|
12
|
+
user_settings_file_handle,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from ._settings_user import UserSettings
|
|
17
|
+
from .upath import UPath
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def save_user_settings(settings: UserSettings):
|
|
21
|
+
type_hints = get_type_hints(UserSettingsStore)
|
|
22
|
+
prefix = "lamin_user_"
|
|
23
|
+
save_settings(settings, current_user_settings_file(), type_hints, prefix)
|
|
24
|
+
if settings.email is not None:
|
|
25
|
+
save_settings(
|
|
26
|
+
settings, user_settings_file_email(settings.email), type_hints, prefix
|
|
27
|
+
)
|
|
28
|
+
if settings.handle is not None and settings.handle != "anonymous":
|
|
29
|
+
save_settings(
|
|
30
|
+
settings, user_settings_file_handle(settings.handle), type_hints, prefix
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def save_settings(
|
|
35
|
+
settings: Any,
|
|
36
|
+
settings_file: Path,
|
|
37
|
+
type_hints: dict[str, Any],
|
|
38
|
+
prefix: str,
|
|
39
|
+
):
|
|
40
|
+
with open(settings_file, "w") as f:
|
|
41
|
+
for store_key, type in type_hints.items():
|
|
42
|
+
if type == Optional[str]:
|
|
43
|
+
type = str
|
|
44
|
+
if type == Optional[bool]:
|
|
45
|
+
type = bool
|
|
46
|
+
if "__" not in store_key:
|
|
47
|
+
if store_key == "model_config":
|
|
48
|
+
continue
|
|
49
|
+
if store_key == "storage_root":
|
|
50
|
+
value = settings.storage.root_as_str
|
|
51
|
+
elif store_key == "storage_region":
|
|
52
|
+
value = settings.storage.region
|
|
53
|
+
else:
|
|
54
|
+
if store_key in {"db", "schema_str", "name_", "uuid", "id"}:
|
|
55
|
+
settings_key = f"_{store_key.rstrip('_')}"
|
|
56
|
+
else:
|
|
57
|
+
settings_key = store_key
|
|
58
|
+
value = getattr(settings, settings_key, None)
|
|
59
|
+
if value is None:
|
|
60
|
+
value = "null"
|
|
61
|
+
elif isinstance(value, UUID):
|
|
62
|
+
value = value.hex
|
|
63
|
+
else:
|
|
64
|
+
value = type(value)
|
|
65
|
+
f.write(f"{prefix}{store_key}={value}\n")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def save_instance_settings(settings: Any, settings_file: Path):
|
|
69
|
+
type_hints = get_type_hints(InstanceSettingsStore)
|
|
70
|
+
prefix = "lamindb_instance_"
|
|
71
|
+
save_settings(settings, settings_file, type_hints, prefix)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def save_system_storage_settings(
|
|
75
|
+
cache_path: str | Path | UPath | None, settings_file: Path
|
|
76
|
+
):
|
|
77
|
+
cache_path = "null" if cache_path is None else cache_path
|
|
78
|
+
if isinstance(cache_path, Path): # also True for UPath
|
|
79
|
+
cache_path = cache_path.as_posix()
|
|
80
|
+
with open(settings_file, "w") as f:
|
|
81
|
+
f.write(f"lamindb_cache_path={cache_path}")
|