lamindb_setup 0.77.2__py2.py3-none-any.whl → 0.77.3__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 -1
- lamindb_setup/_cache.py +34 -34
- lamindb_setup/_check.py +7 -7
- lamindb_setup/_check_setup.py +79 -79
- lamindb_setup/_close.py +35 -35
- lamindb_setup/_connect_instance.py +444 -444
- lamindb_setup/_delete.py +139 -137
- 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 +374 -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_core.py +590 -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 +138 -138
- lamindb_setup/core/_settings_instance.py +467 -467
- lamindb_setup/core/_settings_load.py +105 -105
- lamindb_setup/core/_settings_save.py +81 -81
- lamindb_setup/core/_settings_storage.py +405 -393
- lamindb_setup/core/_settings_store.py +75 -75
- lamindb_setup/core/_settings_user.py +53 -53
- lamindb_setup/core/_setup_bionty_sources.py +101 -101
- lamindb_setup/core/cloud_sqlite_locker.py +232 -232
- lamindb_setup/core/django.py +114 -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.2.dist-info → lamindb_setup-0.77.3.dist-info}/METADATA +1 -1
- lamindb_setup-0.77.3.dist-info/RECORD +47 -0
- {lamindb_setup-0.77.2.dist-info → lamindb_setup-0.77.3.dist-info}/WHEEL +1 -1
- lamindb_setup-0.77.2.dist-info/RECORD +0 -47
- {lamindb_setup-0.77.2.dist-info → lamindb_setup-0.77.3.dist-info}/LICENSE +0 -0
lamindb_setup/__init__.py
CHANGED
lamindb_setup/_cache.py
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import shutil
|
|
4
|
-
|
|
5
|
-
from lamin_utils import logger
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def clear_cache_dir():
|
|
9
|
-
from lamindb_setup import close, settings
|
|
10
|
-
|
|
11
|
-
if settings.instance._is_cloud_sqlite:
|
|
12
|
-
logger.warning(
|
|
13
|
-
"Closing the current instance to update the cloud sqlite database."
|
|
14
|
-
)
|
|
15
|
-
close()
|
|
16
|
-
|
|
17
|
-
cache_dir = settings.storage.cache_dir
|
|
18
|
-
shutil.rmtree(cache_dir)
|
|
19
|
-
cache_dir.mkdir()
|
|
20
|
-
logger.success("The cache directory was cleared.")
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def get_cache_dir():
|
|
24
|
-
from lamindb_setup import settings
|
|
25
|
-
|
|
26
|
-
return settings.storage.cache_dir.as_posix()
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def set_cache_dir(cache_dir: str):
|
|
30
|
-
from lamindb_setup import settings
|
|
31
|
-
|
|
32
|
-
settings.storage.cache_dir = cache_dir
|
|
33
|
-
cache_str = settings.storage.cache_dir.as_posix() # type: ignore
|
|
34
|
-
logger.success(f"The cache directory was set to {cache_str}.")
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import shutil
|
|
4
|
+
|
|
5
|
+
from lamin_utils import logger
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def clear_cache_dir():
|
|
9
|
+
from lamindb_setup import close, settings
|
|
10
|
+
|
|
11
|
+
if settings.instance._is_cloud_sqlite:
|
|
12
|
+
logger.warning(
|
|
13
|
+
"Closing the current instance to update the cloud sqlite database."
|
|
14
|
+
)
|
|
15
|
+
close()
|
|
16
|
+
|
|
17
|
+
cache_dir = settings.storage.cache_dir
|
|
18
|
+
shutil.rmtree(cache_dir)
|
|
19
|
+
cache_dir.mkdir()
|
|
20
|
+
logger.success("The cache directory was cleared.")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_cache_dir():
|
|
24
|
+
from lamindb_setup import settings
|
|
25
|
+
|
|
26
|
+
return settings.storage.cache_dir.as_posix()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def set_cache_dir(cache_dir: str):
|
|
30
|
+
from lamindb_setup import settings
|
|
31
|
+
|
|
32
|
+
settings.storage.cache_dir = cache_dir
|
|
33
|
+
cache_str = settings.storage.cache_dir.as_posix() # type: ignore
|
|
34
|
+
logger.success(f"The cache directory was set to {cache_str}.")
|
lamindb_setup/_check.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def check():
|
|
5
|
-
from django.core.management import call_command
|
|
6
|
-
|
|
7
|
-
call_command("check")
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def check():
|
|
5
|
+
from django.core.management import call_command
|
|
6
|
+
|
|
7
|
+
call_command("check")
|
lamindb_setup/_check_setup.py
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
from typing import TYPE_CHECKING, Optional
|
|
5
|
-
|
|
6
|
-
from lamin_utils import logger
|
|
7
|
-
|
|
8
|
-
from ._silence_loggers import silence_loggers
|
|
9
|
-
from .core import django
|
|
10
|
-
from .core._settings import settings
|
|
11
|
-
from .core._settings_store import current_instance_settings_file
|
|
12
|
-
from .core.exceptions import DefaultMessageException
|
|
13
|
-
|
|
14
|
-
if TYPE_CHECKING:
|
|
15
|
-
from .core._settings_instance import InstanceSettings
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class InstanceNotSetupError(DefaultMessageException):
|
|
19
|
-
default_message = """\
|
|
20
|
-
To use lamindb, you need to connect to an instance.
|
|
21
|
-
|
|
22
|
-
Connect to an instance: `ln.connect()`. Init an instance: `ln.setup.init()`.
|
|
23
|
-
|
|
24
|
-
If you used the CLI to set up lamindb in a notebook, restart the Python session.
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
CURRENT_ISETTINGS: InstanceSettings | None = None
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def _get_current_instance_settings() -> InstanceSettings | None:
|
|
32
|
-
global CURRENT_ISETTINGS
|
|
33
|
-
|
|
34
|
-
if CURRENT_ISETTINGS is not None:
|
|
35
|
-
return CURRENT_ISETTINGS
|
|
36
|
-
if current_instance_settings_file().exists():
|
|
37
|
-
from .core._settings_load import load_instance_settings
|
|
38
|
-
|
|
39
|
-
try:
|
|
40
|
-
isettings = load_instance_settings()
|
|
41
|
-
except Exception as e:
|
|
42
|
-
# user will get more detailed traceback once they run the CLI
|
|
43
|
-
logger.error(
|
|
44
|
-
"Current instance cannot be reached,
|
|
45
|
-
"Alternatively, init or load a connectable instance on the"
|
|
46
|
-
" command line: `lamin load <instance>` or `lamin init <...>`"
|
|
47
|
-
)
|
|
48
|
-
raise e
|
|
49
|
-
return isettings
|
|
50
|
-
else:
|
|
51
|
-
return None
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
# we make this a private function because in all the places it's used,
|
|
55
|
-
# users should see it
|
|
56
|
-
def _check_instance_setup(from_lamindb: bool = False) -> bool:
|
|
57
|
-
if django.IS_SETUP:
|
|
58
|
-
return True
|
|
59
|
-
silence_loggers()
|
|
60
|
-
if os.environ.get("LAMINDB_MULTI_INSTANCE") == "true":
|
|
61
|
-
logger.warning(
|
|
62
|
-
"running LaminDB in multi-instance mode; you'll experience "
|
|
63
|
-
"errors in regular lamindb usage"
|
|
64
|
-
)
|
|
65
|
-
return True
|
|
66
|
-
isettings = _get_current_instance_settings()
|
|
67
|
-
if isettings is not None:
|
|
68
|
-
if from_lamindb and settings.auto_connect:
|
|
69
|
-
if not django.IS_SETUP:
|
|
70
|
-
from ._init_instance import reload_schema_modules
|
|
71
|
-
|
|
72
|
-
django.setup_django(isettings)
|
|
73
|
-
reload_schema_modules(isettings)
|
|
74
|
-
logger.important(f"connected lamindb: {isettings.slug}")
|
|
75
|
-
return django.IS_SETUP
|
|
76
|
-
else:
|
|
77
|
-
if from_lamindb and settings.auto_connect:
|
|
78
|
-
logger.warning(InstanceNotSetupError.default_message)
|
|
79
|
-
return False
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from typing import TYPE_CHECKING, Optional
|
|
5
|
+
|
|
6
|
+
from lamin_utils import logger
|
|
7
|
+
|
|
8
|
+
from ._silence_loggers import silence_loggers
|
|
9
|
+
from .core import django
|
|
10
|
+
from .core._settings import settings
|
|
11
|
+
from .core._settings_store import current_instance_settings_file
|
|
12
|
+
from .core.exceptions import DefaultMessageException
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from .core._settings_instance import InstanceSettings
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class InstanceNotSetupError(DefaultMessageException):
|
|
19
|
+
default_message = """\
|
|
20
|
+
To use lamindb, you need to connect to an instance.
|
|
21
|
+
|
|
22
|
+
Connect to an instance: `ln.connect()`. Init an instance: `ln.setup.init()`.
|
|
23
|
+
|
|
24
|
+
If you used the CLI to set up lamindb in a notebook, restart the Python session.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
CURRENT_ISETTINGS: InstanceSettings | None = None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _get_current_instance_settings() -> InstanceSettings | None:
|
|
32
|
+
global CURRENT_ISETTINGS
|
|
33
|
+
|
|
34
|
+
if CURRENT_ISETTINGS is not None:
|
|
35
|
+
return CURRENT_ISETTINGS
|
|
36
|
+
if current_instance_settings_file().exists():
|
|
37
|
+
from .core._settings_load import load_instance_settings
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
isettings = load_instance_settings()
|
|
41
|
+
except Exception as e:
|
|
42
|
+
# user will get more detailed traceback once they run the CLI
|
|
43
|
+
logger.error(
|
|
44
|
+
"Current instance cannot be reached, unload it: `lamin load --unload`\n"
|
|
45
|
+
"Alternatively, init or load a connectable instance on the"
|
|
46
|
+
" command line: `lamin load <instance>` or `lamin init <...>`"
|
|
47
|
+
)
|
|
48
|
+
raise e
|
|
49
|
+
return isettings
|
|
50
|
+
else:
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# we make this a private function because in all the places it's used,
|
|
55
|
+
# users should see it
|
|
56
|
+
def _check_instance_setup(from_lamindb: bool = False) -> bool:
|
|
57
|
+
if django.IS_SETUP:
|
|
58
|
+
return True
|
|
59
|
+
silence_loggers()
|
|
60
|
+
if os.environ.get("LAMINDB_MULTI_INSTANCE") == "true":
|
|
61
|
+
logger.warning(
|
|
62
|
+
"running LaminDB in multi-instance mode; you'll experience "
|
|
63
|
+
"errors in regular lamindb usage"
|
|
64
|
+
)
|
|
65
|
+
return True
|
|
66
|
+
isettings = _get_current_instance_settings()
|
|
67
|
+
if isettings is not None:
|
|
68
|
+
if from_lamindb and settings.auto_connect:
|
|
69
|
+
if not django.IS_SETUP:
|
|
70
|
+
from ._init_instance import reload_schema_modules
|
|
71
|
+
|
|
72
|
+
django.setup_django(isettings)
|
|
73
|
+
reload_schema_modules(isettings)
|
|
74
|
+
logger.important(f"connected lamindb: {isettings.slug}")
|
|
75
|
+
return django.IS_SETUP
|
|
76
|
+
else:
|
|
77
|
+
if from_lamindb and settings.auto_connect:
|
|
78
|
+
logger.warning(InstanceNotSetupError.default_message)
|
|
79
|
+
return False
|
lamindb_setup/_close.py
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from lamin_utils import logger
|
|
4
|
-
|
|
5
|
-
from .core._settings import settings
|
|
6
|
-
from .core._settings_store import current_instance_settings_file
|
|
7
|
-
from .core._setup_bionty_sources import delete_bionty_sources_yaml
|
|
8
|
-
from .core.cloud_sqlite_locker import clear_locker
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def close(mute: bool = False) -> None:
|
|
12
|
-
"""Close existing instance.
|
|
13
|
-
|
|
14
|
-
Returns `None` if succeeds, otherwise an exception is raised.
|
|
15
|
-
"""
|
|
16
|
-
if current_instance_settings_file().exists():
|
|
17
|
-
instance = settings.instance.slug
|
|
18
|
-
try:
|
|
19
|
-
settings.instance._update_cloud_sqlite_file()
|
|
20
|
-
except Exception as e:
|
|
21
|
-
if isinstance(e, FileNotFoundError):
|
|
22
|
-
logger.warning("did not find local cache file")
|
|
23
|
-
elif isinstance(e, PermissionError):
|
|
24
|
-
logger.warning("did not upload cache file - not enough permissions")
|
|
25
|
-
else:
|
|
26
|
-
raise e
|
|
27
|
-
if "bionty" in settings.instance.schema:
|
|
28
|
-
delete_bionty_sources_yaml()
|
|
29
|
-
current_instance_settings_file().unlink()
|
|
30
|
-
clear_locker()
|
|
31
|
-
if not mute:
|
|
32
|
-
logger.success(f"closed instance: {instance}")
|
|
33
|
-
else:
|
|
34
|
-
if not mute:
|
|
35
|
-
logger.info("no instance loaded")
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from lamin_utils import logger
|
|
4
|
+
|
|
5
|
+
from .core._settings import settings
|
|
6
|
+
from .core._settings_store import current_instance_settings_file
|
|
7
|
+
from .core._setup_bionty_sources import delete_bionty_sources_yaml
|
|
8
|
+
from .core.cloud_sqlite_locker import clear_locker
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def close(mute: bool = False) -> None:
|
|
12
|
+
"""Close existing instance.
|
|
13
|
+
|
|
14
|
+
Returns `None` if succeeds, otherwise an exception is raised.
|
|
15
|
+
"""
|
|
16
|
+
if current_instance_settings_file().exists():
|
|
17
|
+
instance = settings.instance.slug
|
|
18
|
+
try:
|
|
19
|
+
settings.instance._update_cloud_sqlite_file()
|
|
20
|
+
except Exception as e:
|
|
21
|
+
if isinstance(e, FileNotFoundError):
|
|
22
|
+
logger.warning("did not find local cache file")
|
|
23
|
+
elif isinstance(e, PermissionError):
|
|
24
|
+
logger.warning("did not upload cache file - not enough permissions")
|
|
25
|
+
else:
|
|
26
|
+
raise e
|
|
27
|
+
if "bionty" in settings.instance.schema:
|
|
28
|
+
delete_bionty_sources_yaml()
|
|
29
|
+
current_instance_settings_file().unlink()
|
|
30
|
+
clear_locker()
|
|
31
|
+
if not mute:
|
|
32
|
+
logger.success(f"closed instance: {instance}")
|
|
33
|
+
else:
|
|
34
|
+
if not mute:
|
|
35
|
+
logger.info("no instance loaded")
|