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.
Files changed (47) hide show
  1. lamindb_setup/__init__.py +1 -2
  2. lamindb_setup/_cache.py +34 -34
  3. lamindb_setup/_check.py +7 -7
  4. lamindb_setup/_check_setup.py +92 -79
  5. lamindb_setup/_close.py +35 -35
  6. lamindb_setup/_connect_instance.py +425 -444
  7. lamindb_setup/_django.py +41 -41
  8. lamindb_setup/_entry_points.py +22 -22
  9. lamindb_setup/_exportdb.py +68 -68
  10. lamindb_setup/_importdb.py +50 -50
  11. lamindb_setup/_init_instance.py +411 -374
  12. lamindb_setup/_migrate.py +239 -239
  13. lamindb_setup/_register_instance.py +36 -36
  14. lamindb_setup/_schema.py +27 -27
  15. lamindb_setup/_schema_metadata.py +411 -411
  16. lamindb_setup/_set_managed_storage.py +55 -55
  17. lamindb_setup/_setup_user.py +137 -137
  18. lamindb_setup/_silence_loggers.py +44 -44
  19. lamindb_setup/core/__init__.py +21 -21
  20. lamindb_setup/core/_aws_credentials.py +151 -151
  21. lamindb_setup/core/_aws_storage.py +48 -48
  22. lamindb_setup/core/_deprecated.py +55 -55
  23. lamindb_setup/core/_docs.py +14 -14
  24. lamindb_setup/core/_hub_client.py +1 -1
  25. lamindb_setup/core/_hub_core.py +615 -590
  26. lamindb_setup/core/_hub_crud.py +211 -211
  27. lamindb_setup/core/_hub_utils.py +109 -109
  28. lamindb_setup/core/_private_django_api.py +88 -88
  29. lamindb_setup/core/_settings.py +145 -138
  30. lamindb_setup/core/_settings_instance.py +480 -467
  31. lamindb_setup/core/_settings_load.py +105 -105
  32. lamindb_setup/core/_settings_save.py +81 -81
  33. lamindb_setup/core/_settings_storage.py +412 -405
  34. lamindb_setup/core/_settings_store.py +75 -75
  35. lamindb_setup/core/_settings_user.py +55 -53
  36. lamindb_setup/core/_setup_bionty_sources.py +101 -101
  37. lamindb_setup/core/cloud_sqlite_locker.py +237 -232
  38. lamindb_setup/core/django.py +115 -114
  39. lamindb_setup/core/exceptions.py +12 -12
  40. lamindb_setup/core/hashing.py +114 -114
  41. lamindb_setup/core/types.py +19 -19
  42. lamindb_setup/core/upath.py +779 -779
  43. {lamindb_setup-0.77.4.dist-info → lamindb_setup-0.77.6.dist-info}/METADATA +3 -2
  44. lamindb_setup-0.77.6.dist-info/RECORD +47 -0
  45. {lamindb_setup-0.77.4.dist-info → lamindb_setup-0.77.6.dist-info}/WHEEL +1 -1
  46. lamindb_setup-0.77.4.dist-info/RECORD +0 -47
  47. {lamindb_setup-0.77.4.dist-info → lamindb_setup-0.77.6.dist-info}/LICENSE +0 -0
lamindb_setup/__init__.py CHANGED
@@ -21,7 +21,6 @@ Instance operations:
21
21
  :toctree:
22
22
 
23
23
  migrate
24
- register
25
24
 
26
25
  Modules & settings:
27
26
 
@@ -34,7 +33,7 @@ Modules & settings:
34
33
 
35
34
  """
36
35
 
37
- __version__ = "0.77.4" # denote a release candidate for 0.1.0 with 0.1rc1
36
+ __version__ = "0.77.6" # denote a release candidate for 0.1.0 with 0.1rc1
38
37
 
39
38
  import os as _os
40
39
  import sys as _sys
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")
@@ -1,79 +1,92 @@
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
1
+ from __future__ import annotations
2
+
3
+ import importlib as il
4
+ import os
5
+ from typing import TYPE_CHECKING, Optional
6
+
7
+ from lamin_utils import logger
8
+
9
+ from ._silence_loggers import silence_loggers
10
+ from .core import django
11
+ from .core._settings import settings
12
+ from .core._settings_store import current_instance_settings_file
13
+ from .core.exceptions import DefaultMessageException
14
+
15
+ if TYPE_CHECKING:
16
+ from .core._settings_instance import InstanceSettings
17
+
18
+
19
+ class InstanceNotSetupError(DefaultMessageException):
20
+ default_message = """\
21
+ To use lamindb, you need to connect to an instance.
22
+
23
+ Connect to an instance: `ln.connect()`. Init an instance: `ln.setup.init()`.
24
+
25
+ If you used the CLI to set up lamindb in a notebook, restart the Python session.
26
+ """
27
+
28
+
29
+ CURRENT_ISETTINGS: InstanceSettings | None = None
30
+
31
+
32
+ def _get_current_instance_settings() -> InstanceSettings | None:
33
+ global CURRENT_ISETTINGS
34
+
35
+ if CURRENT_ISETTINGS is not None:
36
+ return CURRENT_ISETTINGS
37
+ if current_instance_settings_file().exists():
38
+ from .core._settings_load import load_instance_settings
39
+
40
+ try:
41
+ isettings = load_instance_settings()
42
+ except Exception as e:
43
+ # user will get more detailed traceback once they run the CLI
44
+ logger.error(
45
+ "Current instance cannot be reached, unload it: `lamin load --unload`\n"
46
+ "Alternatively, init or load a connectable instance on the"
47
+ " command line: `lamin load <instance>` or `lamin init <...>`"
48
+ )
49
+ raise e
50
+ return isettings
51
+ else:
52
+ return None
53
+
54
+
55
+ # we make this a private function because in all the places it's used,
56
+ # users should not see it
57
+ def _check_instance_setup(
58
+ from_lamindb: bool = False, from_module: str | None = None
59
+ ) -> bool:
60
+ reload_module = from_lamindb or from_module is not None
61
+ from ._init_instance import get_schema_module_name, reload_schema_modules
62
+
63
+ if django.IS_SETUP:
64
+ # reload logic here because module might not yet have been imported
65
+ # upon first setup
66
+ if from_module is not None:
67
+ il.reload(il.import_module(from_module))
68
+ return True
69
+ silence_loggers()
70
+ if os.environ.get("LAMINDB_MULTI_INSTANCE") == "true":
71
+ logger.warning(
72
+ "running LaminDB in multi-instance mode; you'll experience "
73
+ "errors in regular lamindb usage"
74
+ )
75
+ return True
76
+ isettings = _get_current_instance_settings()
77
+ if isettings is not None:
78
+ if reload_module and settings.auto_connect:
79
+ if not django.IS_SETUP:
80
+ django.setup_django(isettings)
81
+ if from_module is not None:
82
+ # this only reloads `from_module`
83
+ il.reload(il.import_module(from_module))
84
+ else:
85
+ # this bulk reloads all schema modules
86
+ reload_schema_modules(isettings)
87
+ logger.important(f"connected lamindb: {isettings.slug}")
88
+ return django.IS_SETUP
89
+ else:
90
+ if reload_module and settings.auto_connect:
91
+ logger.warning(InstanceNotSetupError.default_message)
92
+ 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")