lamindb_setup 0.74.3__py2.py3-none-any.whl → 0.75.0__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 +1 -1
- lamindb_setup/_close.py +2 -1
- lamindb_setup/_connect_instance.py +101 -2
- lamindb_setup/_register_instance.py +4 -1
- lamindb_setup/_schema_metadata.py +2 -0
- lamindb_setup/core/_hub_core.py +10 -2
- lamindb_setup/core/_setup_bionty_sources.py +8 -8
- {lamindb_setup-0.74.3.dist-info → lamindb_setup-0.75.0.dist-info}/METADATA +1 -1
- {lamindb_setup-0.74.3.dist-info → lamindb_setup-0.75.0.dist-info}/RECORD +11 -11
- {lamindb_setup-0.74.3.dist-info → lamindb_setup-0.75.0.dist-info}/LICENSE +0 -0
- {lamindb_setup-0.74.3.dist-info → lamindb_setup-0.75.0.dist-info}/WHEEL +0 -0
lamindb_setup/__init__.py
CHANGED
lamindb_setup/_close.py
CHANGED
|
@@ -24,8 +24,9 @@ def close(mute: bool = False) -> None:
|
|
|
24
24
|
logger.warning("did not upload cache file - not enough permissions")
|
|
25
25
|
else:
|
|
26
26
|
raise e
|
|
27
|
+
if "bionty" in settings.instance.schema:
|
|
28
|
+
delete_bionty_sources_yaml()
|
|
27
29
|
current_instance_settings_file().unlink()
|
|
28
|
-
delete_bionty_sources_yaml()
|
|
29
30
|
clear_locker()
|
|
30
31
|
if not mute:
|
|
31
32
|
logger.success(f"closed instance: {instance}")
|
|
@@ -4,7 +4,6 @@ import os
|
|
|
4
4
|
from typing import TYPE_CHECKING
|
|
5
5
|
from uuid import UUID
|
|
6
6
|
|
|
7
|
-
from django.db import ProgrammingError
|
|
8
7
|
from lamin_utils import logger
|
|
9
8
|
|
|
10
9
|
from ._check_setup import _check_instance_setup
|
|
@@ -21,7 +20,7 @@ from .core._settings import settings
|
|
|
21
20
|
from .core._settings_instance import InstanceSettings
|
|
22
21
|
from .core._settings_load import load_instance_settings
|
|
23
22
|
from .core._settings_storage import StorageSettings
|
|
24
|
-
from .core._settings_store import instance_settings_file
|
|
23
|
+
from .core._settings_store import instance_settings_file, settings_dir
|
|
25
24
|
from .core.cloud_sqlite_locker import unlock_cloud_sqlite_upon_exception
|
|
26
25
|
|
|
27
26
|
if TYPE_CHECKING:
|
|
@@ -257,9 +256,109 @@ def connect(
|
|
|
257
256
|
if isettings is not None:
|
|
258
257
|
isettings._get_settings_file().unlink(missing_ok=True) # type: ignore
|
|
259
258
|
raise e
|
|
259
|
+
# rename lnschema_bionty to bionty for sql tables
|
|
260
|
+
if "bionty" in isettings.schema:
|
|
261
|
+
no_lnschema_bionty_file = (
|
|
262
|
+
settings_dir / f"no_lnschema_bionty-{isettings.slug.replace('/', '')}"
|
|
263
|
+
)
|
|
264
|
+
if not no_lnschema_bionty_file.exists():
|
|
265
|
+
migrate_lnschema_bionty(isettings, no_lnschema_bionty_file)
|
|
260
266
|
return None
|
|
261
267
|
|
|
262
268
|
|
|
269
|
+
def migrate_lnschema_bionty(isettings: InstanceSettings, no_lnschema_bionty_file: Path):
|
|
270
|
+
"""Migrate lnschema_bionty tables to bionty tables if bionty_source doesn't exist.
|
|
271
|
+
|
|
272
|
+
:param db_uri: str, database URI (e.g., 'sqlite:///path/to/db.sqlite' or 'postgresql://user:password@host:port/dbname')
|
|
273
|
+
"""
|
|
274
|
+
from urllib.parse import urlparse
|
|
275
|
+
|
|
276
|
+
parsed_uri = urlparse(isettings.db)
|
|
277
|
+
db_type = parsed_uri.scheme
|
|
278
|
+
|
|
279
|
+
if db_type == "sqlite":
|
|
280
|
+
import sqlite3
|
|
281
|
+
|
|
282
|
+
conn = sqlite3.connect(parsed_uri.path)
|
|
283
|
+
elif db_type in ["postgresql", "postgres"]:
|
|
284
|
+
import psycopg2
|
|
285
|
+
|
|
286
|
+
conn = psycopg2.connect(isettings.db)
|
|
287
|
+
else:
|
|
288
|
+
raise ValueError("Unsupported database type. Use 'sqlite' or 'postgresql' URI.")
|
|
289
|
+
|
|
290
|
+
cur = conn.cursor()
|
|
291
|
+
|
|
292
|
+
try:
|
|
293
|
+
# check if bionty_source table exists
|
|
294
|
+
if db_type == "sqlite":
|
|
295
|
+
cur.execute(
|
|
296
|
+
"SELECT name FROM sqlite_master WHERE type='table' AND name='bionty_source'"
|
|
297
|
+
)
|
|
298
|
+
migrated = cur.fetchone() is not None
|
|
299
|
+
|
|
300
|
+
# tables that need to be renamed
|
|
301
|
+
cur.execute(
|
|
302
|
+
"SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'lnschema_bionty_%'"
|
|
303
|
+
)
|
|
304
|
+
tables_to_rename = [
|
|
305
|
+
row[0][len("lnschema_bionty_") :] for row in cur.fetchall()
|
|
306
|
+
]
|
|
307
|
+
else: # postgres
|
|
308
|
+
cur.execute(
|
|
309
|
+
"SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'bionty_source')"
|
|
310
|
+
)
|
|
311
|
+
migrated = cur.fetchone()[0]
|
|
312
|
+
|
|
313
|
+
# tables that need to be renamed
|
|
314
|
+
cur.execute(
|
|
315
|
+
"SELECT table_name FROM information_schema.tables WHERE table_name LIKE 'lnschema_bionty_%'"
|
|
316
|
+
)
|
|
317
|
+
tables_to_rename = [
|
|
318
|
+
row[0][len("lnschema_bionty_") :] for row in cur.fetchall()
|
|
319
|
+
]
|
|
320
|
+
|
|
321
|
+
if migrated:
|
|
322
|
+
no_lnschema_bionty_file.touch(exist_ok=True)
|
|
323
|
+
else:
|
|
324
|
+
try:
|
|
325
|
+
# rename tables only if bionty_source doesn't exist and there are tables to rename
|
|
326
|
+
for table in tables_to_rename:
|
|
327
|
+
if db_type == "sqlite":
|
|
328
|
+
cur.execute(
|
|
329
|
+
f"ALTER TABLE lnschema_bionty_{table} RENAME TO bionty_{table}"
|
|
330
|
+
)
|
|
331
|
+
else: # postgres
|
|
332
|
+
cur.execute(
|
|
333
|
+
f"ALTER TABLE lnschema_bionty_{table} RENAME TO bionty_{table};"
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
# update django_migrations table
|
|
337
|
+
cur.execute(
|
|
338
|
+
"UPDATE django_migrations SET app = 'bionty' WHERE app = 'lnschema_bionty'"
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
logger.warning(
|
|
342
|
+
"Please uninstall lnschema-bionty via `pip uninstall lnschema-bionty`!"
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
no_lnschema_bionty_file.touch(exist_ok=True)
|
|
346
|
+
except Exception:
|
|
347
|
+
# read-only users can't rename tables
|
|
348
|
+
pass
|
|
349
|
+
|
|
350
|
+
conn.commit()
|
|
351
|
+
|
|
352
|
+
except Exception as e:
|
|
353
|
+
print(f"An error occurred: {e}")
|
|
354
|
+
conn.rollback()
|
|
355
|
+
|
|
356
|
+
finally:
|
|
357
|
+
# close the cursor and connection
|
|
358
|
+
cur.close()
|
|
359
|
+
conn.close()
|
|
360
|
+
|
|
361
|
+
|
|
263
362
|
def load(
|
|
264
363
|
slug: str,
|
|
265
364
|
*,
|
|
@@ -23,7 +23,10 @@ def register(_test: bool = False):
|
|
|
23
23
|
if ssettings._uid is None and _test:
|
|
24
24
|
# because django isn't up, we can't get it from the database
|
|
25
25
|
ssettings._uid = base62(8)
|
|
26
|
-
|
|
26
|
+
# cannot yet populate the instance id here
|
|
27
|
+
ssettings._instance_id = None
|
|
28
|
+
# flag auto_populate_instance can be removed once FK migration is over
|
|
29
|
+
init_storage_hub(ssettings, auto_populate_instance=False)
|
|
27
30
|
init_instance_hub(isettings)
|
|
28
31
|
isettings._is_on_hub = True
|
|
29
32
|
isettings._persist()
|
lamindb_setup/core/_hub_core.py
CHANGED
|
@@ -118,11 +118,13 @@ def _select_storage(
|
|
|
118
118
|
|
|
119
119
|
def init_storage(
|
|
120
120
|
ssettings: StorageSettings,
|
|
121
|
+
auto_populate_instance: bool = True,
|
|
121
122
|
) -> None:
|
|
122
123
|
if settings.user.handle != "anonymous":
|
|
123
124
|
return call_with_fallback_auth(
|
|
124
125
|
_init_storage,
|
|
125
126
|
ssettings=ssettings,
|
|
127
|
+
auto_populate_instance=auto_populate_instance,
|
|
126
128
|
)
|
|
127
129
|
else:
|
|
128
130
|
storage_exists = call_with_fallback(
|
|
@@ -134,7 +136,9 @@ def init_storage(
|
|
|
134
136
|
raise ValueError("Log in to create a storage location on the hub.")
|
|
135
137
|
|
|
136
138
|
|
|
137
|
-
def _init_storage(
|
|
139
|
+
def _init_storage(
|
|
140
|
+
ssettings: StorageSettings, auto_populate_instance: bool, client: Client
|
|
141
|
+
) -> None:
|
|
138
142
|
from lamindb_setup import settings
|
|
139
143
|
|
|
140
144
|
# storage roots are always stored without the trailing slash in the SQL
|
|
@@ -146,7 +150,11 @@ def _init_storage(ssettings: StorageSettings, client: Client) -> None:
|
|
|
146
150
|
id = uuid.uuid5(uuid.NAMESPACE_URL, root)
|
|
147
151
|
else:
|
|
148
152
|
id = uuid.uuid4()
|
|
149
|
-
if
|
|
153
|
+
if (
|
|
154
|
+
ssettings._instance_id is None
|
|
155
|
+
and settings._instance_exists
|
|
156
|
+
and auto_populate_instance
|
|
157
|
+
):
|
|
150
158
|
logger.warning(
|
|
151
159
|
f"will manage storage location {ssettings.root_as_str} with instance {settings.instance.slug}"
|
|
152
160
|
)
|
|
@@ -14,9 +14,9 @@ def write_bionty_sources(isettings: InstanceSettings) -> None:
|
|
|
14
14
|
return None
|
|
15
15
|
import shutil
|
|
16
16
|
|
|
17
|
-
import bionty_base
|
|
18
|
-
from
|
|
19
|
-
from
|
|
17
|
+
import bionty.base as bionty_base
|
|
18
|
+
from bionty.base.dev._handle_sources import parse_sources_yaml
|
|
19
|
+
from bionty.models import Source
|
|
20
20
|
|
|
21
21
|
shutil.copy(
|
|
22
22
|
bionty_base.settings.current_sources, bionty_base.settings.lamindb_sources
|
|
@@ -58,10 +58,10 @@ def load_bionty_sources(isettings: InstanceSettings):
|
|
|
58
58
|
if "bionty" not in isettings.schema:
|
|
59
59
|
return None
|
|
60
60
|
|
|
61
|
-
import bionty_base
|
|
62
|
-
from
|
|
63
|
-
from
|
|
64
|
-
from
|
|
61
|
+
import bionty.base as bionty_base
|
|
62
|
+
from bionty.base.dev._handle_sources import parse_currently_used_sources
|
|
63
|
+
from bionty.base.dev._io import write_yaml
|
|
64
|
+
from bionty.models import Source
|
|
65
65
|
|
|
66
66
|
try:
|
|
67
67
|
# need try except because of integer primary key migration
|
|
@@ -77,7 +77,7 @@ def load_bionty_sources(isettings: InstanceSettings):
|
|
|
77
77
|
def delete_bionty_sources_yaml():
|
|
78
78
|
"""Delete LAMINDB_SOURCES_PATH in bionty."""
|
|
79
79
|
try:
|
|
80
|
-
import bionty_base
|
|
80
|
+
import bionty.base as bionty_base
|
|
81
81
|
|
|
82
82
|
bionty_base.settings.lamindb_sources.unlink(missing_ok=True)
|
|
83
83
|
except ModuleNotFoundError:
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
lamindb_setup/__init__.py,sha256=
|
|
1
|
+
lamindb_setup/__init__.py,sha256=h484xhWUuDVBkjDLj8nu5IKkNELvscWtoABYLZIU7dU,1542
|
|
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
|
-
lamindb_setup/_close.py,sha256=
|
|
6
|
-
lamindb_setup/_connect_instance.py,sha256=
|
|
5
|
+
lamindb_setup/_close.py,sha256=cXNwK7QTTyNFt2XTpLnO3KHljJ7ShOcISk95np_dltE,1239
|
|
6
|
+
lamindb_setup/_connect_instance.py,sha256=kAZMTP3w5Vgw-pgZDX9RhYl3TKHaxBuTczTVIsy8Xms,16069
|
|
7
7
|
lamindb_setup/_delete.py,sha256=Y8KSFYgY0UHAvjd7cCL6hZ_XiLeJwx50BguVATcj_Xo,5524
|
|
8
8
|
lamindb_setup/_django.py,sha256=EoyWvFzH0i9wxjy4JZhcoXCTckztP_Mrl6FbYQnMmLE,1534
|
|
9
9
|
lamindb_setup/_exportdb.py,sha256=43g77-tH-vAlTn8ig1mMD9-KXLKvxUeDLaq0gVu3l-c,2114
|
|
10
10
|
lamindb_setup/_importdb.py,sha256=yYYShzUajTsR-cTW4CZ-UNDWZY2uE5PAgNbp-wn8Ogc,1874
|
|
11
11
|
lamindb_setup/_init_instance.py,sha256=jcKtXLOwkoq7bC-0j0xnNU4_up9nPl0iKQPNoJbBts8,12078
|
|
12
12
|
lamindb_setup/_migrate.py,sha256=P4n3x0SYzO9szjF2-JMa7z4mQadtWjHv5ow4HbCDZLI,8864
|
|
13
|
-
lamindb_setup/_register_instance.py,sha256=
|
|
13
|
+
lamindb_setup/_register_instance.py,sha256=alQuYp2f8Ct8xvRC1gt8p_HZ0tqCd3gZD3kiPBLPpsI,1269
|
|
14
14
|
lamindb_setup/_schema.py,sha256=b3uzhhWpV5mQtDwhMINc2MabGCnGLESy51ito3yl6Wc,679
|
|
15
|
-
lamindb_setup/_schema_metadata.py,sha256=
|
|
15
|
+
lamindb_setup/_schema_metadata.py,sha256=L0QjUsRmL63txvqptj4t_wh4ZamQ15mKSYsSMrHB1ME,12960
|
|
16
16
|
lamindb_setup/_set_managed_storage.py,sha256=mNZrANn-9rwZ0oGWxxg0wS0T0VOQCWyo4nSSyNAE15Q,1419
|
|
17
17
|
lamindb_setup/_setup_user.py,sha256=6Oc7Rke-yRQSZbuntdUAz8QbJ6UuPzYHI9FnYlf_q-A,3670
|
|
18
18
|
lamindb_setup/_silence_loggers.py,sha256=AKF_YcHvX32eGXdsYK8MJlxEaZ-Uo2f6QDRzjKFCtws,1568
|
|
@@ -22,7 +22,7 @@ lamindb_setup/core/_aws_storage.py,sha256=nEjeUv4xUVpoV0Lx-zjjmyb9w804bDyaeiM-Oq
|
|
|
22
22
|
lamindb_setup/core/_deprecated.py,sha256=3qxUI1dnDlSeR0BYrv7ucjqRBEojbqotPgpShXs4KF8,2520
|
|
23
23
|
lamindb_setup/core/_docs.py,sha256=3k-YY-oVaJd_9UIY-LfBg_u8raKOCNfkZQPA73KsUhs,276
|
|
24
24
|
lamindb_setup/core/_hub_client.py,sha256=Gpt3TmxWQMVenKugCu1agUb-xGN9YFsQOKmrHuFiiDs,5605
|
|
25
|
-
lamindb_setup/core/_hub_core.py,sha256=
|
|
25
|
+
lamindb_setup/core/_hub_core.py,sha256=L9rQXM5eVIFOR6oP5uSqHpkYy4y3Bx0w_6acy-_hEVk,16787
|
|
26
26
|
lamindb_setup/core/_hub_crud.py,sha256=b1XF7AJpM9Q-ttm9nPG-r3OTRWHQaGzAGIyvmb83NTo,4859
|
|
27
27
|
lamindb_setup/core/_hub_utils.py,sha256=w5IRtrxZcvxmGSJslzuZF89ewkzXV4cCUmZUVrqmAfo,3026
|
|
28
28
|
lamindb_setup/core/_private_django_api.py,sha256=KIn43HOhiRjkbTbddyJqv-WNTTa1bAizbM1tWXoXPBg,2869
|
|
@@ -33,14 +33,14 @@ lamindb_setup/core/_settings_save.py,sha256=n_tYfb9EBSxwm4LHyPRHJptE5uB8lmHhcRkz
|
|
|
33
33
|
lamindb_setup/core/_settings_storage.py,sha256=65aobewYX6VfOeYZjZQOOI7ZD_3b4QA9TDmrduU0m4c,13262
|
|
34
34
|
lamindb_setup/core/_settings_store.py,sha256=VEE8Ff2A7y4j8ksOaa7g48jNaOqe1PBnBjb1PKKGUKU,2115
|
|
35
35
|
lamindb_setup/core/_settings_user.py,sha256=P2lC4WDRAFfT-Xq3MlXJ-wMKIHCoGNhMTQfRGIAyUNQ,1344
|
|
36
|
-
lamindb_setup/core/_setup_bionty_sources.py,sha256=
|
|
36
|
+
lamindb_setup/core/_setup_bionty_sources.py,sha256=Y6_DiIj1RS8HsUewWtfjIDchYkL1GE98bf75hHN-j5A,2759
|
|
37
37
|
lamindb_setup/core/cloud_sqlite_locker.py,sha256=reu02M4aE2BT_A5AFqwhv48l91mOMyQ4zTd-hh-wtuU,6922
|
|
38
38
|
lamindb_setup/core/django.py,sha256=QUQm3zt5QIiD8uv6o9vbSm_bshqiSWzKSkgD3z2eJCg,3542
|
|
39
39
|
lamindb_setup/core/exceptions.py,sha256=eoI7AXgATgDVzgArtN7CUvpaMUC067vsBg5LHCsWzDM,305
|
|
40
40
|
lamindb_setup/core/hashing.py,sha256=_JliYeCcjT_foOUJ5ck1rvcCo9q7r4b4SaSclQ_w4Qo,3071
|
|
41
41
|
lamindb_setup/core/types.py,sha256=bcYnZ0uM_2NXKJCl94Mmc-uYrQlRUUVKG3sK2N-F-N4,532
|
|
42
42
|
lamindb_setup/core/upath.py,sha256=dwudkTVsXuyjS-2xR16WomcWtXJAEfRZ0ZzFq8_EDhE,27157
|
|
43
|
-
lamindb_setup-0.
|
|
44
|
-
lamindb_setup-0.
|
|
45
|
-
lamindb_setup-0.
|
|
46
|
-
lamindb_setup-0.
|
|
43
|
+
lamindb_setup-0.75.0.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
|
|
44
|
+
lamindb_setup-0.75.0.dist-info/WHEEL,sha256=Sgu64hAMa6g5FdzHxXv9Xdse9yxpGGMeagVtPMWpJQY,99
|
|
45
|
+
lamindb_setup-0.75.0.dist-info/METADATA,sha256=tpmMZNwLSmNudPk6PE-n6mRXDk7DSjAvfEMbtGeU9uA,1638
|
|
46
|
+
lamindb_setup-0.75.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|