lamindb_setup 0.76.6__py2.py3-none-any.whl → 0.76.7__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 -1
  2. lamindb_setup/_cache.py +34 -34
  3. lamindb_setup/_check.py +7 -7
  4. lamindb_setup/_check_setup.py +79 -79
  5. lamindb_setup/_close.py +35 -35
  6. lamindb_setup/_connect_instance.py +433 -433
  7. lamindb_setup/_delete.py +137 -137
  8. lamindb_setup/_django.py +41 -41
  9. lamindb_setup/_exportdb.py +68 -68
  10. lamindb_setup/_importdb.py +50 -50
  11. lamindb_setup/_init_instance.py +374 -374
  12. lamindb_setup/_migrate.py +239 -236
  13. lamindb_setup/_register_instance.py +36 -36
  14. lamindb_setup/_schema.py +27 -27
  15. lamindb_setup/_schema_metadata.py +391 -391
  16. lamindb_setup/_set_managed_storage.py +55 -55
  17. lamindb_setup/_setup_user.py +118 -118
  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 +164 -161
  25. lamindb_setup/core/_hub_core.py +473 -473
  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 +138 -138
  30. lamindb_setup/core/_settings_instance.py +461 -460
  31. lamindb_setup/core/_settings_load.py +100 -100
  32. lamindb_setup/core/_settings_save.py +81 -81
  33. lamindb_setup/core/_settings_storage.py +393 -393
  34. lamindb_setup/core/_settings_store.py +72 -72
  35. lamindb_setup/core/_settings_user.py +51 -51
  36. lamindb_setup/core/_setup_bionty_sources.py +99 -99
  37. lamindb_setup/core/cloud_sqlite_locker.py +232 -232
  38. lamindb_setup/core/django.py +113 -113
  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.76.6.dist-info → lamindb_setup-0.76.7.dist-info}/METADATA +4 -3
  44. lamindb_setup-0.76.7.dist-info/RECORD +46 -0
  45. {lamindb_setup-0.76.6.dist-info → lamindb_setup-0.76.7.dist-info}/WHEEL +1 -1
  46. lamindb_setup-0.76.6.dist-info/RECORD +0 -46
  47. {lamindb_setup-0.76.6.dist-info → lamindb_setup-0.76.7.dist-info}/LICENSE +0 -0
lamindb_setup/__init__.py CHANGED
@@ -34,7 +34,7 @@ Modules & settings:
34
34
 
35
35
  """
36
36
 
37
- __version__ = "0.76.6" # denote a release candidate for 0.1.0 with 0.1rc1
37
+ __version__ = "0.76.7" # denote a release candidate for 0.1.0 with 0.1rc1
38
38
 
39
39
  import sys
40
40
  from os import name as _os_name
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,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, close it: `lamin close`\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 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, close it: `lamin close`\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")