lamindb_setup 1.0a1__tar.gz → 1.0.1__tar.gz

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 (101) hide show
  1. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/.github/workflows/build.yml +6 -4
  2. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/PKG-INFO +2 -2
  3. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-cloud/04-test-bionty.ipynb +3 -3
  4. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-prod/test-import-schema.ipynb +2 -2
  5. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-prod/test-init-load-local-anonymously.ipynb +1 -1
  6. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-prod/test-invalid-schema.ipynb +3 -1
  7. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/notebooks.md +2 -2
  8. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/__init__.py +3 -20
  9. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_cache.py +9 -5
  10. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_check_setup.py +17 -0
  11. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_close.py +1 -1
  12. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_connect_instance.py +45 -37
  13. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_entry_points.py +1 -4
  14. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_exportdb.py +3 -3
  15. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_importdb.py +2 -2
  16. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_init_instance.py +22 -15
  17. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_migrate.py +14 -11
  18. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_schema_metadata.py +5 -5
  19. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_deprecated.py +12 -5
  20. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_hub_utils.py +0 -9
  21. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_settings_instance.py +15 -6
  22. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_settings_load.py +1 -1
  23. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_setup_bionty_sources.py +3 -3
  24. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/django.py +5 -4
  25. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/hashing.py +1 -1
  26. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/upath.py +1 -1
  27. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/noxfile.py +9 -7
  28. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/pyproject.toml +4 -1
  29. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/test_connect_instance.py +8 -6
  30. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/test_init_instance.py +3 -3
  31. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-local/test_update_schema_in_hub.py +4 -4
  32. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-prod/conftest.py +1 -1
  33. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-prod/test_upath.py +1 -1
  34. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/.github/workflows/doc-changes.yml +0 -0
  35. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/.gitignore +0 -0
  36. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/.pre-commit-config.yaml +0 -0
  37. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/LICENSE +0 -0
  38. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/README.md +0 -0
  39. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/changelog.md +0 -0
  40. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-cloud/01-init-local-instance.ipynb +0 -0
  41. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-cloud/02-connect-local-instance.ipynb +0 -0
  42. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-cloud/03-add-managed-storage.ipynb +0 -0
  43. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-cloud/05-init-hosted-instance.ipynb +0 -0
  44. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-cloud/06-connect-hosted-instance.ipynb +0 -0
  45. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-cloud/07-keep-artifacts-local.ipynb +0 -0
  46. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-cloud/08-test-multi-session.ipynb +0 -0
  47. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-cloud/test_notebooks.py +0 -0
  48. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-prod/test-cache-management.ipynb +0 -0
  49. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-prod/test-cloud-sync.ipynb +0 -0
  50. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-prod/test-connect-anonymously.ipynb +0 -0
  51. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-prod/test-empty-init.ipynb +0 -0
  52. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-prod/test-insufficient-user-info.ipynb +0 -0
  53. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-prod/test-sqlite-lock.ipynb +0 -0
  54. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/hub-prod/test_notebooks2.py +0 -0
  55. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/index.md +0 -0
  56. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/docs/reference.md +0 -0
  57. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_check.py +0 -0
  58. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_delete.py +0 -0
  59. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_django.py +0 -0
  60. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_register_instance.py +0 -0
  61. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_schema.py +0 -0
  62. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_set_managed_storage.py +0 -0
  63. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_setup_user.py +0 -0
  64. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/_silence_loggers.py +0 -0
  65. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/__init__.py +0 -0
  66. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_aws_credentials.py +0 -0
  67. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_aws_storage.py +0 -0
  68. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_docs.py +0 -0
  69. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_hub_client.py +0 -0
  70. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_hub_core.py +0 -0
  71. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_hub_crud.py +0 -0
  72. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_private_django_api.py +0 -0
  73. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_settings.py +0 -0
  74. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_settings_save.py +0 -0
  75. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_settings_storage.py +0 -0
  76. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_settings_store.py +0 -0
  77. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/_settings_user.py +0 -0
  78. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/cloud_sqlite_locker.py +0 -0
  79. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/exceptions.py +0 -0
  80. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/lamindb_setup/core/types.py +0 -0
  81. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/scripts/script-init-pass-user-no-writes.py +0 -0
  82. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/scripts/script-to-fail-managed-storage.py +0 -0
  83. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/test_delete_instance.py +0 -0
  84. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/test_edge_request.py +0 -0
  85. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/test_fail_managed_storage.py +0 -0
  86. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/test_init_pass_user_no_writes.py +0 -0
  87. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/test_login.py +0 -0
  88. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/test_migrate.py +0 -0
  89. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-cloud/test_set_storage.py +0 -0
  90. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-local/conftest.py +0 -0
  91. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-local/test_all.py +0 -0
  92. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-prod/test_aws_credentials_manager.py +0 -0
  93. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-prod/test_django.py +0 -0
  94. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-prod/test_global_settings.py +0 -0
  95. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/hub-prod/test_switch_and_fallback_env.py +0 -0
  96. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/storage/test_entry_point.py +0 -0
  97. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/storage/test_hashing.py +0 -0
  98. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/storage/test_storage_access.py +0 -0
  99. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/storage/test_storage_basis.py +0 -0
  100. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/storage/test_storage_stats.py +0 -0
  101. {lamindb_setup-1.0a1 → lamindb_setup-1.0.1}/tests/storage/test_to_url.py +0 -0
@@ -12,7 +12,7 @@ jobs:
12
12
  # tests only on production hub
13
13
  hub-prod:
14
14
  runs-on: ubuntu-latest
15
- timeout-minutes: 8
15
+ timeout-minutes: 12
16
16
  steps:
17
17
  - uses: actions/checkout@v3
18
18
  - uses: actions/setup-python@v4
@@ -44,7 +44,7 @@ jobs:
44
44
  python-version: "3.11"
45
45
  - lamin_env: "staging"
46
46
  python-version: "3.10" # test on 3.9
47
- timeout-minutes: 8
47
+ timeout-minutes: 12
48
48
  steps:
49
49
  - uses: aws-actions/configure-aws-credentials@v4
50
50
  with:
@@ -94,7 +94,7 @@ jobs:
94
94
  # test user access to storage
95
95
  storage:
96
96
  runs-on: ubuntu-latest
97
- timeout-minutes: 8
97
+ timeout-minutes: 12
98
98
  steps:
99
99
  - uses: actions/checkout@v4
100
100
  - uses: actions/setup-python@v4
@@ -119,7 +119,7 @@ jobs:
119
119
  # test low-level hub functionality
120
120
  hub-local:
121
121
  runs-on: ubuntu-latest
122
- timeout-minutes: 8
122
+ timeout-minutes: 12
123
123
  steps:
124
124
  - uses: aws-actions/configure-aws-credentials@v4
125
125
  with:
@@ -152,6 +152,8 @@ jobs:
152
152
  path: /var/lib/docker
153
153
  key: cache-supabase
154
154
  - uses: supabase/setup-cli@v1
155
+ with:
156
+ version: "2.6.8"
155
157
  - run: nox -s hub_local
156
158
  env:
157
159
  LAMIN_ENV: "local"
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lamindb_setup
3
- Version: 1.0a1
3
+ Version: 1.0.1
4
4
  Summary: Setup & configure LaminDB.
5
5
  Author-email: Lamin Labs <open-source@lamin.ai>
6
- Requires-Python: >=3.9
6
+ Requires-Python: >=3.10
7
7
  Description-Content-Type: text/markdown
8
8
  Requires-Dist: lamin_utils>=0.3.3
9
9
  Requires-Dist: django>=5,<5.2
@@ -33,7 +33,7 @@
33
33
  "metadata": {},
34
34
  "outputs": [],
35
35
  "source": [
36
- "ln_setup.init(storage=\"mydata2\", schema=\"bionty\")"
36
+ "ln_setup.init(storage=\"mydata2\", modules=\"bionty\")"
37
37
  ]
38
38
  },
39
39
  {
@@ -89,7 +89,7 @@
89
89
  "metadata": {},
90
90
  "outputs": [],
91
91
  "source": [
92
- "output = getoutput(\"lamin init --storage mydata2 --schema bionty\")\n",
92
+ "output = getoutput(\"lamin init --storage mydata2 --modules bionty\")\n",
93
93
  "print(output)"
94
94
  ]
95
95
  },
@@ -107,7 +107,7 @@
107
107
  "outputs": [],
108
108
  "source": [
109
109
  "ln_setup.settings.instance._get_settings_file().unlink()\n",
110
- "output = getoutput(\"lamin init --storage mydata2 --schema bionty\")\n",
110
+ "output = getoutput(\"lamin init --storage mydata2 --modules bionty\")\n",
111
111
  "print(output)"
112
112
  ]
113
113
  },
@@ -14,7 +14,7 @@
14
14
  "id": "3e5867b4",
15
15
  "metadata": {},
16
16
  "source": [
17
- "Also see the corresponding FAQ notebook in lamindb: `import-schema`.\n",
17
+ "Also see the corresponding FAQ notebook in lamindb: `import-modules`.\n",
18
18
  "\n",
19
19
  "If you try to access an attribute (other than `model`), you'll load the instance in the same way as calling `import lamindb`."
20
20
  ]
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "outputs": [],
30
30
  "source": [
31
- "!lamin init --storage test-implicit-load --schema wetlab,bionty"
31
+ "!lamin init --storage test-implicit-load --modules wetlab,bionty"
32
32
  ]
33
33
  },
34
34
  {
@@ -64,7 +64,7 @@
64
64
  "outputs": [],
65
65
  "source": [
66
66
  "!lamin disconnect\n",
67
- "!lamin init --storage ./test-anonymous-init --schema bionty"
67
+ "!lamin init --storage ./test-anonymous-init --modules bionty"
68
68
  ]
69
69
  },
70
70
  {
@@ -24,7 +24,9 @@
24
24
  "outputs": [],
25
25
  "source": [
26
26
  "with pytest.raises(ImportError):\n",
27
- " ln_setup.init(storage=\"./test-invalid-schema\", schema=\"bionty,invalid_module_name\")"
27
+ " ln_setup.init(\n",
28
+ " storage=\"./test-invalid-modules\", modules=\"bionty,invalid_module_name\"\n",
29
+ " )"
28
30
  ]
29
31
  }
30
32
  ],
@@ -14,8 +14,8 @@ hub-cloud/test-multi-session
14
14
 
15
15
  hub-prod/test-cache-management
16
16
  hub-prod/test-empty-init
17
- hub-prod/test-import-schema
18
- hub-prod/test-invalid-schema
17
+ hub-prod/test-import-modules
18
+ hub-prod/test-invalid-modules
19
19
  hub-prod/test-insufficient-user-info
20
20
  hub-prod/test-init-load-local-anonymously
21
21
  hub-prod/test-connect-anonymously
@@ -33,10 +33,9 @@ Modules & settings:
33
33
 
34
34
  """
35
35
 
36
- __version__ = "1.0a1" # denote a release candidate for 0.1.0 with 0.1rc1
36
+ __version__ = "1.0.1" # denote a release candidate for 0.1.0 with 0.1rc1
37
37
 
38
- import os as _os
39
- import sys as _sys
38
+ import os
40
39
 
41
40
  from . import core
42
41
  from ._check_setup import _check_instance_setup
@@ -76,27 +75,11 @@ def _is_CI_environment() -> bool:
76
75
  "SEMAPHORE", # Semaphore CI
77
76
  "BUILD_ID", # Generic build environments
78
77
  ]
79
- return any(env_var in _os.environ for env_var in ci_env_vars)
78
+ return any(env_var in os.environ for env_var in ci_env_vars)
80
79
 
81
80
 
82
81
  _TESTING = _is_CI_environment()
83
82
 
84
-
85
- # hide the supabase error in a thread on windows
86
- if _os.name == "nt":
87
- if _sys.version_info.minor > 7:
88
- import threading
89
-
90
- _original_excepthook = threading.excepthook
91
-
92
- def _except_hook(args):
93
- is_overflow = args.exc_type is OverflowError
94
- for_timeout = str(args.exc_value) == "timeout value is too large"
95
- if not (is_overflow and for_timeout):
96
- _original_excepthook(args)
97
-
98
- threading.excepthook = _except_hook
99
-
100
83
  # provide a way for other packages to run custom code on import
101
84
  _call_registered_entry_points("lamindb_setup.on_import")
102
85
 
@@ -10,11 +10,15 @@ from .core._settings_save import save_system_storage_settings
10
10
  def clear_cache_dir():
11
11
  from lamindb_setup import close, settings
12
12
 
13
- if settings.instance._is_cloud_sqlite:
14
- logger.warning(
15
- "Closing the current instance to update the cloud sqlite database."
16
- )
17
- close()
13
+ try:
14
+ if settings.instance._is_cloud_sqlite:
15
+ logger.warning(
16
+ "Closing the current instance to update the cloud sqlite database."
17
+ )
18
+ close()
19
+ except SystemExit as e:
20
+ if str(e) != "No instance is loaded! Call `lamin init` or `lamin connect`":
21
+ raise e
18
22
 
19
23
  cache_dir = settings.cache_dir
20
24
  shutil.rmtree(cache_dir)
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import functools
3
4
  import importlib as il
4
5
  import os
5
6
  from typing import TYPE_CHECKING
@@ -13,6 +14,8 @@ from .core._settings_store import current_instance_settings_file
13
14
  from .core.exceptions import DefaultMessageException
14
15
 
15
16
  if TYPE_CHECKING:
17
+ from collections.abc import Callable
18
+
16
19
  from .core._settings_instance import InstanceSettings
17
20
 
18
21
 
@@ -30,6 +33,20 @@ CURRENT_ISETTINGS: InstanceSettings | None = None
30
33
  IS_LOADING: bool = False
31
34
 
32
35
 
36
+ # decorator to disable auto-connect when importing a module such as lamindb
37
+ def _loading(func: Callable):
38
+ @functools.wraps(func)
39
+ def wrapper(*args, **kwargs):
40
+ global IS_LOADING
41
+ IS_LOADING = True
42
+ try:
43
+ return func(*args, **kwargs)
44
+ finally:
45
+ IS_LOADING = False
46
+
47
+ return wrapper
48
+
49
+
33
50
  def _get_current_instance_settings() -> InstanceSettings | None:
34
51
  global CURRENT_ISETTINGS
35
52
 
@@ -24,7 +24,7 @@ def close(mute: bool = False) -> None:
24
24
  logger.warning("did not upload cache file - not enough permissions")
25
25
  else:
26
26
  raise e
27
- if "bionty" in settings.instance.schema:
27
+ if "bionty" in settings.instance.modules:
28
28
  delete_bionty_sources_yaml()
29
29
  current_instance_settings_file().unlink()
30
30
  clear_locker()
@@ -7,7 +7,7 @@ from uuid import UUID
7
7
 
8
8
  from lamin_utils import logger
9
9
 
10
- from ._check_setup import _check_instance_setup
10
+ from ._check_setup import _check_instance_setup, _get_current_instance_settings
11
11
  from ._close import close as close_instance
12
12
  from ._init_instance import (
13
13
  MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE,
@@ -160,7 +160,7 @@ def _connect_instance(
160
160
  name=name,
161
161
  storage=ssettings,
162
162
  db=db_updated,
163
- schema=instance_result["schema_str"],
163
+ modules=instance_result["schema_str"],
164
164
  git_repo=instance_result["git_repo"],
165
165
  keep_artifacts_local=bool(instance_result["keep_artifacts_local"]),
166
166
  is_on_hub=True,
@@ -186,12 +186,12 @@ def _connect_instance(
186
186
 
187
187
 
188
188
  @unlock_cloud_sqlite_upon_exception(ignore_prev_locker=True)
189
- def connect(slug: str, **kwargs) -> str | tuple | None:
190
- """Connect to instance.
189
+ def connect(instance: str | None = None, **kwargs) -> str | tuple | None:
190
+ """Connect to an instance.
191
191
 
192
192
  Args:
193
- slug: The instance slug `account_handle/instance_name` or URL.
194
- If the instance is owned by you, it suffices to pass the instance name.
193
+ instance: `None` or an instance identifier (URL, slug `account/name`, or `name` if the instance is local or in your account).
194
+ If `None`, it will connect to the instance that was connected via the CLI.
195
195
  """
196
196
  # validate kwargs
197
197
  valid_kwargs = {
@@ -220,39 +220,46 @@ def connect(slug: str, **kwargs) -> str | tuple | None:
220
220
  access_token = _user.access_token
221
221
 
222
222
  try:
223
- owner, name = get_owner_name_from_identifier(slug)
224
-
225
- if _check_instance_setup() and not _test:
226
- if (
227
- settings._instance_exists
228
- and f"{owner}/{name}" == settings.instance.slug
223
+ if instance is None:
224
+ isettings_or_none = _get_current_instance_settings()
225
+ if isettings_or_none is None:
226
+ raise SystemExit(
227
+ "No instance was connected through the CLI, pass a value to `instance` or connect via the CLI."
228
+ )
229
+ isettings = isettings_or_none
230
+ else:
231
+ owner, name = get_owner_name_from_identifier(instance)
232
+ if _check_instance_setup() and not _test:
233
+ if (
234
+ settings._instance_exists
235
+ and f"{owner}/{name}" == settings.instance.slug
236
+ ):
237
+ logger.important(f"connected lamindb: {settings.instance.slug}")
238
+ return None
239
+ else:
240
+ raise CannotSwitchDefaultInstance(
241
+ MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE
242
+ )
243
+ elif (
244
+ _write_settings
245
+ and settings._instance_exists
246
+ and f"{owner}/{name}" != settings.instance.slug
229
247
  ):
230
- logger.info(f"connected lamindb: {settings.instance.slug}")
231
- return None
232
- else:
233
- raise CannotSwitchDefaultInstance(
234
- MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE
248
+ close_instance(mute=True)
249
+
250
+ try:
251
+ isettings = _connect_instance(
252
+ owner, name, db=_db, access_token=access_token
235
253
  )
236
- elif (
237
- _write_settings
238
- and settings._instance_exists
239
- and f"{owner}/{name}" != settings.instance.slug
240
- ):
241
- close_instance(mute=True)
242
-
243
- try:
244
- isettings = _connect_instance(
245
- owner, name, db=_db, access_token=access_token
246
- )
247
- except InstanceNotFoundError as e:
248
- if _raise_not_found_error:
249
- raise e
250
- else:
251
- return "instance-not-found"
252
- if isinstance(isettings, str):
253
- return isettings
254
+ except InstanceNotFoundError as e:
255
+ if _raise_not_found_error:
256
+ raise e
257
+ else:
258
+ return "instance-not-found"
259
+ if isinstance(isettings, str):
260
+ return isettings
254
261
  # at this point we have checked already that isettings is not a string
255
- # _user is passed to lock cloud sqite for this user in isettings._load_db()
262
+ # _user is passed to lock cloud sqlite for this user in isettings._load_db()
256
263
  # has no effect if _user is None or if not cloud sqlite instance
257
264
  isettings._locker_user = _user
258
265
  isettings._persist(write_to_disk=_write_settings)
@@ -304,6 +311,7 @@ def connect(slug: str, **kwargs) -> str | tuple | None:
304
311
  load_from_isettings(isettings, user=_user, write_settings=_write_settings)
305
312
  if _reload_lamindb:
306
313
  importlib.reload(importlib.import_module("lamindb"))
314
+ logger.important(f"connected lamindb: {isettings.slug}")
307
315
  except Exception as e:
308
316
  if isettings is not None:
309
317
  if _write_settings:
@@ -381,7 +389,7 @@ def migrate_lnschema_core(
381
389
  else:
382
390
  try:
383
391
  response = input(
384
- f"Do you want to migrate to lamindb 0.78 (integrate lnschema_core into lamindb)? (y/n) -- Will rename {tables_to_rename}"
392
+ f"Do you want to migrate to lamindb 1.0 (integrate lnschema_core into lamindb)? (y/n) -- Will rename {tables_to_rename}"
385
393
  )
386
394
  if response != "y":
387
395
  print("Aborted.")
@@ -5,10 +5,7 @@ from importlib.metadata import entry_points
5
5
 
6
6
  def call_registered_entry_points(group, **kwargs):
7
7
  """load and call entry points registered under group."""
8
- if sys.version_info >= (3, 10):
9
- eps = entry_points(group=group)
10
- else:
11
- eps = entry_points().get(group, [])
8
+ eps = entry_points(group=group)
12
9
 
13
10
  for ep in eps:
14
11
  func = ep.load()
@@ -12,7 +12,7 @@ MODELS = {
12
12
  "User": False,
13
13
  "Storage": False,
14
14
  "Feature": False,
15
- "FeatureSet": False,
15
+ "Schema": False,
16
16
  "ULabel": False,
17
17
  },
18
18
  # "bionty": {
@@ -57,9 +57,9 @@ def exportdb() -> None:
57
57
 
58
58
  # export data to parquet files
59
59
  print(f"\nexporting data to parquet files in: {directory}\n")
60
- for schema_name, models in MODELS.items():
60
+ for module_name, models in MODELS.items():
61
61
  for model_name in models.keys():
62
- schema_module = import_module(f"lnschema_{schema_name}")
62
+ schema_module = import_module(f"lnschema_{module_name}")
63
63
  registry = getattr(schema_module, model_name)
64
64
  export_registry(registry, directory)
65
65
  many_to_many_names = [field.name for field in registry._meta.many_to_many]
@@ -36,10 +36,10 @@ def importdb() -> None:
36
36
  with engine.begin() as connection:
37
37
  if ln_setup.settings.instance.dialect == "postgresql":
38
38
  connection.execute(text("SET CONSTRAINTS ALL DEFERRED;"))
39
- for schema_name, models in MODELS.items():
39
+ for module_name, models in MODELS.items():
40
40
  for model_name in models.keys():
41
41
  print(model_name)
42
- schema_module = import_module(f"lnschema_{schema_name}")
42
+ schema_module = import_module(f"lnschema_{module_name}")
43
43
  registry = getattr(schema_module, model_name)
44
44
  import_registry(registry, directory, connection)
45
45
  many_to_many_names = [
@@ -25,17 +25,17 @@ if TYPE_CHECKING:
25
25
  from .core.types import UPathStr
26
26
 
27
27
 
28
- def get_schema_module_name(schema_name, raise_import_error: bool = True) -> str | None:
28
+ def get_schema_module_name(module_name, raise_import_error: bool = True) -> str | None:
29
29
  import importlib.util
30
30
 
31
- if schema_name == "core":
31
+ if module_name == "core":
32
32
  return "lamindb"
33
- name_attempts = [f"lnschema_{schema_name.replace('-', '_')}", schema_name]
33
+ name_attempts = [f"lnschema_{module_name.replace('-', '_')}", module_name]
34
34
  for name in name_attempts:
35
35
  module_spec = importlib.util.find_spec(name)
36
36
  if module_spec is not None:
37
37
  return name
38
- message = f"Schema module '{schema_name}' is not installed → no access to its labels & registries (resolve via `pip install {schema_name}`)"
38
+ message = f"schema module '{module_name}' is not installed → no access to its labels & registries (resolve via `pip install {module_name}`)"
39
39
  if raise_import_error:
40
40
  raise ImportError(message)
41
41
  logger.warning(message.lower())
@@ -129,12 +129,21 @@ def process_connect_response(
129
129
  return instance_id, instance_state
130
130
 
131
131
 
132
+ def process_modules_arg(modules: str | None = None) -> str:
133
+ if modules is None or modules == "":
134
+ return ""
135
+ # currently no actual validation, can add back if we see a need
136
+ # the following just strips white spaces
137
+ to_be_validated = [s.strip() for s in modules.split(",")]
138
+ return ",".join(to_be_validated)
139
+
140
+
132
141
  def validate_init_args(
133
142
  *,
134
143
  storage: UPathStr,
135
144
  name: str | None = None,
136
145
  db: PostgresDsn | None = None,
137
- schema: str | None = None,
146
+ modules: str | None = None,
138
147
  _test: bool = False,
139
148
  _write_settings: bool = True,
140
149
  _user: UserSettings | None = None,
@@ -150,9 +159,6 @@ def validate_init_args(
150
159
  str,
151
160
  ]:
152
161
  from ._connect_instance import connect
153
- from .core._hub_utils import (
154
- validate_schema_arg,
155
- )
156
162
 
157
163
  if storage is None:
158
164
  raise SystemExit("✗ `storage` argument can't be `None`")
@@ -178,7 +184,7 @@ def validate_init_args(
178
184
  instance_id = None
179
185
  if response is not None:
180
186
  instance_id, instance_state = process_connect_response(response, instance_slug)
181
- schema = validate_schema_arg(schema)
187
+ modules = process_modules_arg(modules)
182
188
  return name_str, instance_id, instance_state, instance_slug
183
189
 
184
190
 
@@ -202,22 +208,23 @@ def init(
202
208
  storage: UPathStr,
203
209
  name: str | None = None,
204
210
  db: PostgresDsn | None = None,
205
- schema: str | None = None,
211
+ modules: str | None = None,
206
212
  **kwargs,
207
213
  ) -> None:
208
214
  """Create and load a LaminDB instance.
209
215
 
210
216
  Args:
211
- storage: Either ``"create-s3"``, local or
212
- remote folder (``"s3://..."`` or ``"gs://..."``).
217
+ storage: Either local or remote folder (`"s3://..."` or `"gs://..."`).
213
218
  name: Instance name.
214
219
  db: Database connection url, do not pass for SQLite.
215
- schema: Comma-separated string of schema modules. None if not set.
220
+ modules: Comma-separated string of modules. None if the lamindb registries are enough.
216
221
  """
217
222
  isettings = None
218
223
  ssettings = None
219
224
 
220
225
  _write_settings: bool = kwargs.get("_write_settings", True)
226
+ if modules is None:
227
+ modules = kwargs.get("schema", None)
221
228
  _test: bool = kwargs.get("_test", False)
222
229
 
223
230
  # use this user instead of settings.user
@@ -241,7 +248,7 @@ def init(
241
248
  storage=storage,
242
249
  name=name,
243
250
  db=db,
244
- schema=schema,
251
+ modules=modules,
245
252
  _test=_test,
246
253
  _write_settings=_write_settings,
247
254
  _user=_user, # will get from settings.user if _user is None
@@ -268,7 +275,7 @@ def init(
268
275
  name=name_str,
269
276
  storage=ssettings,
270
277
  db=db,
271
- schema=schema,
278
+ modules=modules,
272
279
  uid=ssettings.uid,
273
280
  # to lock passed user in isettings._cloud_sqlite_locker.lock()
274
281
  _locker_user=_user, # only has effect if cloud sqlite
@@ -5,7 +5,7 @@ from django.db.migrations.loader import MigrationLoader
5
5
  from lamin_utils import logger
6
6
  from packaging import version
7
7
 
8
- from . import _check_setup
8
+ from ._check_setup import _check_instance_setup, _loading
9
9
  from .core._settings import settings
10
10
  from .core.django import setup_django
11
11
 
@@ -23,9 +23,9 @@ def check_whether_migrations_in_sync(db_version_str: str):
23
23
  return None
24
24
  installed_version = version.parse(installed_version_str)
25
25
  db_version = version.parse(db_version_str)
26
- if (
27
- installed_version.major < db_version.major
28
- or installed_version.minor < db_version.minor
26
+ if installed_version.major < db_version.major or (
27
+ installed_version.major == db_version.major
28
+ and installed_version.minor < db_version.minor
29
29
  ):
30
30
  db_version_lower = f"{db_version.major}.{db_version.minor}"
31
31
  db_version_upper = f"{db_version.major}.{db_version.minor + 1}"
@@ -37,9 +37,9 @@ def check_whether_migrations_in_sync(db_version_str: str):
37
37
  "please update lamindb: pip install"
38
38
  f' "lamindb>={db_version_lower},<{db_version_upper}"'
39
39
  )
40
- elif (
41
- installed_version.major > db_version.major
42
- or installed_version.minor > db_version.minor
40
+ elif installed_version.major > db_version.major or (
41
+ installed_version.major == db_version.major
42
+ and installed_version.minor > db_version.minor
43
43
  ):
44
44
  logger.warning(
45
45
  f"the database ({db_version_str}) is behind your installed lamindb package"
@@ -62,20 +62,20 @@ class migrate:
62
62
  """
63
63
 
64
64
  @classmethod
65
+ @_loading
65
66
  def create(cls) -> None:
66
67
  """Create a migration."""
67
- if _check_setup._check_instance_setup():
68
+ if _check_instance_setup():
68
69
  raise RuntimeError("Restart Python session to create migration or use CLI!")
69
- _check_setup.IS_LOADING = True
70
70
  setup_django(settings.instance, create_migrations=True)
71
- _check_setup.IS_LOADING = False
72
71
 
73
72
  @classmethod
73
+ @_loading
74
74
  def deploy(cls) -> None:
75
75
  """Deploy a migration."""
76
76
  from ._schema_metadata import update_schema_in_hub
77
77
 
78
- if _check_setup._check_instance_setup():
78
+ if _check_instance_setup():
79
79
  raise RuntimeError("Restart Python session to migrate or use CLI!")
80
80
  from lamindb_setup.core._hub_client import call_with_fallback_auth
81
81
  from lamindb_setup.core._hub_crud import (
@@ -115,6 +115,7 @@ class migrate:
115
115
  )
116
116
 
117
117
  @classmethod
118
+ @_loading
118
119
  def check(cls) -> bool:
119
120
  """Check whether Registry definitions are in sync with migrations."""
120
121
  from django.core.management import call_command
@@ -131,6 +132,7 @@ class migrate:
131
132
  return True
132
133
 
133
134
  @classmethod
135
+ @_loading
134
136
  def squash(
135
137
  cls, package_name, migration_nr, start_migration_nr: str | None = None
136
138
  ) -> None:
@@ -146,6 +148,7 @@ class migrate:
146
148
  call_command("squashmigrations", package_name, migration_nr)
147
149
 
148
150
  @classmethod
151
+ @_loading
149
152
  def show(cls) -> None:
150
153
  """Show migrations."""
151
154
  from django.core.management import call_command
@@ -238,15 +238,15 @@ class _ModelHandler:
238
238
  model_name = field.model._meta.model_name
239
239
  relation_type = self._get_relation_type(model, field)
240
240
  if field.related_model is None:
241
- schema_name = field.model.__get_schema_name__()
241
+ schema_name = field.model.__get_module_name__()
242
242
  related_model_name = None
243
243
  related_schema_name = None
244
244
  related_field_name = None
245
245
  field_name = field.name
246
246
  else:
247
247
  related_model_name = field.related_model._meta.model_name
248
- related_schema_name = field.related_model.__get_schema_name__()
249
- schema_name = field.model.__get_schema_name__()
248
+ related_schema_name = field.related_model.__get_module_name__()
249
+ schema_name = field.model.__get_module_name__()
250
250
  related_field_name = field.remote_field.name
251
251
  field_name = field.name
252
252
 
@@ -362,7 +362,7 @@ class _ModelHandler:
362
362
 
363
363
  class _SchemaHandler:
364
364
  def __init__(self) -> None:
365
- self.included_modules = ["core"] + list(settings.instance.schema)
365
+ self.included_modules = ["core"] + list(settings.instance.modules)
366
366
  self.modules = self._get_modules_metadata()
367
367
 
368
368
  def to_dict(self, include_django_objects: bool = True):
@@ -391,7 +391,7 @@ class _SchemaHandler:
391
391
  if model.__class__ is Registry
392
392
  and model is not Record
393
393
  and not model._meta.abstract
394
- and model.__get_schema_name__() == module_name
394
+ and model.__get_module_name__() == module_name
395
395
  }
396
396
  for module_name in self.included_modules
397
397
  }