lamindb_setup 1.19.0__py3-none-any.whl → 1.19.1__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.
Files changed (49) hide show
  1. lamindb_setup/__init__.py +1 -1
  2. lamindb_setup/_cache.py +87 -87
  3. lamindb_setup/_check.py +7 -7
  4. lamindb_setup/_check_setup.py +131 -131
  5. lamindb_setup/_connect_instance.py +443 -441
  6. lamindb_setup/_delete.py +155 -155
  7. lamindb_setup/_disconnect.py +38 -38
  8. lamindb_setup/_django.py +39 -39
  9. lamindb_setup/_entry_points.py +19 -19
  10. lamindb_setup/_init_instance.py +423 -423
  11. lamindb_setup/_migrate.py +331 -331
  12. lamindb_setup/_register_instance.py +32 -32
  13. lamindb_setup/_schema.py +27 -27
  14. lamindb_setup/_schema_metadata.py +451 -451
  15. lamindb_setup/_set_managed_storage.py +81 -81
  16. lamindb_setup/_setup_user.py +198 -198
  17. lamindb_setup/_silence_loggers.py +46 -46
  18. lamindb_setup/core/__init__.py +25 -34
  19. lamindb_setup/core/_aws_options.py +276 -276
  20. lamindb_setup/core/_aws_storage.py +57 -57
  21. lamindb_setup/core/_clone.py +50 -50
  22. lamindb_setup/core/_deprecated.py +62 -62
  23. lamindb_setup/core/_docs.py +14 -14
  24. lamindb_setup/core/_hub_client.py +288 -288
  25. lamindb_setup/core/_hub_crud.py +247 -247
  26. lamindb_setup/core/_hub_utils.py +100 -100
  27. lamindb_setup/core/_private_django_api.py +80 -80
  28. lamindb_setup/core/_settings.py +440 -434
  29. lamindb_setup/core/_settings_instance.py +22 -1
  30. lamindb_setup/core/_settings_load.py +162 -162
  31. lamindb_setup/core/_settings_save.py +108 -108
  32. lamindb_setup/core/_settings_storage.py +433 -433
  33. lamindb_setup/core/_settings_store.py +162 -162
  34. lamindb_setup/core/_settings_user.py +55 -55
  35. lamindb_setup/core/_setup_bionty_sources.py +44 -44
  36. lamindb_setup/core/cloud_sqlite_locker.py +240 -240
  37. lamindb_setup/core/django.py +414 -413
  38. lamindb_setup/core/exceptions.py +1 -1
  39. lamindb_setup/core/hashing.py +134 -134
  40. lamindb_setup/core/types.py +1 -1
  41. lamindb_setup/core/upath.py +1031 -1028
  42. lamindb_setup/errors.py +72 -72
  43. lamindb_setup/io.py +423 -423
  44. lamindb_setup/types.py +17 -17
  45. {lamindb_setup-1.19.0.dist-info → lamindb_setup-1.19.1.dist-info}/METADATA +3 -2
  46. lamindb_setup-1.19.1.dist-info/RECORD +51 -0
  47. {lamindb_setup-1.19.0.dist-info → lamindb_setup-1.19.1.dist-info}/WHEEL +1 -1
  48. {lamindb_setup-1.19.0.dist-info → lamindb_setup-1.19.1.dist-info/licenses}/LICENSE +201 -201
  49. lamindb_setup-1.19.0.dist-info/RECORD +0 -51
@@ -1,247 +1,247 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
- from uuid import UUID, uuid4
5
-
6
- from lamin_utils import logger
7
- from supabase.client import Client # noqa
8
-
9
-
10
- def select_instance_by_owner_name(
11
- owner: str,
12
- name: str,
13
- client: Client,
14
- ) -> dict | None:
15
- # this won't find an instance without the default storage
16
- data = (
17
- client.table("instance")
18
- .select(
19
- "*, account!inner!instance_account_id_28936e8f_fk_account_id(*),"
20
- " storage!inner!storage_instance_id_359fca71_fk_instance_id(*)"
21
- )
22
- .eq("name", name)
23
- .eq("account.handle", owner)
24
- .eq("storage.is_default", True)
25
- .execute()
26
- .data
27
- )
28
- if len(data) == 0:
29
- return None
30
- result = data[0]
31
- # this is a list
32
- # assume only one default storage
33
- result["storage"] = result["storage"][0]
34
- return result
35
-
36
-
37
- # --------------- ACCOUNT ----------------------
38
- def select_account_by_handle(
39
- handle: str,
40
- client: Client,
41
- ):
42
- data = client.table("account").select("*").eq("handle", handle).execute().data
43
- if len(data) == 0:
44
- return None
45
- return data[0]
46
-
47
-
48
- def select_account_handle_name_by_lnid(lnid: str, client: Client):
49
- data = (
50
- client.table("account").select("handle, name").eq("lnid", lnid).execute().data
51
- )
52
- if not data:
53
- return None
54
- return data[0]
55
-
56
-
57
- # --------------- INSTANCE ----------------------
58
- def select_instance_by_name(
59
- account_id: str,
60
- name: str,
61
- client: Client,
62
- ):
63
- data = (
64
- client.table("instance")
65
- .select("*")
66
- .eq("account_id", account_id)
67
- .eq("name", name)
68
- .execute()
69
- .data
70
- )
71
- if len(data) != 0:
72
- return data[0]
73
-
74
- data = (
75
- client.table("instance_previous_name")
76
- .select(
77
- "instance!instance_previous_name_instance_id_17ac5d61_fk_instance_id(*)"
78
- )
79
- .eq("instance.account_id", account_id)
80
- .eq("previous_name", name)
81
- .execute()
82
- .data
83
- )
84
- if len(data) != 0:
85
- return data[0]["instance"]
86
-
87
- return None
88
-
89
-
90
- def select_instance_by_id(
91
- instance_id: str,
92
- client: Client,
93
- ):
94
- response = client.table("instance").select("*").eq("id", instance_id).execute()
95
- if len(response.data) == 0:
96
- return None
97
- return response.data[0]
98
-
99
-
100
- def select_instance_by_id_with_storage(
101
- instance_id: str,
102
- client: Client,
103
- ):
104
- # this won't find an instance without the default storage
105
- data = (
106
- client.table("instance")
107
- .select("*, storage!inner!storage_instance_id_359fca71_fk_instance_id(*)")
108
- .eq("id", instance_id)
109
- .eq("storage.is_default", True)
110
- .execute()
111
- .data
112
- )
113
- if len(data) == 0:
114
- return None
115
- result = data[0]
116
- # this is a list
117
- # assume only one default storage
118
- result["storage"] = result["storage"][0]
119
- return result
120
-
121
-
122
- def update_instance(instance_id: str, instance_fields: dict, client: Client):
123
- response = (
124
- client.table("instance").update(instance_fields).eq("id", instance_id).execute()
125
- )
126
- if len(response.data) == 0:
127
- raise PermissionError(
128
- f"Update of instance with {instance_id} was not successful. Probably, you"
129
- " don't have sufficient permissions."
130
- )
131
- return response.data[0]
132
-
133
-
134
- # --------------- COLLABORATOR ----------------------
135
-
136
-
137
- def select_collaborator(
138
- instance_id: str,
139
- account_id: str,
140
- fine_grained_access: bool,
141
- client: Client,
142
- ):
143
- table = "access_instance" if fine_grained_access else "account_instance"
144
- data = (
145
- client.table(table)
146
- .select("*")
147
- .eq("instance_id", instance_id)
148
- .eq("account_id", account_id)
149
- .execute()
150
- .data
151
- )
152
- if len(data) == 0:
153
- return None
154
- return data[0]
155
-
156
-
157
- # --------------- STORAGE ----------------------
158
-
159
-
160
- def select_default_storage_by_instance_id(
161
- instance_id: str, client: Client
162
- ) -> dict | None:
163
- data = (
164
- client.table("storage")
165
- .select("*")
166
- .eq("instance_id", instance_id)
167
- .eq("is_default", True)
168
- .execute()
169
- .data
170
- )
171
- if len(data) == 0:
172
- return None
173
- return data[0]
174
-
175
-
176
- # --------------- DBUser ----------------------
177
-
178
-
179
- def insert_db_user(
180
- *,
181
- name: str,
182
- db_user_name: str,
183
- db_user_password: str,
184
- instance_id: UUID,
185
- fine_grained_access: bool,
186
- client: Client,
187
- ) -> None:
188
- fields = {"instance_id": instance_id.hex}
189
- if fine_grained_access:
190
- table = "access_db_user"
191
- fields.update(
192
- {
193
- "name": db_user_name,
194
- "password": db_user_password,
195
- "type": name,
196
- }
197
- )
198
- else:
199
- table = "db_user"
200
- fields.update(
201
- {
202
- "id": uuid4().hex,
203
- "name": name,
204
- "db_user_name": db_user_name,
205
- "db_user_password": db_user_password,
206
- }
207
- )
208
-
209
- data = client.table(table).insert(fields).execute().data
210
- return data[0]
211
-
212
-
213
- def select_db_user_by_instance(
214
- instance_id: str, fine_grained_access: bool, client: Client
215
- ):
216
- """Get db_user for which client has permission."""
217
- if fine_grained_access:
218
- table = "access_db_user"
219
- type_name = "type"
220
- type_priority = "jwt"
221
- else:
222
- table = "db_user"
223
- type_name = "name"
224
- type_priority = "write"
225
-
226
- data = client.table(table).select("*").eq("instance_id", instance_id).execute().data
227
- if len(data) == 0:
228
- return None
229
- elif len(data) > 1:
230
- for item in data:
231
- if item[type_name] == type_priority:
232
- return item
233
- logger.warning("found multiple db credentials, using the first one")
234
- return data[0]
235
-
236
-
237
- def _delete_instance_record(instance_id: UUID, client: Client) -> None:
238
- if not isinstance(instance_id, UUID):
239
- instance_id = UUID(instance_id)
240
- response = client.table("instance").delete().eq("id", instance_id.hex).execute()
241
- if response.data:
242
- logger.important(f"deleted instance record on hub {instance_id.hex}")
243
- else:
244
- raise PermissionError(
245
- f"Deleting of instance with {instance_id.hex} was not successful. Probably, you"
246
- " don't have sufficient permissions."
247
- )
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+ from uuid import UUID, uuid4
5
+
6
+ from lamin_utils import logger
7
+ from supabase.client import Client # noqa
8
+
9
+
10
+ def select_instance_by_owner_name(
11
+ owner: str,
12
+ name: str,
13
+ client: Client,
14
+ ) -> dict | None:
15
+ # this won't find an instance without the default storage
16
+ data = (
17
+ client.table("instance")
18
+ .select(
19
+ "*, account!inner!instance_account_id_28936e8f_fk_account_id(*),"
20
+ " storage!inner!storage_instance_id_359fca71_fk_instance_id(*)"
21
+ )
22
+ .eq("name", name)
23
+ .eq("account.handle", owner)
24
+ .eq("storage.is_default", True)
25
+ .execute()
26
+ .data
27
+ )
28
+ if len(data) == 0:
29
+ return None
30
+ result = data[0]
31
+ # this is a list
32
+ # assume only one default storage
33
+ result["storage"] = result["storage"][0]
34
+ return result
35
+
36
+
37
+ # --------------- ACCOUNT ----------------------
38
+ def select_account_by_handle(
39
+ handle: str,
40
+ client: Client,
41
+ ):
42
+ data = client.table("account").select("*").eq("handle", handle).execute().data
43
+ if len(data) == 0:
44
+ return None
45
+ return data[0]
46
+
47
+
48
+ def select_account_handle_name_by_lnid(lnid: str, client: Client):
49
+ data = (
50
+ client.table("account").select("handle, name").eq("lnid", lnid).execute().data
51
+ )
52
+ if not data:
53
+ return None
54
+ return data[0]
55
+
56
+
57
+ # --------------- INSTANCE ----------------------
58
+ def select_instance_by_name(
59
+ account_id: str,
60
+ name: str,
61
+ client: Client,
62
+ ):
63
+ data = (
64
+ client.table("instance")
65
+ .select("*")
66
+ .eq("account_id", account_id)
67
+ .eq("name", name)
68
+ .execute()
69
+ .data
70
+ )
71
+ if len(data) != 0:
72
+ return data[0]
73
+
74
+ data = (
75
+ client.table("instance_previous_name")
76
+ .select(
77
+ "instance!instance_previous_name_instance_id_17ac5d61_fk_instance_id(*)"
78
+ )
79
+ .eq("instance.account_id", account_id)
80
+ .eq("previous_name", name)
81
+ .execute()
82
+ .data
83
+ )
84
+ if len(data) != 0:
85
+ return data[0]["instance"]
86
+
87
+ return None
88
+
89
+
90
+ def select_instance_by_id(
91
+ instance_id: str,
92
+ client: Client,
93
+ ):
94
+ response = client.table("instance").select("*").eq("id", instance_id).execute()
95
+ if len(response.data) == 0:
96
+ return None
97
+ return response.data[0]
98
+
99
+
100
+ def select_instance_by_id_with_storage(
101
+ instance_id: str,
102
+ client: Client,
103
+ ):
104
+ # this won't find an instance without the default storage
105
+ data = (
106
+ client.table("instance")
107
+ .select("*, storage!inner!storage_instance_id_359fca71_fk_instance_id(*)")
108
+ .eq("id", instance_id)
109
+ .eq("storage.is_default", True)
110
+ .execute()
111
+ .data
112
+ )
113
+ if len(data) == 0:
114
+ return None
115
+ result = data[0]
116
+ # this is a list
117
+ # assume only one default storage
118
+ result["storage"] = result["storage"][0]
119
+ return result
120
+
121
+
122
+ def update_instance(instance_id: str, instance_fields: dict, client: Client):
123
+ response = (
124
+ client.table("instance").update(instance_fields).eq("id", instance_id).execute()
125
+ )
126
+ if len(response.data) == 0:
127
+ raise PermissionError(
128
+ f"Update of instance with {instance_id} was not successful. Probably, you"
129
+ " don't have sufficient permissions."
130
+ )
131
+ return response.data[0]
132
+
133
+
134
+ # --------------- COLLABORATOR ----------------------
135
+
136
+
137
+ def select_collaborator(
138
+ instance_id: str,
139
+ account_id: str,
140
+ fine_grained_access: bool,
141
+ client: Client,
142
+ ):
143
+ table = "access_instance" if fine_grained_access else "account_instance"
144
+ data = (
145
+ client.table(table)
146
+ .select("*")
147
+ .eq("instance_id", instance_id)
148
+ .eq("account_id", account_id)
149
+ .execute()
150
+ .data
151
+ )
152
+ if len(data) == 0:
153
+ return None
154
+ return data[0]
155
+
156
+
157
+ # --------------- STORAGE ----------------------
158
+
159
+
160
+ def select_default_storage_by_instance_id(
161
+ instance_id: str, client: Client
162
+ ) -> dict | None:
163
+ data = (
164
+ client.table("storage")
165
+ .select("*")
166
+ .eq("instance_id", instance_id)
167
+ .eq("is_default", True)
168
+ .execute()
169
+ .data
170
+ )
171
+ if len(data) == 0:
172
+ return None
173
+ return data[0]
174
+
175
+
176
+ # --------------- DBUser ----------------------
177
+
178
+
179
+ def insert_db_user(
180
+ *,
181
+ name: str,
182
+ db_user_name: str,
183
+ db_user_password: str,
184
+ instance_id: UUID,
185
+ fine_grained_access: bool,
186
+ client: Client,
187
+ ) -> None:
188
+ fields = {"instance_id": instance_id.hex}
189
+ if fine_grained_access:
190
+ table = "access_db_user"
191
+ fields.update(
192
+ {
193
+ "name": db_user_name,
194
+ "password": db_user_password,
195
+ "type": name,
196
+ }
197
+ )
198
+ else:
199
+ table = "db_user"
200
+ fields.update(
201
+ {
202
+ "id": uuid4().hex,
203
+ "name": name,
204
+ "db_user_name": db_user_name,
205
+ "db_user_password": db_user_password,
206
+ }
207
+ )
208
+
209
+ data = client.table(table).insert(fields).execute().data
210
+ return data[0]
211
+
212
+
213
+ def select_db_user_by_instance(
214
+ instance_id: str, fine_grained_access: bool, client: Client
215
+ ):
216
+ """Get db_user for which client has permission."""
217
+ if fine_grained_access:
218
+ table = "access_db_user"
219
+ type_name = "type"
220
+ type_priority = "jwt"
221
+ else:
222
+ table = "db_user"
223
+ type_name = "name"
224
+ type_priority = "write"
225
+
226
+ data = client.table(table).select("*").eq("instance_id", instance_id).execute().data
227
+ if len(data) == 0:
228
+ return None
229
+ elif len(data) > 1:
230
+ for item in data:
231
+ if item[type_name] == type_priority:
232
+ return item
233
+ logger.warning("found multiple db credentials, using the first one")
234
+ return data[0]
235
+
236
+
237
+ def _delete_instance_record(instance_id: UUID, client: Client) -> None:
238
+ if not isinstance(instance_id, UUID):
239
+ instance_id = UUID(instance_id)
240
+ response = client.table("instance").delete().eq("id", instance_id.hex).execute()
241
+ if response.data:
242
+ logger.important(f"deleted instance record on hub {instance_id.hex}")
243
+ else:
244
+ raise PermissionError(
245
+ f"Deleting of instance with {instance_id.hex} was not successful. Probably, you"
246
+ " don't have sufficient permissions."
247
+ )