lamindb_setup 1.10.2__py3-none-any.whl → 1.11.0__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
@@ -35,7 +35,7 @@ Modules & settings:
35
35
 
36
36
  """
37
37
 
38
- __version__ = "1.10.2" # denote a release candidate for 0.1.0 with 0.1rc1
38
+ __version__ = "1.11.0" # denote a release candidate for 0.1.0 with 0.1rc1
39
39
 
40
40
  import os
41
41
 
@@ -196,7 +196,7 @@ def reset_django_module_variables():
196
196
  # to the old classes
197
197
  # Other functions that dynamically import are no problem because the variables
198
198
  # are automatically refreshed when the function runs the next time after ln.connect() was called
199
- logger.important_hint("resetting django module variables")
199
+ logger.debug("resetting django module variables")
200
200
 
201
201
  # django.apps needs to be a local import to refresh variables
202
202
  from django.apps import apps
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import importlib
4
4
  import os
5
5
  import uuid
6
+ from pathlib import Path
6
7
  from typing import TYPE_CHECKING, Literal
7
8
  from uuid import UUID
8
9
 
lamindb_setup/_migrate.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import requests # type: ignore
3
4
  from django.db import connection
4
5
  from django.db.migrations.loader import MigrationLoader
5
6
  from lamin_utils import logger
@@ -142,6 +143,13 @@ class migrate:
142
143
  logger.important(f"updating lamindb version in hub: {lamindb.__version__}")
143
144
  if settings.instance.dialect != "sqlite":
144
145
  update_schema_in_hub()
146
+ logger.warning(
147
+ "clearing instance cache in hub; if this fails, re-run with latest lamindb version"
148
+ )
149
+ requests.delete(
150
+ f"{settings.instance.api_url}/cache/instances/{settings.instance._id.hex}",
151
+ headers={"Authorization": f"Bearer {settings.user.access_token}"},
152
+ )
145
153
  call_with_fallback_auth(
146
154
  update_instance,
147
155
  instance_id=settings.instance._id.hex,
@@ -404,23 +404,27 @@ class _SchemaHandler:
404
404
  return self.to_dict(include_django_objects=False)
405
405
 
406
406
  def _get_modules_metadata(self):
407
+ from django.apps import apps
407
408
  from lamindb.models import Registry, SQLRecord
408
409
 
409
- all_models = {
410
- module_name: {
411
- model._meta.model_name: _ModelHandler(
412
- model, module_name, self.included_modules
413
- )
414
- for model in self._get_schema_module(
415
- module_name
416
- ).models.__dict__.values()
417
- if model.__class__ is Registry
410
+ all_models = {module_name: {} for module_name in self.included_modules}
411
+
412
+ # Iterate through all registered Django models
413
+ for model in apps.get_models():
414
+ # Check if model meets the criteria
415
+ if (
416
+ model.__class__ is Registry
418
417
  and model is not SQLRecord
419
418
  and not model._meta.abstract
420
- and model.__get_module_name__() == module_name
421
- }
422
- for module_name in self.included_modules
423
- }
419
+ ):
420
+ module_name = model.__get_module_name__()
421
+ # Only include if module is in our included list
422
+ if module_name in self.included_modules:
423
+ model_name = model._meta.model_name
424
+ all_models[module_name][model_name] = _ModelHandler(
425
+ model, module_name, self.included_modules
426
+ )
427
+
424
428
  assert all_models
425
429
  return all_models
426
430
 
@@ -661,7 +661,12 @@ def _sign_in_hub(email: str, password: str, handle: str | None, client: Client):
661
661
  "password": password,
662
662
  }
663
663
  )
664
- data = client.table("account").select("*").eq("id", auth.user.id).execute().data
664
+ # normally public.account.id is equal to auth.user.id
665
+ # but it might be not the case in the future
666
+ # this is why we check public.account.user_id that references auth.user.id
667
+ data = (
668
+ client.table("account").select("*").eq("user_id", auth.user.id).execute().data
669
+ )
665
670
  if data: # sync data from hub to local cache in case it was updated on the hub
666
671
  user = data[0]
667
672
  user_uuid = UUID(user["id"])
@@ -710,8 +715,9 @@ def _sign_in_hub_api_key(api_key: str, client: Client):
710
715
  # probably need more info here to avoid additional queries
711
716
  # like handle, uid etc
712
717
  account_id = jwt.decode(access_token, options={"verify_signature": False})["sub"]
718
+
713
719
  client.postgrest.auth(access_token)
714
- # normally public.account.id is equal to auth.user.id
720
+
715
721
  data = client.table("account").select("*").eq("id", account_id).execute().data
716
722
  if data:
717
723
  user = data[0]
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import os
4
4
  import sys
5
5
  import warnings
6
+ from pathlib import Path
6
7
  from typing import TYPE_CHECKING
7
8
 
8
9
  from lamin_utils import logger
@@ -23,8 +24,6 @@ from ._settings_store import (
23
24
  from .upath import LocalPathClasses, UPath
24
25
 
25
26
  if TYPE_CHECKING:
26
- from pathlib import Path
27
-
28
27
  from lamindb.models import Branch, Space
29
28
 
30
29
  from lamindb_setup.core import InstanceSettings, StorageSettings, UserSettings
@@ -60,6 +59,7 @@ class SetupSettings:
60
59
 
61
60
  _auto_connect_path: Path = settings_dir / "auto_connect"
62
61
  _private_django_api_path: Path = settings_dir / "private_django_api"
62
+ _work_dir: Path = settings_dir / "work_dir.txt"
63
63
 
64
64
  _cache_dir: Path | None = None
65
65
 
@@ -70,6 +70,25 @@ class SetupSettings:
70
70
  def _instance_settings_path(self) -> Path:
71
71
  return current_instance_settings_file()
72
72
 
73
+ @property
74
+ def work_dir(self) -> Path | None:
75
+ """Get or set the current working directory.
76
+
77
+ If setting it to `None`, the working directory is unset
78
+ """
79
+ if not self._work_dir.exists():
80
+ return None
81
+ return Path(self._work_dir.read_text())
82
+
83
+ @work_dir.setter
84
+ def work_dir(self, value: str | Path | None) -> None:
85
+ if value is None:
86
+ if self._work_dir.exists():
87
+ self._work_dir.unlink()
88
+ else:
89
+ value_str = Path(value).expanduser().resolve().as_posix()
90
+ self._work_dir.write_text(value_str)
91
+
73
92
  @property
74
93
  def settings_dir(self) -> Path:
75
94
  """The directory that holds locally persisted settings."""
@@ -317,6 +336,7 @@ class SetupSettings:
317
336
  repr += "\nConfig:\n"
318
337
  repr += f" - private Django API: {self.private_django_api}\n"
319
338
  repr += "Local directories:\n"
339
+ repr += f" - working directory: {self.work_dir}\n"
320
340
  repr += f" - cache: {self.cache_dir.as_posix()}\n"
321
341
  repr += f" - user settings: {settings_dir.as_posix()}\n"
322
342
  repr += f" - system settings: {system_settings_dir.as_posix()}\n"
@@ -168,7 +168,10 @@ def setup_django(
168
168
  ssl_require = False
169
169
  else:
170
170
  ssl_require = not is_local_db_url(instance_db)
171
- options = {"connect_timeout": os.getenv("PGCONNECT_TIMEOUT", 20)}
171
+ options = {
172
+ "connect_timeout": os.getenv("PGCONNECT_TIMEOUT", 20),
173
+ "gssencmode": "disable",
174
+ }
172
175
  else:
173
176
  ssl_require = False
174
177
  options = {}
@@ -3,6 +3,7 @@
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
+ import math
6
7
  import os
7
8
  import warnings
8
9
  from collections import defaultdict
@@ -353,6 +354,15 @@ def upload_from(
353
354
  destination = fsspec.utils.other_paths(
354
355
  files, self.as_posix(), exists=False, flatten=False
355
356
  )
357
+ elif self.protocol == "s3" and "chunksize" not in kwargs:
358
+ size = local_path.stat().st_size
359
+ MiB = 1024**2
360
+ DEFAULT_CHUNKSIZE = 50 * MiB # so in s3fs
361
+ if size / DEFAULT_CHUNKSIZE > 10000: # should be no more than 10k parts for s3
362
+ raw = math.ceil(size / 10000)
363
+ step = 5 * MiB
364
+ rounded = math.ceil(raw / step) * step
365
+ kwargs["chunksize"] = rounded
356
366
 
357
367
  # the below lines are to avoid s3fs triggering create_bucket in upload if
358
368
  # dirs are present, it allows to avoid the permission error
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lamindb_setup
3
- Version: 1.10.2
3
+ Version: 1.11.0
4
4
  Summary: Setup & configure LaminDB.
5
5
  Author-email: Lamin Labs <open-source@lamin.ai>
6
6
  Requires-Python: >=3.10
@@ -1,19 +1,19 @@
1
- lamindb_setup/__init__.py,sha256=X3c4WiIMGBIUrnNgq0NYa6vEZbdSPENtF4bbr2kHuwc,2783
1
+ lamindb_setup/__init__.py,sha256=iSKoEHzHwBMbBer5p_FuUPHJndK2eX3pfc6avRWqSaY,2783
2
2
  lamindb_setup/_cache.py,sha256=pGvDNVHGx4HWr_6w5ajqEJOdysmaGc6F221qFnXkT-k,2747
3
3
  lamindb_setup/_check.py,sha256=28PcG8Kp6OpjSLSi1r2boL2Ryeh6xkaCL87HFbjs6GA,129
4
4
  lamindb_setup/_check_setup.py,sha256=ToKMxsUq8dQBQh8baOrNVlSb1iC8h4zTg5dV8wMu0W4,6760
5
- lamindb_setup/_connect_instance.py,sha256=6pgE_8Kv8ZVytXzN6Qp5ZlOtMtqE93cIdSkdA3Ey8ko,17545
5
+ lamindb_setup/_connect_instance.py,sha256=BWQplcUNZ-hCLDwB1xUPtBrvcmLAl9-5-I5yfKc2tXE,17536
6
6
  lamindb_setup/_delete.py,sha256=4kS-_nQrV5xMvZE3BGCNEEGCboyGmqqDMXlckF0GxSk,5780
7
7
  lamindb_setup/_disconnect.py,sha256=FT8EpCm5XXDdhDH7QtAnkO3KPatq2HqT9VXGNjgJDbk,1232
8
8
  lamindb_setup/_django.py,sha256=uIQflpkp8l3axyPaKURlk3kacgpElVP5KOKmFxYSMGk,1454
9
9
  lamindb_setup/_entry_points.py,sha256=sKwXPX9xjOotoAjvgkU5LBwjjHLWVkh0ZGdiSsrch9k,522
10
10
  lamindb_setup/_exportdb.py,sha256=QLjoH4dEwqa01A12naKaDPglCCzl2_VLKWFfJRE_uSg,2113
11
11
  lamindb_setup/_importdb.py,sha256=fKv9ev5OOj_-bmzC8XZ1GxOcjIjI486yrHSHDWQrJeI,1874
12
- lamindb_setup/_init_instance.py,sha256=0DhUGJ6FERxVg30F4XhCfsXaIy3AP1UecQzyjEm-FLw,14965
13
- lamindb_setup/_migrate.py,sha256=oaqFcONqclTBXjxr4OWCJkSIH08nmC69xgVzdRq0N8U,10375
12
+ lamindb_setup/_init_instance.py,sha256=5FRECcB_wuQ9pFkQctooyI6fJV0ItpVaBOHlL5EjfIk,14990
13
+ lamindb_setup/_migrate.py,sha256=O84O2QLzLrXOK6ogeK4Nxtt-M2oLPUuZ8lKYo2pCcgU,10795
14
14
  lamindb_setup/_register_instance.py,sha256=RdUZxZWHLdbvdNZWpF8e0UWROb_T0cStWbzc5yUw34I,1047
15
15
  lamindb_setup/_schema.py,sha256=b3uzhhWpV5mQtDwhMINc2MabGCnGLESy51ito3yl6Wc,679
16
- lamindb_setup/_schema_metadata.py,sha256=yMSuLZc-7iWUV7tETNuKmcDeMW0wtUr5ypKxsKC-m7k,14898
16
+ lamindb_setup/_schema_metadata.py,sha256=VWO03tYBoU_rZF2eI2a5HSMPzpDS4kCE0Ul3fpvnSTA,15132
17
17
  lamindb_setup/_set_managed_storage.py,sha256=y5YQASsWNYVWUYeLgh3N2YBETYP7mBtbpxe3X_Vgb5I,2699
18
18
  lamindb_setup/_setup_user.py,sha256=DapdzT3u0f5LN5W9W9A6PWw-n8ejcJciQtHN9b5lidA,5889
19
19
  lamindb_setup/_silence_loggers.py,sha256=AKF_YcHvX32eGXdsYK8MJlxEaZ-Uo2f6QDRzjKFCtws,1568
@@ -26,11 +26,11 @@ lamindb_setup/core/_aws_storage.py,sha256=ofPTHXvF97I9eUCHxj5RPpUUqAcNV0VsPWpyKM
26
26
  lamindb_setup/core/_deprecated.py,sha256=M3vpM4fZPOncxY2qsXQAPeaEph28xWdv7tYaueaUyAA,2554
27
27
  lamindb_setup/core/_docs.py,sha256=3k-YY-oVaJd_9UIY-LfBg_u8raKOCNfkZQPA73KsUhs,276
28
28
  lamindb_setup/core/_hub_client.py,sha256=Pl3sEG2rasdJp4Rh5HNY0VsPVls-nfY0OxD5QzrYF9A,8678
29
- lamindb_setup/core/_hub_core.py,sha256=r1tpfDjzgv7phESjq_dqYk23fyvm1M4KaVI-snP3NLA,26477
29
+ lamindb_setup/core/_hub_core.py,sha256=6VNeREgFGjJ6nMNBlhbylV28oHZeoT0BlXL6dXzn9LU,26628
30
30
  lamindb_setup/core/_hub_crud.py,sha256=j6516H82kLjFUNPqFGUINbDw9YbofMgjxadGzYb0OS4,6362
31
31
  lamindb_setup/core/_hub_utils.py,sha256=6dyDGyzYFgVfR_lE3VN3CP1jGp98gxPtr-T91PAP05U,2687
32
32
  lamindb_setup/core/_private_django_api.py,sha256=By63l3vIEtK1pq246FhHq3tslxsaTJGKm5VakYluWp4,2656
33
- lamindb_setup/core/_settings.py,sha256=Xsn4Z-Z-gGM6q89f0SiWMaSDhIbTurwEwJLRsz6vspM,13312
33
+ lamindb_setup/core/_settings.py,sha256=s2wB0vMeR0D36YCtwMSbyfYj6R05cQc0JYO1SH89bqc,14033
34
34
  lamindb_setup/core/_settings_instance.py,sha256=P2O2RWOSx2OUuU2nJBaD8FV6EIZYvUGGqTeVabIBKsA,23325
35
35
  lamindb_setup/core/_settings_load.py,sha256=j20cy3J56ZBHLDfB2A8oKjekNetMNsy0_W3eWD36pWI,5161
36
36
  lamindb_setup/core/_settings_save.py,sha256=XZx-vow7BT6y3JpRBB2UOJp2vwc7jOGea4wSgOPqjPU,3262
@@ -39,12 +39,12 @@ lamindb_setup/core/_settings_store.py,sha256=QmeWIGdIyq7UmjfHiEB_0xRD8hY-8-ZR2Wn
39
39
  lamindb_setup/core/_settings_user.py,sha256=gFfyMf-738onbh1Mf4wsmLlenQJPtjQfpUgKnOlqc2o,1453
40
40
  lamindb_setup/core/_setup_bionty_sources.py,sha256=ox3X-SHiHa2lNPSWjwZhINypbLacX6kGwH6hVVrSFZc,1505
41
41
  lamindb_setup/core/cloud_sqlite_locker.py,sha256=H_CTUCjURFXwD1cCtV_Jn0_60iztZTkaesLLXIBgIxc,7204
42
- lamindb_setup/core/django.py,sha256=Er0ikZmWHx5rPkzbuWLNkq2XTL9yTcEL16iX1yz9R60,10470
42
+ lamindb_setup/core/django.py,sha256=kV8W3WZy5Rkhn4rDJv2GNoq8JYvX_8dLBHhDRZdSgwE,10542
43
43
  lamindb_setup/core/exceptions.py,sha256=qjMzqy_uzPA7mCOdnoWnS_fdA6OWbdZGftz-YYplrY0,84
44
44
  lamindb_setup/core/hashing.py,sha256=Y8Uc5uSGTfU6L2R_gb5w8DdHhGRog7RnkK-e9FEMjPY,3680
45
45
  lamindb_setup/core/types.py,sha256=T7NwspfRHgIIpYsXDcApks8jkOlGeGRW-YbVLB7jNIo,67
46
- lamindb_setup/core/upath.py,sha256=-Wxct7lYOLVzUGv3ynqq0zLcRSAGWbvs-NqrZL0Aqy4,35579
47
- lamindb_setup-1.10.2.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
48
- lamindb_setup-1.10.2.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
49
- lamindb_setup-1.10.2.dist-info/METADATA,sha256=B90EP2olTts5waIXLN5nLvIBqWnhY_FxeoMX9yLOnwk,1804
50
- lamindb_setup-1.10.2.dist-info/RECORD,,
46
+ lamindb_setup/core/upath.py,sha256=5mrAeAyYWXn1zJlwQmBM-NfXhpi2S-YsbEkXo_UESk0,36017
47
+ lamindb_setup-1.11.0.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
48
+ lamindb_setup-1.11.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
49
+ lamindb_setup-1.11.0.dist-info/METADATA,sha256=gvtfSb-3uOq8Vl0buE_koqO1zGu2B22kmcBNjmrChbQ,1804
50
+ lamindb_setup-1.11.0.dist-info/RECORD,,