lamindb_setup 1.18.2__py3-none-any.whl → 1.19.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.
Files changed (50) hide show
  1. lamindb_setup/__init__.py +4 -19
  2. lamindb_setup/_cache.py +87 -87
  3. lamindb_setup/_check.py +7 -7
  4. lamindb_setup/_check_setup.py +131 -131
  5. lamindb_setup/_connect_instance.py +443 -438
  6. lamindb_setup/_delete.py +155 -151
  7. lamindb_setup/_disconnect.py +38 -38
  8. lamindb_setup/_django.py +39 -39
  9. lamindb_setup/_entry_points.py +19 -19
  10. lamindb_setup/_init_instance.py +423 -429
  11. lamindb_setup/_migrate.py +331 -327
  12. lamindb_setup/_register_instance.py +32 -32
  13. lamindb_setup/_schema.py +27 -27
  14. lamindb_setup/_schema_metadata.py +451 -451
  15. lamindb_setup/_set_managed_storage.py +81 -80
  16. lamindb_setup/_setup_user.py +198 -198
  17. lamindb_setup/_silence_loggers.py +46 -46
  18. lamindb_setup/core/__init__.py +25 -34
  19. lamindb_setup/core/_aws_options.py +276 -266
  20. lamindb_setup/core/_aws_storage.py +57 -55
  21. lamindb_setup/core/_clone.py +50 -50
  22. lamindb_setup/core/_deprecated.py +62 -62
  23. lamindb_setup/core/_docs.py +14 -14
  24. lamindb_setup/core/_hub_client.py +288 -294
  25. lamindb_setup/core/_hub_core.py +0 -2
  26. lamindb_setup/core/_hub_crud.py +247 -247
  27. lamindb_setup/core/_hub_utils.py +100 -100
  28. lamindb_setup/core/_private_django_api.py +80 -80
  29. lamindb_setup/core/_settings.py +440 -434
  30. lamindb_setup/core/_settings_instance.py +32 -7
  31. lamindb_setup/core/_settings_load.py +162 -159
  32. lamindb_setup/core/_settings_save.py +108 -96
  33. lamindb_setup/core/_settings_storage.py +433 -433
  34. lamindb_setup/core/_settings_store.py +162 -92
  35. lamindb_setup/core/_settings_user.py +55 -55
  36. lamindb_setup/core/_setup_bionty_sources.py +44 -44
  37. lamindb_setup/core/cloud_sqlite_locker.py +240 -240
  38. lamindb_setup/core/django.py +414 -413
  39. lamindb_setup/core/exceptions.py +1 -1
  40. lamindb_setup/core/hashing.py +134 -134
  41. lamindb_setup/core/types.py +1 -1
  42. lamindb_setup/core/upath.py +1031 -1028
  43. lamindb_setup/errors.py +72 -70
  44. lamindb_setup/io.py +423 -416
  45. lamindb_setup/types.py +17 -17
  46. {lamindb_setup-1.18.2.dist-info → lamindb_setup-1.19.1.dist-info}/METADATA +4 -2
  47. lamindb_setup-1.19.1.dist-info/RECORD +51 -0
  48. {lamindb_setup-1.18.2.dist-info → lamindb_setup-1.19.1.dist-info}/WHEEL +1 -1
  49. {lamindb_setup-1.18.2.dist-info → lamindb_setup-1.19.1.dist-info/licenses}/LICENSE +201 -201
  50. lamindb_setup-1.18.2.dist-info/RECORD +0 -51
lamindb_setup/__init__.py CHANGED
@@ -35,7 +35,7 @@ Migration management
35
35
 
36
36
  """
37
37
 
38
- __version__ = "1.18.2" # denote a release candidate for 0.1.0 with 0.1rc1
38
+ __version__ = "1.19.1" # denote a release candidate for 0.1.0 with 0.1rc1
39
39
 
40
40
  import os
41
41
  import warnings
@@ -48,9 +48,9 @@ warnings.filterwarnings(
48
48
  )
49
49
  warnings.filterwarnings("ignore", category=DeprecationWarning, module="postgrest")
50
50
 
51
- from packaging import version as packaging_version
52
-
53
- from . import core, errors, io, types
51
+ # do not import io by default to reduce import time
52
+ # it's not immediately needed in the default user workflows
53
+ from . import core, errors, types
54
54
  from ._check_setup import _check_instance_setup
55
55
  from ._connect_instance import connect
56
56
  from ._delete import delete
@@ -63,20 +63,6 @@ from ._register_instance import register
63
63
  from ._setup_user import login, logout
64
64
  from .core._settings import settings
65
65
 
66
- # check that the version of s3fs is higher than the lower bound
67
- # needed because spatialdata installs old versions of s3fs
68
- try:
69
- from s3fs import __version__ as s3fs_version
70
-
71
- if packaging_version.parse(s3fs_version) < packaging_version.parse("2023.12.2"):
72
- raise RuntimeError(
73
- f"The version of s3fs you have ({s3fs_version}) is impompatible "
74
- "with lamindb, please upgrade it: pip install s3fs>=2023.12.2"
75
- )
76
- except ImportError:
77
- # might be not installed
78
- pass
79
-
80
66
 
81
67
  def _is_CI_environment() -> bool:
82
68
  ci_env_vars = [
@@ -112,5 +98,4 @@ _call_registered_entry_points("lamindb_setup.on_import")
112
98
 
113
99
  settings.__doc__ = """Global :class:`~lamindb.setup.core.SetupSettings`."""
114
100
 
115
-
116
101
  close = disconnect # backward compatibility
lamindb_setup/_cache.py CHANGED
@@ -1,87 +1,87 @@
1
- from __future__ import annotations
2
-
3
- import shutil
4
- from pathlib import Path
5
-
6
- from dotenv import dotenv_values
7
- from lamin_utils import logger
8
-
9
- from .core._settings_save import save_platform_user_storage_settings
10
- from .core._settings_store import system_settings_file
11
- from .errors import CurrentInstanceNotConfigured
12
-
13
-
14
- def clear_cache_dir():
15
- from lamindb_setup import disconnect, settings
16
-
17
- try:
18
- if settings.instance._is_cloud_sqlite:
19
- logger.warning(
20
- "disconnecting the current instance to update the cloud sqlite database."
21
- )
22
- disconnect()
23
- except CurrentInstanceNotConfigured:
24
- pass
25
-
26
- cache_dir = settings.cache_dir
27
- if cache_dir.exists():
28
- shutil.rmtree(cache_dir)
29
- cache_dir.mkdir()
30
- logger.success("the cache directory was cleared")
31
- else:
32
- logger.warning("the cache directory doesn't exist")
33
-
34
-
35
- def get_cache_dir():
36
- from lamindb_setup import settings
37
-
38
- return settings.cache_dir.as_posix()
39
-
40
-
41
- def set_cache_dir(cache_dir: str):
42
- from lamindb_setup.core._settings import (
43
- DEFAULT_CACHE_DIR,
44
- _process_cache_path,
45
- settings,
46
- )
47
-
48
- old_cache_dir = settings.cache_dir
49
- new_cache_dir = _process_cache_path(cache_dir)
50
-
51
- system_cache_dir = None
52
- if (system_settings := system_settings_file()).exists():
53
- system_cache_dir = dotenv_values(system_settings).get(
54
- "lamindb_cache_path", None
55
- )
56
- system_cache_dir = (
57
- Path(system_cache_dir) if system_cache_dir is not None else None
58
- )
59
-
60
- need_reset = False
61
- if new_cache_dir is None:
62
- need_reset = True
63
- new_cache_dir = (
64
- DEFAULT_CACHE_DIR if system_cache_dir is None else system_cache_dir
65
- )
66
-
67
- if new_cache_dir != old_cache_dir:
68
- if old_cache_dir.exists():
69
- shutil.copytree(old_cache_dir, new_cache_dir, dirs_exist_ok=True)
70
- logger.info(
71
- f"the current cache directory was copied to {new_cache_dir.as_posix()} "
72
- )
73
- if old_cache_dir != system_cache_dir:
74
- shutil.rmtree(old_cache_dir)
75
- logger.info(
76
- f"cleared the old cache directory {old_cache_dir.as_posix()}"
77
- )
78
- else:
79
- logger.info(
80
- f"didn't clear the system cache directory {system_cache_dir.as_posix()}, "
81
- "please clear it manually if you need"
82
- )
83
- else:
84
- new_cache_dir.mkdir(parents=True, exist_ok=True)
85
- new_cache_dir = new_cache_dir.resolve()
86
- save_platform_user_storage_settings(None if need_reset else new_cache_dir)
87
- settings._cache_dir = new_cache_dir
1
+ from __future__ import annotations
2
+
3
+ import shutil
4
+ from pathlib import Path
5
+
6
+ from dotenv import dotenv_values
7
+ from lamin_utils import logger
8
+
9
+ from .core._settings_save import save_platform_user_storage_settings
10
+ from .core._settings_store import system_settings_file
11
+ from .errors import CurrentInstanceNotConfigured
12
+
13
+
14
+ def clear_cache_dir():
15
+ from lamindb_setup import disconnect, settings
16
+
17
+ try:
18
+ if settings.instance._is_cloud_sqlite:
19
+ logger.warning(
20
+ "disconnecting the current instance to update the cloud sqlite database."
21
+ )
22
+ disconnect()
23
+ except CurrentInstanceNotConfigured:
24
+ pass
25
+
26
+ cache_dir = settings.cache_dir
27
+ if cache_dir.exists():
28
+ shutil.rmtree(cache_dir)
29
+ cache_dir.mkdir()
30
+ logger.success("the cache directory was cleared")
31
+ else:
32
+ logger.warning("the cache directory doesn't exist")
33
+
34
+
35
+ def get_cache_dir():
36
+ from lamindb_setup import settings
37
+
38
+ return settings.cache_dir.as_posix()
39
+
40
+
41
+ def set_cache_dir(cache_dir: str):
42
+ from lamindb_setup.core._settings import (
43
+ DEFAULT_CACHE_DIR,
44
+ _process_cache_path,
45
+ settings,
46
+ )
47
+
48
+ old_cache_dir = settings.cache_dir
49
+ new_cache_dir = _process_cache_path(cache_dir)
50
+
51
+ system_cache_dir = None
52
+ if (system_settings := system_settings_file()).exists():
53
+ system_cache_dir = dotenv_values(system_settings).get(
54
+ "lamindb_cache_path", None
55
+ )
56
+ system_cache_dir = (
57
+ Path(system_cache_dir) if system_cache_dir is not None else None
58
+ )
59
+
60
+ need_reset = False
61
+ if new_cache_dir is None:
62
+ need_reset = True
63
+ new_cache_dir = (
64
+ DEFAULT_CACHE_DIR if system_cache_dir is None else system_cache_dir
65
+ )
66
+
67
+ if new_cache_dir != old_cache_dir:
68
+ if old_cache_dir.exists():
69
+ shutil.copytree(old_cache_dir, new_cache_dir, dirs_exist_ok=True)
70
+ logger.info(
71
+ f"the current cache directory was copied to {new_cache_dir.as_posix()} "
72
+ )
73
+ if old_cache_dir != system_cache_dir:
74
+ shutil.rmtree(old_cache_dir)
75
+ logger.info(
76
+ f"cleared the old cache directory {old_cache_dir.as_posix()}"
77
+ )
78
+ else:
79
+ logger.info(
80
+ f"didn't clear the system cache directory {system_cache_dir.as_posix()}, "
81
+ "please clear it manually if you need"
82
+ )
83
+ else:
84
+ new_cache_dir.mkdir(parents=True, exist_ok=True)
85
+ new_cache_dir = new_cache_dir.resolve()
86
+ save_platform_user_storage_settings(None if need_reset else new_cache_dir)
87
+ settings._cache_dir = new_cache_dir
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")
@@ -1,131 +1,131 @@
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
- from uuid import UUID
9
-
10
- from lamin_utils import logger
11
-
12
- from ._silence_loggers import silence_loggers
13
- from .core import django as django_lamin
14
- from .core._settings import settings
15
- from .core._settings_store import current_instance_settings_file
16
- from .errors import (
17
- MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE,
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
- IS_LOADING: bool = False
28
-
29
-
30
- # decorator to disable auto-connect when importing a module such as lamindb
31
- def disable_auto_connect(func: Callable):
32
- @functools.wraps(func)
33
- def wrapper(*args, **kwargs):
34
- global IS_LOADING
35
- IS_LOADING = True
36
- try:
37
- return func(*args, **kwargs)
38
- finally:
39
- IS_LOADING = False
40
-
41
- return wrapper
42
-
43
-
44
- def _normalize_module_name(module_name: str) -> str:
45
- return module_name.replace("lnschema_", "").replace("_", "-")
46
-
47
-
48
- # checks that the provided modules is in the modules of the provided instance
49
- # or in the apps setup by django
50
- def _check_module_in_instance_modules(
51
- module: str, isettings: InstanceSettings | None = None
52
- ) -> None:
53
- if isettings is not None:
54
- modules_raw = isettings.modules
55
- modules = set(modules_raw).union(
56
- _normalize_module_name(module) for module in modules_raw
57
- )
58
- if _normalize_module_name(module) not in modules and module not in modules:
59
- raise ModuleWasntConfigured(
60
- MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE.format(module)
61
- )
62
- else:
63
- return
64
-
65
- from django.apps import apps
66
-
67
- for app in apps.get_app_configs():
68
- # app.name is always unnormalized module (python package) name
69
- if module == app.name or module == _normalize_module_name(app.name):
70
- return
71
- raise ModuleWasntConfigured(MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE.format(module))
72
-
73
-
74
- # infer the name of the module that calls this function
75
- def _infer_callers_module_name() -> str | None:
76
- stack = inspect.stack()
77
- if len(stack) < 3:
78
- return None
79
- module = inspect.getmodule(stack[2][0])
80
- return module.__name__.partition(".")[0] if module is not None else None
81
-
82
-
83
- # we make this a private function because in all the places it's used,
84
- # users should not see it
85
- def _check_instance_setup(from_module: str | None = None) -> bool:
86
- if django_lamin.IS_SETUP:
87
- if from_module is not None:
88
- if from_module != "lamindb":
89
- _check_module_in_instance_modules(from_module)
90
- else:
91
- infer_module = _infer_callers_module_name()
92
- if infer_module is not None and infer_module not in {
93
- "lamindb",
94
- "lamindb_setup",
95
- "lamin_cli",
96
- }:
97
- _check_module_in_instance_modules(infer_module)
98
- return True
99
- silence_loggers()
100
- if os.environ.get("LAMINDB_MULTI_INSTANCE") == "true":
101
- logger.warning(
102
- "running LaminDB in multi-instance mode; you'll experience "
103
- "errors in regular lamindb usage"
104
- )
105
- return True
106
-
107
- if IS_LOADING or from_module is None:
108
- return False
109
-
110
- if (
111
- not settings._instance_exists
112
- and os.environ.get("LAMIN_CURRENT_INSTANCE") is not None
113
- ):
114
- from ._connect_instance import connect
115
-
116
- connect(_write_settings=False, _reload_lamindb=False)
117
- return django_lamin.IS_SETUP
118
- else:
119
- isettings = settings.instance
120
- if from_module != "lamindb":
121
- _check_module_in_instance_modules(from_module, isettings)
122
-
123
- import lamindb # connect to the instance
124
- else:
125
- # disable_auto_connect to avoid triggering _check_instance_setup in modules
126
- disable_auto_connect(django_lamin.setup_django)(isettings)
127
- if isettings.slug != "none/none":
128
- logger.important(f"connected lamindb: {isettings.slug}")
129
- # update of local storage location through search_local_root()
130
- settings._instance_settings = isettings
131
- return django_lamin.IS_SETUP
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
+ from uuid import UUID
9
+
10
+ from lamin_utils import logger
11
+
12
+ from ._silence_loggers import silence_loggers
13
+ from .core import django as django_lamin
14
+ from .core._settings import settings
15
+ from .core._settings_store import current_instance_settings_file
16
+ from .errors import (
17
+ MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE,
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
+ IS_LOADING: bool = False
28
+
29
+
30
+ # decorator to disable auto-connect when importing a module such as lamindb
31
+ def disable_auto_connect(func: Callable):
32
+ @functools.wraps(func)
33
+ def wrapper(*args, **kwargs):
34
+ global IS_LOADING
35
+ IS_LOADING = True
36
+ try:
37
+ return func(*args, **kwargs)
38
+ finally:
39
+ IS_LOADING = False
40
+
41
+ return wrapper
42
+
43
+
44
+ def _normalize_module_name(module_name: str) -> str:
45
+ return module_name.replace("lnschema_", "").replace("_", "-")
46
+
47
+
48
+ # checks that the provided modules is in the modules of the provided instance
49
+ # or in the apps setup by django
50
+ def _check_module_in_instance_modules(
51
+ module: str, isettings: InstanceSettings | None = None
52
+ ) -> None:
53
+ if isettings is not None:
54
+ modules_raw = isettings.modules
55
+ modules = set(modules_raw).union(
56
+ _normalize_module_name(module) for module in modules_raw
57
+ )
58
+ if _normalize_module_name(module) not in modules and module not in modules:
59
+ raise ModuleWasntConfigured(
60
+ MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE.format(module)
61
+ )
62
+ else:
63
+ return
64
+
65
+ from django.apps import apps
66
+
67
+ for app in apps.get_app_configs():
68
+ # app.name is always unnormalized module (python package) name
69
+ if module == app.name or module == _normalize_module_name(app.name):
70
+ return
71
+ raise ModuleWasntConfigured(MODULE_WASNT_CONFIGURED_MESSAGE_TEMPLATE.format(module))
72
+
73
+
74
+ # infer the name of the module that calls this function
75
+ def _infer_callers_module_name() -> str | None:
76
+ stack = inspect.stack()
77
+ if len(stack) < 3:
78
+ return None
79
+ module = inspect.getmodule(stack[2][0])
80
+ return module.__name__.partition(".")[0] if module is not None else None
81
+
82
+
83
+ # we make this a private function because in all the places it's used,
84
+ # users should not see it
85
+ def _check_instance_setup(from_module: str | None = None) -> bool:
86
+ if django_lamin.IS_SETUP:
87
+ if from_module is not None:
88
+ if from_module != "lamindb":
89
+ _check_module_in_instance_modules(from_module)
90
+ else:
91
+ infer_module = _infer_callers_module_name()
92
+ if infer_module is not None and infer_module not in {
93
+ "lamindb",
94
+ "lamindb_setup",
95
+ "lamin_cli",
96
+ }:
97
+ _check_module_in_instance_modules(infer_module)
98
+ return True
99
+ silence_loggers()
100
+ if os.environ.get("LAMINDB_MULTI_INSTANCE") == "true":
101
+ logger.warning(
102
+ "running LaminDB in multi-instance mode; you'll experience "
103
+ "errors in regular lamindb usage"
104
+ )
105
+ return True
106
+
107
+ if IS_LOADING or from_module is None:
108
+ return False
109
+
110
+ if (
111
+ not settings._instance_exists
112
+ and os.environ.get("LAMIN_CURRENT_INSTANCE") is not None
113
+ ):
114
+ from ._connect_instance import connect
115
+
116
+ connect(_write_settings=False, _reload_lamindb=False)
117
+ return django_lamin.IS_SETUP
118
+ else:
119
+ isettings = settings.instance
120
+ if from_module != "lamindb":
121
+ _check_module_in_instance_modules(from_module, isettings)
122
+
123
+ import lamindb # connect to the instance
124
+ else:
125
+ # disable_auto_connect to avoid triggering _check_instance_setup in modules
126
+ disable_auto_connect(django_lamin.setup_django)(isettings)
127
+ if isettings.slug != "none/none":
128
+ logger.important(f"connected lamindb: {isettings.slug}")
129
+ # update of local storage location through search_local_root()
130
+ settings._instance_settings = isettings
131
+ return django_lamin.IS_SETUP