lamindb_setup 1.8.3__py3-none-any.whl → 1.9.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 +166 -166
- lamindb_setup/_connect_instance.py +328 -342
- lamindb_setup/_delete.py +141 -141
- lamindb_setup/_disconnect.py +32 -32
- lamindb_setup/_init_instance.py +440 -440
- lamindb_setup/_migrate.py +266 -259
- lamindb_setup/_register_instance.py +35 -35
- lamindb_setup/_schema_metadata.py +441 -441
- lamindb_setup/_set_managed_storage.py +70 -70
- lamindb_setup/_setup_user.py +133 -133
- lamindb_setup/core/__init__.py +21 -21
- lamindb_setup/core/_aws_options.py +223 -211
- lamindb_setup/core/_hub_client.py +248 -243
- lamindb_setup/core/_hub_core.py +665 -663
- lamindb_setup/core/_hub_crud.py +227 -227
- lamindb_setup/core/_private_django_api.py +83 -83
- lamindb_setup/core/_settings.py +377 -364
- lamindb_setup/core/_settings_instance.py +569 -568
- lamindb_setup/core/_settings_load.py +141 -141
- lamindb_setup/core/_settings_save.py +95 -95
- lamindb_setup/core/_settings_storage.py +429 -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 +305 -291
- 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 -1009
- lamindb_setup/errors.py +70 -70
- lamindb_setup/types.py +20 -20
- {lamindb_setup-1.8.3.dist-info → lamindb_setup-1.9.1.dist-info}/METADATA +1 -1
- lamindb_setup-1.9.1.dist-info/RECORD +50 -0
- lamindb_setup-1.8.3.dist-info/RECORD +0 -50
- {lamindb_setup-1.8.3.dist-info → lamindb_setup-1.9.1.dist-info}/LICENSE +0 -0
- {lamindb_setup-1.8.3.dist-info → lamindb_setup-1.9.1.dist-info}/WHEEL +0 -0
lamindb_setup/_check_setup.py
CHANGED
|
@@ -1,166 +1,166 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import functools
|
|
4
|
-
import importlib as il
|
|
5
|
-
import inspect
|
|
6
|
-
import os
|
|
7
|
-
from typing import TYPE_CHECKING
|
|
8
|
-
|
|
9
|
-
from lamin_utils import logger
|
|
10
|
-
|
|
11
|
-
from ._silence_loggers import silence_loggers
|
|
12
|
-
from .core import django as django_lamin
|
|
13
|
-
from .core._settings import settings
|
|
14
|
-
from .core._settings_store import current_instance_settings_file
|
|
15
|
-
from .errors import (
|
|
16
|
-
MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE,
|
|
17
|
-
InstanceNotSetupError,
|
|
18
|
-
ModuleWasntConfigured,
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
if TYPE_CHECKING:
|
|
22
|
-
from collections.abc import Callable
|
|
23
|
-
|
|
24
|
-
from .core._settings_instance import InstanceSettings
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
CURRENT_ISETTINGS: InstanceSettings | None = None
|
|
28
|
-
IS_LOADING: bool = False
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
# decorator to disable auto-connect when importing a module such as lamindb
|
|
32
|
-
def disable_auto_connect(func: Callable):
|
|
33
|
-
@functools.wraps(func)
|
|
34
|
-
def wrapper(*args, **kwargs):
|
|
35
|
-
global IS_LOADING
|
|
36
|
-
IS_LOADING = True
|
|
37
|
-
try:
|
|
38
|
-
return func(*args, **kwargs)
|
|
39
|
-
finally:
|
|
40
|
-
IS_LOADING = False
|
|
41
|
-
|
|
42
|
-
return wrapper
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def _get_current_instance_settings() -> InstanceSettings | None:
|
|
46
|
-
global CURRENT_ISETTINGS
|
|
47
|
-
|
|
48
|
-
if CURRENT_ISETTINGS is not None:
|
|
49
|
-
return CURRENT_ISETTINGS
|
|
50
|
-
if current_instance_settings_file().exists():
|
|
51
|
-
from .core._settings_load import load_instance_settings
|
|
52
|
-
|
|
53
|
-
try:
|
|
54
|
-
isettings = load_instance_settings()
|
|
55
|
-
except Exception as e:
|
|
56
|
-
# user will get more detailed traceback once they run the CLI
|
|
57
|
-
logger.error(
|
|
58
|
-
"Current instance cannot be reached, disconnect from it: `lamin disconnect`\n"
|
|
59
|
-
"Alternatively, init or load a connectable instance on the"
|
|
60
|
-
" command line: `lamin connect <instance>` or `lamin init <...>`"
|
|
61
|
-
)
|
|
62
|
-
raise e
|
|
63
|
-
return isettings
|
|
64
|
-
else:
|
|
65
|
-
return None
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def _normalize_module_name(module_name: str) -> str:
|
|
69
|
-
return module_name.replace("lnschema_", "").replace("_", "-")
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# checks that the provided modules is in the modules of the provided instance
|
|
73
|
-
# or in the apps setup by django
|
|
74
|
-
def _check_module_in_instance_modules(
|
|
75
|
-
module: str, isettings: InstanceSettings | None = None
|
|
76
|
-
) -> None:
|
|
77
|
-
if isettings is not None:
|
|
78
|
-
modules_raw = isettings.modules
|
|
79
|
-
modules = set(modules_raw).union(
|
|
80
|
-
_normalize_module_name(module) for module in modules_raw
|
|
81
|
-
)
|
|
82
|
-
if _normalize_module_name(module) not in modules and module not in modules:
|
|
83
|
-
raise ModuleWasntConfigured(
|
|
84
|
-
MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE.format(module)
|
|
85
|
-
)
|
|
86
|
-
else:
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
from django.apps import apps
|
|
90
|
-
|
|
91
|
-
for app in apps.get_app_configs():
|
|
92
|
-
# app.name is always unnormalized module (python package) name
|
|
93
|
-
if module == app.name or module == _normalize_module_name(app.name):
|
|
94
|
-
return
|
|
95
|
-
raise ModuleWasntConfigured(MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE.format(module))
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
# infer the name of the module that calls this function
|
|
99
|
-
def _infer_callers_module_name() -> str | None:
|
|
100
|
-
stack = inspect.stack()
|
|
101
|
-
if len(stack) < 3:
|
|
102
|
-
return None
|
|
103
|
-
module = inspect.getmodule(stack[2][0])
|
|
104
|
-
return module.__name__.partition(".")[0] if module is not None else None
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
# we make this a private function because in all the places it's used,
|
|
108
|
-
# users should not see it
|
|
109
|
-
def _check_instance_setup(from_module: str | None = None) -> bool:
|
|
110
|
-
if django_lamin.IS_SETUP:
|
|
111
|
-
# reload logic here because module might not yet have been imported
|
|
112
|
-
# upon first setup
|
|
113
|
-
if from_module is not None:
|
|
114
|
-
if from_module != "lamindb":
|
|
115
|
-
_check_module_in_instance_modules(from_module)
|
|
116
|
-
il.reload(il.import_module(from_module))
|
|
117
|
-
else:
|
|
118
|
-
infer_module = _infer_callers_module_name()
|
|
119
|
-
if infer_module is not None and infer_module not in {
|
|
120
|
-
"lamindb",
|
|
121
|
-
"lamindb_setup",
|
|
122
|
-
"lamin_cli",
|
|
123
|
-
}:
|
|
124
|
-
_check_module_in_instance_modules(infer_module)
|
|
125
|
-
return True
|
|
126
|
-
silence_loggers()
|
|
127
|
-
if os.environ.get("LAMINDB_MULTI_INSTANCE") == "true":
|
|
128
|
-
logger.warning(
|
|
129
|
-
"running LaminDB in multi-instance mode; you'll experience "
|
|
130
|
-
"errors in regular lamindb usage"
|
|
131
|
-
)
|
|
132
|
-
return True
|
|
133
|
-
isettings = _get_current_instance_settings()
|
|
134
|
-
if isettings is not None:
|
|
135
|
-
if (
|
|
136
|
-
from_module is not None
|
|
137
|
-
and settings.auto_connect
|
|
138
|
-
and not django_lamin.IS_SETUP
|
|
139
|
-
and not IS_LOADING
|
|
140
|
-
):
|
|
141
|
-
if from_module != "lamindb":
|
|
142
|
-
_check_module_in_instance_modules(from_module, isettings)
|
|
143
|
-
|
|
144
|
-
import lamindb
|
|
145
|
-
|
|
146
|
-
il.reload(il.import_module(from_module))
|
|
147
|
-
else:
|
|
148
|
-
django_lamin.setup_django(isettings)
|
|
149
|
-
logger.important(f"connected lamindb: {isettings.slug}")
|
|
150
|
-
settings._instance_settings = (
|
|
151
|
-
isettings # update of local storage location
|
|
152
|
-
)
|
|
153
|
-
return django_lamin.IS_SETUP
|
|
154
|
-
else:
|
|
155
|
-
if from_module is not None and settings.auto_connect:
|
|
156
|
-
# the below enables users to auto-connect to an instance
|
|
157
|
-
# simply by setting an environment variable, bypassing the
|
|
158
|
-
# need of calling connect() manually
|
|
159
|
-
if os.environ.get("LAMIN_CURRENT_INSTANCE") is not None:
|
|
160
|
-
from ._connect_instance import connect
|
|
161
|
-
|
|
162
|
-
connect(_write_settings=False, _reload_lamindb=False)
|
|
163
|
-
return django_lamin.IS_SETUP
|
|
164
|
-
else:
|
|
165
|
-
logger.warning(InstanceNotSetupError.default_message)
|
|
166
|
-
return False
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import functools
|
|
4
|
+
import importlib as il
|
|
5
|
+
import inspect
|
|
6
|
+
import os
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
8
|
+
|
|
9
|
+
from lamin_utils import logger
|
|
10
|
+
|
|
11
|
+
from ._silence_loggers import silence_loggers
|
|
12
|
+
from .core import django as django_lamin
|
|
13
|
+
from .core._settings import settings
|
|
14
|
+
from .core._settings_store import current_instance_settings_file
|
|
15
|
+
from .errors import (
|
|
16
|
+
MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE,
|
|
17
|
+
InstanceNotSetupError,
|
|
18
|
+
ModuleWasntConfigured,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
if TYPE_CHECKING:
|
|
22
|
+
from collections.abc import Callable
|
|
23
|
+
|
|
24
|
+
from .core._settings_instance import InstanceSettings
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
CURRENT_ISETTINGS: InstanceSettings | None = None
|
|
28
|
+
IS_LOADING: bool = False
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# decorator to disable auto-connect when importing a module such as lamindb
|
|
32
|
+
def disable_auto_connect(func: Callable):
|
|
33
|
+
@functools.wraps(func)
|
|
34
|
+
def wrapper(*args, **kwargs):
|
|
35
|
+
global IS_LOADING
|
|
36
|
+
IS_LOADING = True
|
|
37
|
+
try:
|
|
38
|
+
return func(*args, **kwargs)
|
|
39
|
+
finally:
|
|
40
|
+
IS_LOADING = False
|
|
41
|
+
|
|
42
|
+
return wrapper
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _get_current_instance_settings() -> InstanceSettings | None:
|
|
46
|
+
global CURRENT_ISETTINGS
|
|
47
|
+
|
|
48
|
+
if CURRENT_ISETTINGS is not None:
|
|
49
|
+
return CURRENT_ISETTINGS
|
|
50
|
+
if current_instance_settings_file().exists():
|
|
51
|
+
from .core._settings_load import load_instance_settings
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
isettings = load_instance_settings()
|
|
55
|
+
except Exception as e:
|
|
56
|
+
# user will get more detailed traceback once they run the CLI
|
|
57
|
+
logger.error(
|
|
58
|
+
"Current instance cannot be reached, disconnect from it: `lamin disconnect`\n"
|
|
59
|
+
"Alternatively, init or load a connectable instance on the"
|
|
60
|
+
" command line: `lamin connect <instance>` or `lamin init <...>`"
|
|
61
|
+
)
|
|
62
|
+
raise e
|
|
63
|
+
return isettings
|
|
64
|
+
else:
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _normalize_module_name(module_name: str) -> str:
|
|
69
|
+
return module_name.replace("lnschema_", "").replace("_", "-")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# checks that the provided modules is in the modules of the provided instance
|
|
73
|
+
# or in the apps setup by django
|
|
74
|
+
def _check_module_in_instance_modules(
|
|
75
|
+
module: str, isettings: InstanceSettings | None = None
|
|
76
|
+
) -> None:
|
|
77
|
+
if isettings is not None:
|
|
78
|
+
modules_raw = isettings.modules
|
|
79
|
+
modules = set(modules_raw).union(
|
|
80
|
+
_normalize_module_name(module) for module in modules_raw
|
|
81
|
+
)
|
|
82
|
+
if _normalize_module_name(module) not in modules and module not in modules:
|
|
83
|
+
raise ModuleWasntConfigured(
|
|
84
|
+
MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE.format(module)
|
|
85
|
+
)
|
|
86
|
+
else:
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
from django.apps import apps
|
|
90
|
+
|
|
91
|
+
for app in apps.get_app_configs():
|
|
92
|
+
# app.name is always unnormalized module (python package) name
|
|
93
|
+
if module == app.name or module == _normalize_module_name(app.name):
|
|
94
|
+
return
|
|
95
|
+
raise ModuleWasntConfigured(MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE.format(module))
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# infer the name of the module that calls this function
|
|
99
|
+
def _infer_callers_module_name() -> str | None:
|
|
100
|
+
stack = inspect.stack()
|
|
101
|
+
if len(stack) < 3:
|
|
102
|
+
return None
|
|
103
|
+
module = inspect.getmodule(stack[2][0])
|
|
104
|
+
return module.__name__.partition(".")[0] if module is not None else None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# we make this a private function because in all the places it's used,
|
|
108
|
+
# users should not see it
|
|
109
|
+
def _check_instance_setup(from_module: str | None = None) -> bool:
|
|
110
|
+
if django_lamin.IS_SETUP:
|
|
111
|
+
# reload logic here because module might not yet have been imported
|
|
112
|
+
# upon first setup
|
|
113
|
+
if from_module is not None:
|
|
114
|
+
if from_module != "lamindb":
|
|
115
|
+
_check_module_in_instance_modules(from_module)
|
|
116
|
+
il.reload(il.import_module(from_module))
|
|
117
|
+
else:
|
|
118
|
+
infer_module = _infer_callers_module_name()
|
|
119
|
+
if infer_module is not None and infer_module not in {
|
|
120
|
+
"lamindb",
|
|
121
|
+
"lamindb_setup",
|
|
122
|
+
"lamin_cli",
|
|
123
|
+
}:
|
|
124
|
+
_check_module_in_instance_modules(infer_module)
|
|
125
|
+
return True
|
|
126
|
+
silence_loggers()
|
|
127
|
+
if os.environ.get("LAMINDB_MULTI_INSTANCE") == "true":
|
|
128
|
+
logger.warning(
|
|
129
|
+
"running LaminDB in multi-instance mode; you'll experience "
|
|
130
|
+
"errors in regular lamindb usage"
|
|
131
|
+
)
|
|
132
|
+
return True
|
|
133
|
+
isettings = _get_current_instance_settings()
|
|
134
|
+
if isettings is not None:
|
|
135
|
+
if (
|
|
136
|
+
from_module is not None
|
|
137
|
+
and settings.auto_connect
|
|
138
|
+
and not django_lamin.IS_SETUP
|
|
139
|
+
and not IS_LOADING
|
|
140
|
+
):
|
|
141
|
+
if from_module != "lamindb":
|
|
142
|
+
_check_module_in_instance_modules(from_module, isettings)
|
|
143
|
+
|
|
144
|
+
import lamindb
|
|
145
|
+
|
|
146
|
+
il.reload(il.import_module(from_module))
|
|
147
|
+
else:
|
|
148
|
+
django_lamin.setup_django(isettings)
|
|
149
|
+
logger.important(f"connected lamindb: {isettings.slug}")
|
|
150
|
+
settings._instance_settings = (
|
|
151
|
+
isettings # update of local storage location
|
|
152
|
+
)
|
|
153
|
+
return django_lamin.IS_SETUP
|
|
154
|
+
else:
|
|
155
|
+
if from_module is not None and settings.auto_connect:
|
|
156
|
+
# the below enables users to auto-connect to an instance
|
|
157
|
+
# simply by setting an environment variable, bypassing the
|
|
158
|
+
# need of calling connect() manually
|
|
159
|
+
if os.environ.get("LAMIN_CURRENT_INSTANCE") is not None:
|
|
160
|
+
from ._connect_instance import connect
|
|
161
|
+
|
|
162
|
+
connect(_write_settings=False, _reload_lamindb=False)
|
|
163
|
+
return django_lamin.IS_SETUP
|
|
164
|
+
else:
|
|
165
|
+
logger.warning(InstanceNotSetupError.default_message)
|
|
166
|
+
return False
|