lamindb_setup 1.7.1__py3-none-any.whl → 1.7.3__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.1" # denote a release candidate for 0.1.0 with 0.1rc1
38
+ __version__ = "1.7.3" # denote a release candidate for 0.1.0 with 0.1rc1
39
39
 
40
40
  import os
41
41
 
@@ -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
  )
@@ -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
 
@@ -91,6 +93,94 @@ class SetupSettings:
91
93
  else:
92
94
  self._auto_connect_path.unlink(missing_ok=True)
93
95
 
96
+ @property
97
+ def _branch_path(self) -> Path:
98
+ return (
99
+ settings_dir
100
+ / f"current-branch--{self.instance.owner}--{self.instance.name}.txt"
101
+ )
102
+
103
+ def _read_branch_idlike_name(self) -> tuple[int | str, str]:
104
+ idlike: str | int = 1
105
+ name: str = "main"
106
+ try:
107
+ branch_path = self._branch_path
108
+ except SystemExit: # in case no instance setup
109
+ return idlike, name
110
+ if branch_path.exists():
111
+ idlike, name = branch_path.read_text().split("\n")
112
+ return idlike, name
113
+
114
+ @property
115
+ def branch(self) -> Branch:
116
+ """Default branch."""
117
+ from lamindb import Branch
118
+
119
+ idlike, _ = self._read_branch_idlike_name()
120
+ return Branch.get(idlike)
121
+
122
+ @branch.setter
123
+ def branch(self, value: str | Branch) -> None:
124
+ from lamindb import Branch, Q
125
+ from lamindb.errors import DoesNotExist
126
+
127
+ if isinstance(value, Branch):
128
+ assert value._state.adding is False, "Branch must be saved"
129
+ branch_record = value
130
+ else:
131
+ branch_record = Branch.filter(Q(name=value) | Q(uid=value)).one_or_none()
132
+ if branch_record is None:
133
+ raise DoesNotExist(
134
+ f"Branch '{value}', please check on the hub UI whether you have the correct `uid` or `name`."
135
+ )
136
+ # we are sure that the current instance is setup because
137
+ # it will error on lamindb import otherwise
138
+ self._branch_path.write_text(f"{branch_record.uid}\n{branch_record.name}")
139
+
140
+ @property
141
+ def _space_path(self) -> Path:
142
+ return (
143
+ settings_dir
144
+ / f"current-space--{self.instance.owner}--{self.instance.name}.txt"
145
+ )
146
+
147
+ def _read_space_idlike_name(self) -> tuple[int | str, str]:
148
+ idlike: str | int = 1
149
+ name: str = "all"
150
+ try:
151
+ space_path = self._space_path
152
+ except SystemExit: # in case no instance setup
153
+ return idlike, name
154
+ if space_path.exists():
155
+ idlike, name = space_path.read_text().split("\n")
156
+ return idlike, name
157
+
158
+ @property
159
+ def space(self) -> Space:
160
+ """Default space."""
161
+ from lamindb import Space
162
+
163
+ idlike, _ = self._read_space_idlike_name()
164
+ return Space.get(idlike)
165
+
166
+ @space.setter
167
+ def space(self, value: str | Space) -> None:
168
+ from lamindb import Q, Space
169
+ from lamindb.errors import DoesNotExist
170
+
171
+ if isinstance(value, Space):
172
+ assert value._state.adding is False, "Space must be saved"
173
+ space_record = value
174
+ else:
175
+ space_record = Space.filter(Q(name=value) | Q(uid=value)).one_or_none()
176
+ if space_record is None:
177
+ raise DoesNotExist(
178
+ f"Space '{value}', please check on the hub UI whether you have the correct `uid` or `name`."
179
+ )
180
+ # we are sure that the current instance is setup because
181
+ # it will error on lamindb import otherwise
182
+ self._space_path.write_text(f"{space_record.uid}\n{space_record.name}")
183
+
94
184
  @property
95
185
  def is_connected(self) -> bool:
96
186
  """Determine whether the current instance is fully connected and ready to use.
@@ -205,16 +295,22 @@ class SetupSettings:
205
295
  # do not show current setting representation when building docs
206
296
  if "sphinx" in sys.modules:
207
297
  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"
298
+ repr = ""
214
299
  if self._instance_exists:
300
+ repr += "Current branch & space:\n"
301
+ repr += f" - branch: {self._read_branch_idlike_name()[1]}\n"
302
+ repr += f" - space: {self._read_space_idlike_name()[1]}\n"
215
303
  repr += self.instance.__repr__()
216
304
  else:
217
- repr += "\nNo instance connected"
305
+ repr += "Current instance: None"
306
+ repr += "\nConfig:\n"
307
+ repr += f" - auto-connect in Python: {self.auto_connect}\n"
308
+ repr += f" - private Django API: {self.private_django_api}\n"
309
+ repr += "Local directories:\n"
310
+ repr += f" - cache: {self.cache_dir.as_posix()}\n"
311
+ repr += f" - user settings: {settings_dir.as_posix()}\n"
312
+ repr += f" - system settings: {system_settings_dir.as_posix()}\n"
313
+ repr += self.user.__repr__()
218
314
  return repr
219
315
 
220
316
 
@@ -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.1
3
+ Version: 1.7.3
4
4
  Summary: Setup & configure LaminDB.
5
5
  Author-email: Lamin Labs <open-source@lamin.ai>
6
6
  Requires-Python: >=3.10
@@ -1,4 +1,4 @@
1
- lamindb_setup/__init__.py,sha256=jC_Rb1xvhIFtY2hWmuzYijeL2V6dfen9NrVtKjGJlr4,2782
1
+ lamindb_setup/__init__.py,sha256=YCc_Qq5IYq91E9yQdWzQwsOoWSjH5qBpBkZulYdQaJ0,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
@@ -9,7 +9,7 @@ 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=Zb0YjDkAkNCY3KHdiU0tNDB8vc7GH4dSGyFzzzXmyhc,15300
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=0la2eYAHcdMYophheGsgQaD2nJGQrPuX4jMV5GKDiC0,12946
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.1.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
48
- lamindb_setup-1.7.1.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
49
- lamindb_setup-1.7.1.dist-info/METADATA,sha256=wa-lWsy1r7Sf-zRXpIAoWtBB9KiyKd8x97ynmUQnIcE,1797
50
- lamindb_setup-1.7.1.dist-info/RECORD,,
47
+ lamindb_setup-1.7.3.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
48
+ lamindb_setup-1.7.3.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
49
+ lamindb_setup-1.7.3.dist-info/METADATA,sha256=LkK3UmxVpUDNES_P4zFdkeMx02PzrEWjAtqPrpX0-PQ,1797
50
+ lamindb_setup-1.7.3.dist-info/RECORD,,