lamindb_setup 1.7.0__py3-none-any.whl → 1.7.2__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.7.0" # denote a release candidate for 0.1.0 with 0.1rc1
38
+ __version__ = "1.7.2" # denote a release candidate for 0.1.0 with 0.1rc1
39
39
 
40
40
  import os
41
41
 
@@ -9,7 +9,10 @@ from lamin_utils import logger
9
9
 
10
10
  from ._check_setup import _check_instance_setup, _get_current_instance_settings
11
11
  from ._disconnect import disconnect
12
- from ._init_instance import load_from_isettings
12
+ from ._init_instance import (
13
+ MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE,
14
+ load_from_isettings,
15
+ )
13
16
  from ._silence_loggers import silence_loggers
14
17
  from .core._hub_core import connect_instance_hub
15
18
  from .core._hub_utils import (
@@ -238,9 +241,9 @@ def connect(instance: str | None = None, **kwargs: Any) -> str | tuple | None:
238
241
  logger.important(f"connected lamindb: {settings.instance.slug}")
239
242
  return None
240
243
  else:
241
- from lamindb_setup.core.django import reset_django
242
-
243
- reset_django()
244
+ raise CannotSwitchDefaultInstance(
245
+ MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE
246
+ )
244
247
  elif (
245
248
  _write_settings
246
249
  and settings._instance_exists
@@ -98,24 +98,24 @@ def register_initial_records(isettings: InstanceSettings, usettings: UserSetting
98
98
 
99
99
  try:
100
100
  Space.objects.get_or_create(
101
- uid="a",
101
+ uid=12 * "a",
102
102
  name="all",
103
103
  description="Every team & user with access to the instance has access.",
104
104
  )
105
105
  Branch.objects.get_or_create(
106
106
  id=-1,
107
- uid="t",
107
+ uid=12 * "t",
108
108
  name="trash",
109
109
  description="The trash.",
110
110
  )
111
111
  Branch.objects.get_or_create(
112
112
  id=0,
113
- uid="a",
113
+ uid=12 * "a",
114
114
  name="archive",
115
115
  description="The archive.",
116
116
  )
117
117
  Branch.objects.get_or_create(
118
- uid="m",
118
+ uid=12 * "m",
119
119
  name="main",
120
120
  description="The main & default branch of the instance.",
121
121
  )
@@ -215,6 +215,16 @@ def validate_init_args(
215
215
  return name_str, instance_id, instance_state, instance_slug
216
216
 
217
217
 
218
+ MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE = """
219
+ You cannot write to different instances in the same Python session.
220
+
221
+ Do you want to read from another instance via `SQLRecord.using()`? For example:
222
+
223
+ ln.Artifact.using("laminlabs/cellxgene").filter()
224
+
225
+ Or do you want to switch off auto-connect via `lamin settings set auto-connect false`?
226
+ """
227
+
218
228
  DOC_STORAGE_ARG = "A local or remote folder (`'s3://...'` or `'gs://...'`). Defaults to current working directory."
219
229
  DOC_INSTANCE_NAME = (
220
230
  "Instance name. If not passed, it will equal the folder name passed to `storage`."
@@ -262,9 +272,7 @@ def init(
262
272
  from ._check_setup import _check_instance_setup
263
273
 
264
274
  if _check_instance_setup() and not _test:
265
- from lamindb_setup.core.django import reset_django
266
-
267
- reset_django()
275
+ raise CannotSwitchDefaultInstance(MESSAGE_CANNOT_SWITCH_DEFAULT_INSTANCE)
268
276
  elif _write_settings:
269
277
  disconnect(mute=True)
270
278
  from .core._hub_core import init_instance_hub
@@ -70,7 +70,7 @@ def connect_hub(
70
70
  # increase to avoid rare timeouts for edge functions
71
71
  client_options = ClientOptions(
72
72
  auto_refresh_token=False,
73
- function_client_timeout=20,
73
+ function_client_timeout=30,
74
74
  postgrest_client_timeout=20,
75
75
  )
76
76
  return create_client(env.supabase_api_url, env.supabase_anon_key, client_options)
@@ -380,14 +380,16 @@ def _connect_instance_hub(
380
380
  .data
381
381
  )
382
382
  if len(data) != 0 and (instance_data := data[0]["instance"]) is not None:
383
- new_name = instance_data["name"] # the instance was renamed
384
- logger.warning(
385
- f"'{owner}/{name}' was renamed, please use '{owner}/{new_name}'"
386
- )
387
- response = client.functions.invoke(
388
- "get-instance-settings-v1",
389
- invoke_options={"body": {"owner": owner, "name": new_name}},
390
- )
383
+ new_name = instance_data["name"]
384
+ # the instance was renamed
385
+ if new_name != name:
386
+ logger.warning(
387
+ f"'{owner}/{name}' was renamed, please use '{owner}/{new_name}'"
388
+ )
389
+ response = client.functions.invoke(
390
+ "get-instance-settings-v1",
391
+ invoke_options={"body": {"owner": owner, "name": new_name}},
392
+ )
391
393
  # no instance found, check why is that
392
394
  if response == b"{}":
393
395
  # try the via single requests, will take more time
@@ -22,6 +22,8 @@ from .upath import LocalPathClasses, UPath
22
22
  if TYPE_CHECKING:
23
23
  from pathlib import Path
24
24
 
25
+ from lamindb.models import Branch, Space
26
+
25
27
  from lamindb_setup.core import InstanceSettings, StorageSettings, UserSettings
26
28
  from lamindb_setup.types import UPathStr
27
29
 
@@ -54,6 +56,8 @@ class SetupSettings:
54
56
  _instance_settings_env: str | None = None
55
57
 
56
58
  _auto_connect_path: Path = settings_dir / "auto_connect"
59
+ _branch_path: Path = settings_dir / "branch_uid.txt"
60
+ _space_path: Path = settings_dir / "space_uid.txt"
57
61
  _private_django_api_path: Path = settings_dir / "private_django_api"
58
62
 
59
63
  _cache_dir: Path | None = None
@@ -91,6 +95,58 @@ class SetupSettings:
91
95
  else:
92
96
  self._auto_connect_path.unlink(missing_ok=True)
93
97
 
98
+ @property
99
+ def branch(self) -> Branch:
100
+ """Default branch."""
101
+ from lamindb import Branch
102
+
103
+ idlike: str | int = 1
104
+ if self._branch_path.exists():
105
+ idlike = self._branch_path.read_text()
106
+ return Branch.get(idlike)
107
+
108
+ @branch.setter
109
+ def branch(self, value: str | Branch) -> None:
110
+ from lamindb import Branch, Q
111
+ from lamindb.errors import DoesNotExist
112
+
113
+ if isinstance(value, Branch):
114
+ assert value._state.adding is False, "Branch must be saved"
115
+ branch_record = value
116
+ else:
117
+ branch_record = Branch.filter(Q(name=value) | Q(uid=value)).one_or_none()
118
+ if branch_record is None:
119
+ raise DoesNotExist(
120
+ f"Branch '{value}', please check on the hub UI whether you have the correct `uid` or `name`."
121
+ )
122
+ self._branch_path.write_text(branch_record.uid)
123
+
124
+ @property
125
+ def space(self) -> Space:
126
+ """Default space."""
127
+ from lamindb import Space
128
+
129
+ idlike: str | int = 1
130
+ if self._space_path.exists():
131
+ idlike = self._space_path.read_text()
132
+ return Space.get(idlike)
133
+
134
+ @space.setter
135
+ def space(self, value: str | Space) -> None:
136
+ from lamindb import Q, Space
137
+ from lamindb.errors import DoesNotExist
138
+
139
+ if isinstance(value, Space):
140
+ assert value._state.adding is False, "Space must be saved"
141
+ space_record = value
142
+ else:
143
+ space_record = Space.filter(Q(name=value) | Q(uid=value)).one_or_none()
144
+ if space_record is None:
145
+ raise DoesNotExist(
146
+ f"Space '{value}', please check on the hub UI whether you have the correct `uid` or `name`."
147
+ )
148
+ self._space_path.write_text(space_record.uid)
149
+
94
150
  @property
95
151
  def is_connected(self) -> bool:
96
152
  """Determine whether the current instance is fully connected and ready to use.
@@ -205,16 +261,22 @@ class SetupSettings:
205
261
  # do not show current setting representation when building docs
206
262
  if "sphinx" in sys.modules:
207
263
  return object.__repr__(self)
208
- repr = f"Auto-connect in Python: {self.auto_connect}\n"
209
- repr += f"Private Django API: {self.private_django_api}\n"
210
- repr += f"Cache directory: {self.cache_dir.as_posix()}\n"
211
- repr += f"User settings directory: {settings_dir.as_posix()}\n"
212
- repr += f"System settings directory: {system_settings_dir.as_posix()}\n"
213
- repr += self.user.__repr__() + "\n"
264
+ repr = ""
214
265
  if self._instance_exists:
266
+ repr += "Current branch & space:\n"
267
+ repr += f" - branch: {self.branch.name}\n"
268
+ repr += f" - space: {self.space.name}\n"
215
269
  repr += self.instance.__repr__()
216
270
  else:
217
- repr += "\nNo instance connected"
271
+ repr += "Current instance: None"
272
+ repr += "\nConfig:\n"
273
+ repr += f" - auto-connect in Python: {self.auto_connect}\n"
274
+ repr += f" - private Django API: {self.private_django_api}\n"
275
+ repr += "Local directories:\n"
276
+ repr += f" - cache: {self.cache_dir.as_posix()}\n"
277
+ repr += f" - user settings: {settings_dir.as_posix()}\n"
278
+ repr += f" - system settings: {system_settings_dir.as_posix()}\n"
279
+ repr += self.user.__repr__()
218
280
  return repr
219
281
 
220
282
 
@@ -97,13 +97,13 @@ class InstanceSettings:
97
97
 
98
98
  def __repr__(self):
99
99
  """Rich string representation."""
100
- representation = f"Current instance: {self.slug}"
101
- attrs = ["owner", "name", "storage", "db", "modules", "git_repo"]
100
+ representation = "Current instance:"
101
+ attrs = ["slug", "storage", "db", "modules", "git_repo"]
102
102
  for attr in attrs:
103
103
  value = getattr(self, attr)
104
104
  if attr == "storage":
105
- representation += f"\n- storage root: {value.root_as_str}"
106
- representation += f"\n- storage region: {value.region}"
105
+ representation += f"\n - storage root: {value.root_as_str}"
106
+ representation += f"\n - storage region: {value.region}"
107
107
  elif attr == "db":
108
108
  if self.dialect != "sqlite":
109
109
  model = LaminDsnModel(db=value)
@@ -117,11 +117,11 @@ class InstanceSettings:
117
117
  )
118
118
  else:
119
119
  db_print = value
120
- representation += f"\n- {attr}: {db_print}"
120
+ representation += f"\n - {attr}: {db_print}"
121
121
  elif attr == "modules":
122
- representation += f"\n- {attr}: {value if value else '{}'}"
122
+ representation += f"\n - {attr}: {value if value else '{}'}"
123
123
  else:
124
- representation += f"\n- {attr}: {value}"
124
+ representation += f"\n - {attr}: {value}"
125
125
  return representation
126
126
 
127
127
  @property
@@ -38,11 +38,11 @@ class UserSettings:
38
38
 
39
39
  def __repr__(self) -> str:
40
40
  """Rich string representation."""
41
- representation = f"Current user: {self.handle}"
41
+ representation = "Current user:"
42
42
  attrs = ["handle", "email", "uid"]
43
43
  for attr in attrs:
44
44
  value = getattr(self, attr)
45
- representation += f"\n- {attr}: {value}"
45
+ representation += f"\n - {attr}: {value}"
46
46
  return representation
47
47
 
48
48
  @property
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lamindb_setup
3
- Version: 1.7.0
3
+ Version: 1.7.2
4
4
  Summary: Setup & configure LaminDB.
5
5
  Author-email: Lamin Labs <open-source@lamin.ai>
6
6
  Requires-Python: >=3.10
@@ -1,15 +1,15 @@
1
- lamindb_setup/__init__.py,sha256=czSdhM6f8e3Kh7eGH6JIMndX_G6Bf4SuZjt-QilKceQ,2782
1
+ lamindb_setup/__init__.py,sha256=rXOlL53oN84rtC715KZqc82f3DmiFQu7G2giORCTMdY,2782
2
2
  lamindb_setup/_cache.py,sha256=5o749NuW6zi6uP4rmBtwxg7ifWpAHXVngzC0tEgXLgo,2776
3
3
  lamindb_setup/_check.py,sha256=28PcG8Kp6OpjSLSi1r2boL2Ryeh6xkaCL87HFbjs6GA,129
4
4
  lamindb_setup/_check_setup.py,sha256=bXuqx2HEc178RM7gbKZQ65PEVJFu6uSOKiHAs_xz6GI,5575
5
- lamindb_setup/_connect_instance.py,sha256=WjkQ-u__4vogsofmjKX2Vc5ELG7P4IuK3O2MEEcboKQ,12638
5
+ lamindb_setup/_connect_instance.py,sha256=wQARuWyPSc9V5gYSADi_GIrwkyxNlZmsQT8-SbDHh-8,12724
6
6
  lamindb_setup/_delete.py,sha256=2KnZOqd5Kgr45XzjiDE9der35LODDUajZD6_hcurGtQ,5676
7
7
  lamindb_setup/_disconnect.py,sha256=p6tRLhixU4CuSxMKqzGTr-ovKmTRlZ8aID5dWQxOsg8,1092
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=KeY3qcmQecCKjNVUN5ah59sztdi4lKoaeq8L7FVmIoQ,14967
12
+ lamindb_setup/_init_instance.py,sha256=jNNE7ZWIl1V28YqfdbaiyZ_One6K2vv0RMubxdvvb74,15320
13
13
  lamindb_setup/_migrate.py,sha256=ya-15sc91i4JmEWI4j00T2892x8hdy2fSW-qz4IdxLs,9739
14
14
  lamindb_setup/_register_instance.py,sha256=zmk7UrOF6qED_zTEaTM8GbZurMSP1SwddkRy7rpYmUY,1215
15
15
  lamindb_setup/_schema.py,sha256=b3uzhhWpV5mQtDwhMINc2MabGCnGLESy51ito3yl6Wc,679
@@ -25,18 +25,18 @@ lamindb_setup/core/_aws_options.py,sha256=JN6fJNcotdIuT-WkBRKDPdyDri9XmorEX2unbu
25
25
  lamindb_setup/core/_aws_storage.py,sha256=nEjeUv4xUVpoV0Lx-zjjmyb9w804bDyaeiM-OqbfwM0,1799
26
26
  lamindb_setup/core/_deprecated.py,sha256=HN7iUBdEgahw5e4NHCd1VJooUfieNb6GRzS5x8jU-q8,2549
27
27
  lamindb_setup/core/_docs.py,sha256=3k-YY-oVaJd_9UIY-LfBg_u8raKOCNfkZQPA73KsUhs,276
28
- lamindb_setup/core/_hub_client.py,sha256=3RD5WiXtutLulcoqICuLLHu8i-OH0sPvSnOse9HYUzY,7718
29
- lamindb_setup/core/_hub_core.py,sha256=QjYvv_p0TSG8M-21_cCGk24ZDPnbHhGJqsIq6KZnmz4,23790
28
+ lamindb_setup/core/_hub_client.py,sha256=iMAEwhvhsI85DWZdNT9Vv1K-AlXHw5dmTFDZB3FyAKE,7718
29
+ lamindb_setup/core/_hub_core.py,sha256=x77WpaPMr1uA1kJBSvM5JRNyRG0vYIVlxQbhjAdOhu8,23862
30
30
  lamindb_setup/core/_hub_crud.py,sha256=Jz0d8wFKM1Pv9B9byyUJPlCIMkIzk56Jd-c3Awpm9Xw,5730
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=FV9EM3_sCQW036e_qY2c2PKfscquT_epZ76M0P_8QeU,9505
34
- lamindb_setup/core/_settings_instance.py,sha256=ERsnNGnRs4pUHOQi0rk3WcSfi_049701FRSXOj--lhI,19535
33
+ lamindb_setup/core/_settings.py,sha256=SIXxs0ZCqjNz53PwPYdLoC5sMQ2pjraEBZ3BpA8jGYU,11726
34
+ lamindb_setup/core/_settings_instance.py,sha256=nXSOc6qPwamcoD-4W8sIOFD_L-W8VO8e0tT-U0INuYo,19518
35
35
  lamindb_setup/core/_settings_load.py,sha256=JWd0_hBy04xjKo-tH4y8C9RkaywjrmoT0PsKzVme0n4,5176
36
36
  lamindb_setup/core/_settings_save.py,sha256=XZx-vow7BT6y3JpRBB2UOJp2vwc7jOGea4wSgOPqjPU,3262
37
37
  lamindb_setup/core/_settings_storage.py,sha256=AY3OpJd2uOR8nTrJUzESq_sS1P1Uo_y9oqi5_NdcSPQ,16353
38
38
  lamindb_setup/core/_settings_store.py,sha256=QmeWIGdIyq7UmjfHiEB_0xRD8hY-8-ZR2WntIKfwTKI,2714
39
- lamindb_setup/core/_settings_user.py,sha256=5hmnMu6fxrHAcwBEtIL0P9N8V4B0SjhzIdqFQ9o3Tsg,1476
39
+ lamindb_setup/core/_settings_user.py,sha256=K2a6nQ0fhEiSb9mCY_p6ItNrHZ3J_j7EfO7CjZap9aA,1462
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
42
  lamindb_setup/core/django.py,sha256=dOt1OkUnZeYOo-LTjatQWQFh_MnjRf9IwwvRZhCwdZQ,9637
@@ -44,7 +44,7 @@ lamindb_setup/core/exceptions.py,sha256=qjMzqy_uzPA7mCOdnoWnS_fdA6OWbdZGftz-YYpl
44
44
  lamindb_setup/core/hashing.py,sha256=Y8Uc5uSGTfU6L2R_gb5w8DdHhGRog7RnkK-e9FEMjPY,3680
45
45
  lamindb_setup/core/types.py,sha256=T7NwspfRHgIIpYsXDcApks8jkOlGeGRW-YbVLB7jNIo,67
46
46
  lamindb_setup/core/upath.py,sha256=tvu178E08VSC7YUNrcDYxri4ODuVtX3BGNhJO8UZf00,34302
47
- lamindb_setup-1.7.0.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
48
- lamindb_setup-1.7.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
49
- lamindb_setup-1.7.0.dist-info/METADATA,sha256=0xpYGkvJz0YXz4VJ6QWctANg8n3ecQ8ndqjDQNjjUp8,1797
50
- lamindb_setup-1.7.0.dist-info/RECORD,,
47
+ lamindb_setup-1.7.2.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
48
+ lamindb_setup-1.7.2.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
49
+ lamindb_setup-1.7.2.dist-info/METADATA,sha256=RO5_HhbMpABK27CGooW3cLDubeImzHtltprOJB4sLUQ,1797
50
+ lamindb_setup-1.7.2.dist-info/RECORD,,