lamindb_setup 0.77.0__py2.py3-none-any.whl → 0.77.2__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 CHANGED
@@ -34,7 +34,7 @@ Modules & settings:
34
34
 
35
35
  """
36
36
 
37
- __version__ = "0.77.0" # denote a release candidate for 0.1.0 with 0.1rc1
37
+ __version__ = "0.77.2" # denote a release candidate for 0.1.0 with 0.1rc1
38
38
 
39
39
  import os as _os
40
40
  import sys as _sys
@@ -45,6 +45,7 @@ from ._close import close
45
45
  from ._connect_instance import connect, load
46
46
  from ._delete import delete
47
47
  from ._django import django
48
+ from ._entry_points import call_registered_entry_points as _call_registered_entry_points
48
49
  from ._init_instance import init
49
50
  from ._migrate import migrate
50
51
  from ._register_instance import register
@@ -68,4 +69,7 @@ if _os.name == "nt":
68
69
 
69
70
  threading.excepthook = _except_hook
70
71
 
72
+ # provide a way for other packages to run custom code on import
73
+ _call_registered_entry_points("lamindb_setup.on_import")
74
+
71
75
  settings.__doc__ = """Global :class:`~lamindb.setup.core.SetupSettings`."""
@@ -12,6 +12,7 @@ from ._init_instance import MESSAGE_NO_MULTIPLE_INSTANCE, load_from_isettings
12
12
  from ._migrate import check_whether_migrations_in_sync
13
13
  from ._silence_loggers import silence_loggers
14
14
  from .core._hub_core import connect_instance as load_instance_from_hub
15
+ from .core._hub_core import connect_instance_new as load_instance_from_hub_edge
15
16
  from .core._hub_utils import (
16
17
  LaminDsn,
17
18
  LaminDsnModel,
@@ -126,7 +127,10 @@ def _connect_instance(
126
127
  # on the hub
127
128
  # do not call hub if the user is anonymous
128
129
  if owner != "anonymous":
129
- hub_result = load_instance_from_hub(owner=owner, name=name)
130
+ if settings.user.handle in {"Koncopd", "sunnyosun", "falexwolf"}:
131
+ hub_result = load_instance_from_hub_edge(owner=owner, name=name)
132
+ else:
133
+ hub_result = load_instance_from_hub(owner=owner, name=name)
130
134
  else:
131
135
  hub_result = "anonymous-user"
132
136
  # if hub_result is not a string, it means it made a request
@@ -0,0 +1,22 @@
1
+ import sys
2
+ import warnings
3
+ from importlib.metadata import entry_points
4
+
5
+
6
+ def call_registered_entry_points(group, **kwargs):
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, [])
12
+
13
+ for ep in eps:
14
+ func = ep.load()
15
+ try:
16
+ func(**kwargs)
17
+ except BaseException as e:
18
+ warnings.warn(
19
+ f"Error loading entry point of group {group!r}: {ep} -> {e}",
20
+ RuntimeWarning,
21
+ stacklevel=2,
22
+ )
@@ -28,7 +28,7 @@ def load_user(email: str | None = None, handle: str | None = None) -> UserSettin
28
28
  if settings_file.exists():
29
29
  user_settings = load_user_settings(settings_file)
30
30
  save_user_settings(user_settings) # needed to save to current_user.env
31
- assert user_settings.email is not None
31
+ assert user_settings.email is not None or user_settings.api_key is not None
32
32
  else:
33
33
  user_settings = load_or_create_user_settings()
34
34
  if email is None:
@@ -74,13 +74,15 @@ def login(
74
74
  # within UserSettings, we still call it "password" for a while
75
75
  user_settings.password = key
76
76
 
77
- if user_settings.email is None:
78
- raise SystemExit(f"✗ No stored user email, please call: lamin login {user}")
79
-
80
77
  if user_settings.password is None:
81
- raise SystemExit(
82
- "✗ No stored API key, please call: lamin login <your-email> --key <API-key>"
83
- )
78
+ api_key = user_settings.api_key
79
+ if api_key is None:
80
+ raise SystemExit(
81
+ "✗ No stored API key, please call: "
82
+ "`lamin login` or `lamin login <your-email> --key <API-key>`"
83
+ )
84
+ elif user_settings.email is None:
85
+ raise SystemExit(f"✗ No stored user email, please call: lamin login {user}")
84
86
  else:
85
87
  user_settings = load_or_create_user_settings()
86
88
 
@@ -94,6 +96,7 @@ def login(
94
96
  )
95
97
  else:
96
98
  response = sign_in_hub_api_key(api_key)
99
+ user_settings.password = None
97
100
 
98
101
  if isinstance(response, Exception):
99
102
  raise response
@@ -131,7 +131,7 @@ def call_with_fallback_auth(
131
131
  try:
132
132
  if renew_token:
133
133
  logger.warning(
134
- "renewing expired lamin token: call `lamin login` to avoid this"
134
+ "renewing expired lamin token: call `lamin login <your-handle>` to avoid this"
135
135
  )
136
136
  client = connect_hub_with_auth(
137
137
  renew_token=renew_token, fallback_env=fallback_env
@@ -277,7 +277,6 @@ def _init_instance(isettings: InstanceSettings, client: Client) -> None:
277
277
  "id": isettings._id.hex,
278
278
  "account_id": settings.user._uuid.hex, # type: ignore
279
279
  "name": isettings.name,
280
- "storage_id": isettings.storage._uuid.hex, # type: ignore
281
280
  "lnid": isettings.uid,
282
281
  "schema_str": isettings._schema_str,
283
282
  "lamindb_version": lamindb_version,
@@ -340,7 +339,7 @@ def _connect_instance(
340
339
  # get default storage
341
340
  storage = select_default_storage_by_instance_id(instance["id"], client)
342
341
  if storage is None:
343
- return "storage-does-not-exist-on-hub"
342
+ return "default-storage-does-not-exist-on-hub"
344
343
  else:
345
344
  account = instance_account_storage.pop("account")
346
345
  storage = instance_account_storage.pop("storage")
@@ -367,6 +366,73 @@ def _connect_instance(
367
366
  return instance, storage # type: ignore
368
367
 
369
368
 
369
+ def _connect_instance_new(
370
+ owner: str, # account_handle
371
+ name: str, # instance_name
372
+ client: Client,
373
+ ) -> tuple[dict, dict] | str:
374
+ response = client.functions.invoke(
375
+ "get-instance-settings", invoke_options={"body": {"owner": owner, "name": name}}
376
+ )
377
+ # no instance found, check why is that
378
+ if response == b"{}":
379
+ # try the via single requests, will take more time
380
+ account = select_account_by_handle(owner, client)
381
+ if account is None:
382
+ return "account-not-exists"
383
+ instance = select_instance_by_name(account["id"], name, client)
384
+ if instance is None:
385
+ return "instance-not-found"
386
+ # get default storage
387
+ storage = select_default_storage_by_instance_id(instance["id"], client)
388
+ if storage is None:
389
+ return "default-storage-does-not-exist-on-hub"
390
+ logger.warning(
391
+ "Could not find instance via API, but found directly querying hub."
392
+ )
393
+ else:
394
+ instance = json.loads(response)
395
+ storage = instance.pop("storage")
396
+
397
+ if instance["db_scheme"] is not None:
398
+ db_user_name, db_user_password = None, None
399
+ if "db_user_name" in instance and "db_user_password" in instance:
400
+ db_user_name, db_user_password = (
401
+ instance["db_user_name"],
402
+ instance["db_user_password"],
403
+ )
404
+ else:
405
+ db_user = select_db_user_by_instance(instance["id"], client)
406
+ if db_user is not None:
407
+ db_user_name, db_user_password = (
408
+ db_user["db_user_name"],
409
+ db_user["db_user_password"],
410
+ )
411
+ db_dsn = LaminDsn.build(
412
+ scheme=instance["db_scheme"],
413
+ user=db_user_name if db_user_name is not None else "none",
414
+ password=db_user_password if db_user_password is not None else "none",
415
+ host=instance["db_host"],
416
+ port=instance["db_port"],
417
+ database=instance["db_database"],
418
+ )
419
+ instance["db"] = db_dsn
420
+ return instance, storage # type: ignore
421
+
422
+
423
+ def connect_instance_new(
424
+ *,
425
+ owner: str, # account_handle
426
+ name: str, # instance_name
427
+ ) -> tuple[dict, dict] | str:
428
+ from ._settings import settings
429
+
430
+ if settings.user.handle != "anonymous":
431
+ return call_with_fallback_auth(_connect_instance_new, owner=owner, name=name)
432
+ else:
433
+ return call_with_fallback(_connect_instance_new, owner=owner, name=name)
434
+
435
+
370
436
  def access_aws(storage_root: str, access_token: str | None = None) -> dict[str, dict]:
371
437
  from ._settings import settings
372
438
 
@@ -333,6 +333,12 @@ class InstanceSettings:
333
333
  @property
334
334
  def db(self) -> str:
335
335
  """Database connection string (URI)."""
336
+ if "LAMINDB_DJANGO_DATABASE_URL" in os.environ:
337
+ logger.warning(
338
+ "LAMINDB_DJANGO_DATABASE_URL env variable "
339
+ f"is set to {os.environ['LAMINDB_DJANGO_DATABASE_URL']}. "
340
+ "It overwrites all db connections and is used instead of `instance.db`."
341
+ )
336
342
  if self._db is None:
337
343
  # here, we want the updated sqlite file
338
344
  # hence, we don't use self._sqlite_file_local()
@@ -55,7 +55,7 @@ def save_settings(
55
55
  settings_key = f"_{store_key.rstrip('_')}"
56
56
  else:
57
57
  settings_key = store_key
58
- value = getattr(settings, settings_key)
58
+ value = getattr(settings, settings_key, None)
59
59
  if value is None:
60
60
  value = "null"
61
61
  elif isinstance(value, UUID):
@@ -49,12 +49,14 @@ def system_storage_settings_file():
49
49
 
50
50
 
51
51
  class InstanceSettingsStore(BaseSettings):
52
+ api_url: Optional[str] = None
52
53
  owner: str
53
54
  name: str
54
55
  storage_root: str
55
56
  storage_region: Optional[str] # take old type annotations here because pydantic
56
57
  db: Optional[str] # doesn't like new types on 3.9 even with future annotations
57
58
  schema_str: Optional[str]
59
+ schema_id: Optional[str] = None
58
60
  id: str
59
61
  git_repo: Optional[str]
60
62
  keep_artifacts_local: Optional[bool]
@@ -42,6 +42,7 @@ def setup_django(
42
42
  # configuration
43
43
  if not settings.configured:
44
44
  default_db = dj_database_url.config(
45
+ env="LAMINDB_DJANGO_DATABASE_URL",
45
46
  default=isettings.db,
46
47
  # see comment next to patching BaseDatabaseWrapper below
47
48
  conn_max_age=CONN_MAX_AGE,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lamindb_setup
3
- Version: 0.77.0
3
+ Version: 0.77.2
4
4
  Summary: Setup & configure LaminDB.
5
5
  Author-email: Lamin Labs <open-source@lamin.ai>
6
6
  Description-Content-Type: text/markdown
@@ -1,11 +1,12 @@
1
- lamindb_setup/__init__.py,sha256=si77fb-FM3YtS5mR_apN1fteFqtzFd3fI7j2UREy4XM,1515
1
+ lamindb_setup/__init__.py,sha256=qb9t881MUHVHKM2hZh_a8wqQJ594sKEkhTWq5AU1ABw,1726
2
2
  lamindb_setup/_cache.py,sha256=wA7mbysANwe8hPNbjDo9bOmXJ0xIyaS5iyxIpxSWji4,846
3
3
  lamindb_setup/_check.py,sha256=28PcG8Kp6OpjSLSi1r2boL2Ryeh6xkaCL87HFbjs6GA,129
4
4
  lamindb_setup/_check_setup.py,sha256=cNEL9Q4yPpmEkGKHH8JgullWl1VUZwALJ4RHn9wZypY,2613
5
5
  lamindb_setup/_close.py,sha256=cXNwK7QTTyNFt2XTpLnO3KHljJ7ShOcISk95np_dltE,1239
6
- lamindb_setup/_connect_instance.py,sha256=TaY317ufYYAVWoEAfeGI_P8IJDP4AYTcHxA4w0-CIqU,16386
6
+ lamindb_setup/_connect_instance.py,sha256=Ln7i-J4ALqmPEMiG-jdYwxz08sAbbMPlbPW72r90Iz0,16647
7
7
  lamindb_setup/_delete.py,sha256=Y8KSFYgY0UHAvjd7cCL6hZ_XiLeJwx50BguVATcj_Xo,5524
8
8
  lamindb_setup/_django.py,sha256=EoyWvFzH0i9wxjy4JZhcoXCTckztP_Mrl6FbYQnMmLE,1534
9
+ lamindb_setup/_entry_points.py,sha256=Hs2oJQOCTaGUdWn-1mufM6qUZr9W_EJ_Oc3f0_Vc0Yw,616
9
10
  lamindb_setup/_exportdb.py,sha256=43g77-tH-vAlTn8ig1mMD9-KXLKvxUeDLaq0gVu3l-c,2114
10
11
  lamindb_setup/_importdb.py,sha256=yYYShzUajTsR-cTW4CZ-UNDWZY2uE5PAgNbp-wn8Ogc,1874
11
12
  lamindb_setup/_init_instance.py,sha256=VxHgD2i0hrFm2f_WCX76YmS_Lsx2iufrMtfab82r8X0,12391
@@ -14,33 +15,33 @@ lamindb_setup/_register_instance.py,sha256=alQuYp2f8Ct8xvRC1gt8p_HZ0tqCd3gZD3kiP
14
15
  lamindb_setup/_schema.py,sha256=b3uzhhWpV5mQtDwhMINc2MabGCnGLESy51ito3yl6Wc,679
15
16
  lamindb_setup/_schema_metadata.py,sha256=XfKCcpQXoatx4Dm2pflp-mPhZ9tpqjn2Cq4ip3MOFSY,13715
16
17
  lamindb_setup/_set_managed_storage.py,sha256=4tDxXQMt8Gw028uY3vIQxZQ7qBNXhQMc8saarNK_Z-s,2043
17
- lamindb_setup/_setup_user.py,sha256=vvmzotU_6C-fFLIZ85mevdkKMV9qXHsQFIXoXV3GUEk,4395
18
+ lamindb_setup/_setup_user.py,sha256=z2TTnnTZw2m3szuezn2ToU_qVfjD9ZMGvcH792KjINM,4601
18
19
  lamindb_setup/_silence_loggers.py,sha256=AKF_YcHvX32eGXdsYK8MJlxEaZ-Uo2f6QDRzjKFCtws,1568
19
20
  lamindb_setup/core/__init__.py,sha256=BxIVMX5HQq8oZ1OuY_saUEJz5Tdd7gaCPngxVu5iou4,417
20
21
  lamindb_setup/core/_aws_credentials.py,sha256=uKMQO9q42Hnepz8aj3RxwLKDWUJx8pNOYrFnnNh5X40,5325
21
22
  lamindb_setup/core/_aws_storage.py,sha256=nEjeUv4xUVpoV0Lx-zjjmyb9w804bDyaeiM-OqbfwM0,1799
22
23
  lamindb_setup/core/_deprecated.py,sha256=3qxUI1dnDlSeR0BYrv7ucjqRBEojbqotPgpShXs4KF8,2520
23
24
  lamindb_setup/core/_docs.py,sha256=3k-YY-oVaJd_9UIY-LfBg_u8raKOCNfkZQPA73KsUhs,276
24
- lamindb_setup/core/_hub_client.py,sha256=nhdF9qYABRzVkDQMFI-Ft4KVZPDJXrZiyHIvAE5e2j4,6103
25
- lamindb_setup/core/_hub_core.py,sha256=IOH8yI60xYel42aXTk2yYlF5Z2jJPsHFhvn9cguA-FY,18690
25
+ lamindb_setup/core/_hub_client.py,sha256=8sD_AbH_Iaw87Vdcoe3Va0I-_kT2jfYjfWM2zbuQETg,6117
26
+ lamindb_setup/core/_hub_core.py,sha256=ZpjGaNRPLSt3QMyBJC5ug3yhTgC7jdqJpwd0AMPDXbc,21140
26
27
  lamindb_setup/core/_hub_crud.py,sha256=eZErpq9t1Cp2ULBSi457ekrcqfesw4Y6IJgaqyrINMY,5276
27
28
  lamindb_setup/core/_hub_utils.py,sha256=w5IRtrxZcvxmGSJslzuZF89ewkzXV4cCUmZUVrqmAfo,3026
28
29
  lamindb_setup/core/_private_django_api.py,sha256=KIn43HOhiRjkbTbddyJqv-WNTTa1bAizbM1tWXoXPBg,2869
29
30
  lamindb_setup/core/_settings.py,sha256=46axQ5HPvI0X9YuotgdpuSOfSo7qYU1DudIx3vxpFk0,4471
30
- lamindb_setup/core/_settings_instance.py,sha256=QkhBeDrnM86WDq_FL6KwBIkQxW9mqLjwNW7FSBoKXxs,17608
31
+ lamindb_setup/core/_settings_instance.py,sha256=dpNuFlD0bJF6pyz_GhKtejDMrKCEGd_ERPXLL_OOlIo,17930
31
32
  lamindb_setup/core/_settings_load.py,sha256=n7-_vg7YfuoMo4wdwwL2hdBjorywTq0GiprsfILWCko,3720
32
- lamindb_setup/core/_settings_save.py,sha256=n_tYfb9EBSxwm4LHyPRHJptE5uB8lmHhcRkz1JkAmhg,2781
33
+ lamindb_setup/core/_settings_save.py,sha256=2sd8o-5MHazfDFO13iRIuCDpmzztn2b5J3fmfw4MGxY,2787
33
34
  lamindb_setup/core/_settings_storage.py,sha256=jFdoIkSn1gPDDZKjAlgKyrlsHBqZDOvv-UnuUI7aD_4,14249
34
- lamindb_setup/core/_settings_store.py,sha256=tEpHPEqg58ZMyCZUKRkekQ3VzTByqsRTnWh_esTWUVY,2149
35
+ lamindb_setup/core/_settings_store.py,sha256=WcsgOmgnu9gztcrhp-N4OONNZyxICHV8M0HdJllTaEo,2219
35
36
  lamindb_setup/core/_settings_user.py,sha256=N3a3CjZSCs0TW5Q0A_HVUaKBCpb0_82wZMoa5C_YsbA,1390
36
37
  lamindb_setup/core/_setup_bionty_sources.py,sha256=o2L5Ww8TKgSqJtL4cGUcpJwLNYxA9BZgddhCMCu_E2g,3428
37
38
  lamindb_setup/core/cloud_sqlite_locker.py,sha256=reu02M4aE2BT_A5AFqwhv48l91mOMyQ4zTd-hh-wtuU,6922
38
- lamindb_setup/core/django.py,sha256=QUQm3zt5QIiD8uv6o9vbSm_bshqiSWzKSkgD3z2eJCg,3542
39
+ lamindb_setup/core/django.py,sha256=3pVbUWDSU2mkMLCFRGAWpIHdFUinnDI9zga5WrcM47g,3589
39
40
  lamindb_setup/core/exceptions.py,sha256=eoI7AXgATgDVzgArtN7CUvpaMUC067vsBg5LHCsWzDM,305
40
41
  lamindb_setup/core/hashing.py,sha256=Y2cvEaqtm3KwpHqj5ZG2f_sLaXhsQT4oDrmJdHbOQeo,3116
41
42
  lamindb_setup/core/types.py,sha256=bcYnZ0uM_2NXKJCl94Mmc-uYrQlRUUVKG3sK2N-F-N4,532
42
43
  lamindb_setup/core/upath.py,sha256=EPLLm62q-Y3hZzd-286cynFMttXKDNXNOKL3_QGkeug,27215
43
- lamindb_setup-0.77.0.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
44
- lamindb_setup-0.77.0.dist-info/WHEEL,sha256=Sgu64hAMa6g5FdzHxXv9Xdse9yxpGGMeagVtPMWpJQY,99
45
- lamindb_setup-0.77.0.dist-info/METADATA,sha256=n4t0efsUWS3gfVZOGhDWQtL6QpHAEqQJUJskEXg14qE,1667
46
- lamindb_setup-0.77.0.dist-info/RECORD,,
44
+ lamindb_setup-0.77.2.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
45
+ lamindb_setup-0.77.2.dist-info/WHEEL,sha256=Sgu64hAMa6g5FdzHxXv9Xdse9yxpGGMeagVtPMWpJQY,99
46
+ lamindb_setup-0.77.2.dist-info/METADATA,sha256=x9pp3IAYEixvruorfano5Q650a7i3Y-fH5YWW4JqH-k,1667
47
+ lamindb_setup-0.77.2.dist-info/RECORD,,