lamindb_setup 0.75.0__py2.py3-none-any.whl → 0.76.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/_init_instance.py +11 -4
- lamindb_setup/core/__init__.py +1 -0
- lamindb_setup/core/_hub_core.py +3 -1
- lamindb_setup/core/_settings_instance.py +11 -10
- lamindb_setup/core/_settings_storage.py +10 -5
- lamindb_setup/core/_setup_bionty_sources.py +17 -1
- lamindb_setup/core/hashing.py +6 -4
- lamindb_setup/core/upath.py +1 -1
- {lamindb_setup-0.75.0.dist-info → lamindb_setup-0.76.0.dist-info}/METADATA +1 -1
- {lamindb_setup-0.75.0.dist-info → lamindb_setup-0.76.0.dist-info}/RECORD +13 -13
- {lamindb_setup-0.75.0.dist-info → lamindb_setup-0.76.0.dist-info}/LICENSE +0 -0
- {lamindb_setup-0.75.0.dist-info → lamindb_setup-0.76.0.dist-info}/WHEEL +0 -0
lamindb_setup/__init__.py
CHANGED
lamindb_setup/_init_instance.py
CHANGED
|
@@ -15,6 +15,7 @@ from ._close import close as close_instance
|
|
|
15
15
|
from ._silence_loggers import silence_loggers
|
|
16
16
|
from .core import InstanceSettings
|
|
17
17
|
from .core._settings import settings
|
|
18
|
+
from .core._settings_instance import is_local_db_url
|
|
18
19
|
from .core._settings_storage import StorageSettings, init_storage
|
|
19
20
|
from .core.upath import UPath
|
|
20
21
|
|
|
@@ -245,10 +246,16 @@ def init(
|
|
|
245
246
|
if instance_state == "connected":
|
|
246
247
|
settings.auto_connect = True # we can also debate this switch here
|
|
247
248
|
return None
|
|
248
|
-
#
|
|
249
|
-
#
|
|
250
|
-
#
|
|
251
|
-
|
|
249
|
+
# the conditions here match `isettings.is_remote`, but I currently don't
|
|
250
|
+
# see a way of making this more elegant; should become possible if we
|
|
251
|
+
# remove the instance.storage_id FK on the hub
|
|
252
|
+
prevent_register_hub = is_local_db_url(db) if db is not None else False
|
|
253
|
+
ssettings = init_storage(
|
|
254
|
+
storage,
|
|
255
|
+
instance_id=instance_id,
|
|
256
|
+
init_instance=True,
|
|
257
|
+
prevent_register_hub=prevent_register_hub,
|
|
258
|
+
)
|
|
252
259
|
isettings = InstanceSettings(
|
|
253
260
|
id=instance_id, # type: ignore
|
|
254
261
|
owner=settings.user.handle,
|
lamindb_setup/core/__init__.py
CHANGED
lamindb_setup/core/_hub_core.py
CHANGED
|
@@ -160,7 +160,9 @@ def _init_storage(
|
|
|
160
160
|
)
|
|
161
161
|
ssettings._instance_id = settings.instance._id
|
|
162
162
|
instance_id_hex = (
|
|
163
|
-
|
|
163
|
+
ssettings._instance_id.hex
|
|
164
|
+
if (ssettings._instance_id is not None and auto_populate_instance)
|
|
165
|
+
else None
|
|
164
166
|
)
|
|
165
167
|
fields = {
|
|
166
168
|
"id": id.hex,
|
|
@@ -29,6 +29,16 @@ def sanitize_git_repo_url(repo_url: str) -> str:
|
|
|
29
29
|
return repo_url.replace(".git", "")
|
|
30
30
|
|
|
31
31
|
|
|
32
|
+
def is_local_db_url(db_url: str) -> bool:
|
|
33
|
+
if "@localhost:" in db_url:
|
|
34
|
+
return True
|
|
35
|
+
if "@0.0.0.0:" in db_url:
|
|
36
|
+
return True
|
|
37
|
+
if "@127.0.0.1" in db_url:
|
|
38
|
+
return True
|
|
39
|
+
return False
|
|
40
|
+
|
|
41
|
+
|
|
32
42
|
class InstanceSettings:
|
|
33
43
|
"""Instance settings."""
|
|
34
44
|
|
|
@@ -370,17 +380,8 @@ class InstanceSettings:
|
|
|
370
380
|
if not self.storage.type_is_cloud:
|
|
371
381
|
return False
|
|
372
382
|
|
|
373
|
-
def is_local_uri(uri: str):
|
|
374
|
-
if "@localhost:" in uri:
|
|
375
|
-
return True
|
|
376
|
-
if "@0.0.0.0:" in uri:
|
|
377
|
-
return True
|
|
378
|
-
if "@127.0.0.1" in uri:
|
|
379
|
-
return True
|
|
380
|
-
return False
|
|
381
|
-
|
|
382
383
|
if self.dialect == "postgresql":
|
|
383
|
-
if
|
|
384
|
+
if is_local_db_url(self.db):
|
|
384
385
|
return False
|
|
385
386
|
# returns True for cloud SQLite
|
|
386
387
|
# and remote postgres
|
|
@@ -78,7 +78,11 @@ def mark_storage_root(root: UPathStr, uid: str):
|
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
def init_storage(
|
|
81
|
-
root: UPathStr,
|
|
81
|
+
root: UPathStr,
|
|
82
|
+
instance_id: UUID | None = None,
|
|
83
|
+
register_hub: bool | None = None,
|
|
84
|
+
prevent_register_hub: bool = False,
|
|
85
|
+
init_instance: bool = False,
|
|
82
86
|
) -> StorageSettings:
|
|
83
87
|
if root is None:
|
|
84
88
|
raise ValueError("`storage` argument can't be `None`")
|
|
@@ -114,11 +118,12 @@ def init_storage(
|
|
|
114
118
|
instance_id=instance_id,
|
|
115
119
|
)
|
|
116
120
|
# the below might update the uid with one that's already taken on the hub
|
|
117
|
-
if
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
if not prevent_register_hub:
|
|
122
|
+
if ssettings.type_is_cloud or register_hub:
|
|
123
|
+
from ._hub_core import delete_storage_record
|
|
124
|
+
from ._hub_core import init_storage as init_storage_hub
|
|
120
125
|
|
|
121
|
-
|
|
126
|
+
init_storage_hub(ssettings, auto_populate_instance=not init_instance)
|
|
122
127
|
# below comes last only if everything else was successful
|
|
123
128
|
try:
|
|
124
129
|
# (federated) credentials for AWS access are provisioned under-the-hood
|
|
@@ -7,6 +7,9 @@ from django.db.utils import OperationalError, ProgrammingError
|
|
|
7
7
|
if TYPE_CHECKING:
|
|
8
8
|
from ._settings_instance import InstanceSettings
|
|
9
9
|
|
|
10
|
+
# bionty.Source -> bionty.base
|
|
11
|
+
RENAME = {"name": "source", "description": "source_name"}
|
|
12
|
+
|
|
10
13
|
|
|
11
14
|
def write_bionty_sources(isettings: InstanceSettings) -> None:
|
|
12
15
|
"""Write bionty sources to Source table."""
|
|
@@ -14,10 +17,14 @@ def write_bionty_sources(isettings: InstanceSettings) -> None:
|
|
|
14
17
|
return None
|
|
15
18
|
import shutil
|
|
16
19
|
|
|
20
|
+
import bionty
|
|
17
21
|
import bionty.base as bionty_base
|
|
22
|
+
from bionty._bionty import list_biorecord_models
|
|
18
23
|
from bionty.base.dev._handle_sources import parse_sources_yaml
|
|
19
24
|
from bionty.models import Source
|
|
20
25
|
|
|
26
|
+
bionty_models = list_biorecord_models(bionty)
|
|
27
|
+
|
|
21
28
|
shutil.copy(
|
|
22
29
|
bionty_base.settings.current_sources, bionty_base.settings.lamindb_sources
|
|
23
30
|
)
|
|
@@ -46,7 +53,10 @@ def write_bionty_sources(isettings: InstanceSettings) -> None:
|
|
|
46
53
|
# won't need this once lamindb is released with the new pin
|
|
47
54
|
kwargs["run"] = None # can't yet access tracking information
|
|
48
55
|
kwargs["in_db"] = False
|
|
49
|
-
|
|
56
|
+
for db_field, base_col in RENAME.items():
|
|
57
|
+
kwargs[db_field] = kwargs.pop(base_col)
|
|
58
|
+
if kwargs["entity"] in bionty_models:
|
|
59
|
+
kwargs["entity"] = f"bionty.{kwargs['entity']}"
|
|
50
60
|
record = Source(**kwargs)
|
|
51
61
|
all_records.append(record)
|
|
52
62
|
|
|
@@ -66,6 +76,12 @@ def load_bionty_sources(isettings: InstanceSettings):
|
|
|
66
76
|
try:
|
|
67
77
|
# need try except because of integer primary key migration
|
|
68
78
|
active_records = Source.objects.filter(currently_used=True).all().values()
|
|
79
|
+
for kwargs in active_records:
|
|
80
|
+
for db_field, base_col in RENAME.items():
|
|
81
|
+
kwargs[base_col] = kwargs.pop(db_field)
|
|
82
|
+
# TODO: non-bionty schema?
|
|
83
|
+
if db_field == "entity":
|
|
84
|
+
kwargs["entity"] = kwargs["entity"].split(".")[1]
|
|
69
85
|
write_yaml(
|
|
70
86
|
parse_currently_used_sources(active_records),
|
|
71
87
|
bionty_base.settings.lamindb_sources,
|
lamindb_setup/core/hashing.py
CHANGED
|
@@ -17,6 +17,8 @@ from typing import TYPE_CHECKING, Iterable
|
|
|
17
17
|
|
|
18
18
|
import psutil
|
|
19
19
|
|
|
20
|
+
HASH_LENGTH = 22
|
|
21
|
+
|
|
20
22
|
if TYPE_CHECKING:
|
|
21
23
|
from .types import Path, UPathStr
|
|
22
24
|
|
|
@@ -39,8 +41,8 @@ def b16_to_b64(s: str):
|
|
|
39
41
|
# a lot to read about this: lamin-notes/2022/hashing
|
|
40
42
|
def hash_set(s: set[str]) -> str:
|
|
41
43
|
bstr = ":".join(sorted(s)).encode("utf-8")
|
|
42
|
-
# as we're truncating at
|
|
43
|
-
return to_b64_str(hashlib.md5(bstr).digest())[:
|
|
44
|
+
# as we're truncating at 22 b64, we choose md5 over sha512
|
|
45
|
+
return to_b64_str(hashlib.md5(bstr).digest())[:HASH_LENGTH]
|
|
44
46
|
|
|
45
47
|
|
|
46
48
|
def hash_md5s_from_dir(hashes: Iterable[str]) -> tuple[str, str]:
|
|
@@ -50,7 +52,7 @@ def hash_md5s_from_dir(hashes: Iterable[str]) -> tuple[str, str]:
|
|
|
50
52
|
hashlib.md5(hash.encode("utf-8")).digest() for hash in sorted(hashes)
|
|
51
53
|
)
|
|
52
54
|
digest = hashlib.md5(digests).digest()
|
|
53
|
-
return to_b64_str(digest)[:
|
|
55
|
+
return to_b64_str(digest)[:HASH_LENGTH], "md5-d"
|
|
54
56
|
|
|
55
57
|
|
|
56
58
|
def hash_code(file_path: UPathStr):
|
|
@@ -85,7 +87,7 @@ def hash_file(
|
|
|
85
87
|
hashlib.sha1(first_chunk).digest() + hashlib.sha1(last_chunk).digest()
|
|
86
88
|
).digest()
|
|
87
89
|
hash_type = "sha1-fl"
|
|
88
|
-
return to_b64_str(digest)[:
|
|
90
|
+
return to_b64_str(digest)[:HASH_LENGTH], hash_type
|
|
89
91
|
|
|
90
92
|
|
|
91
93
|
def hash_dir(path: Path):
|
lamindb_setup/core/upath.py
CHANGED
|
@@ -772,7 +772,7 @@ def check_storage_is_empty(
|
|
|
772
772
|
hint += " ignored"
|
|
773
773
|
message = (
|
|
774
774
|
f"Storage {directory_string} contains {n_objects - n_offset_objects} objects "
|
|
775
|
-
f"({hint}) - {ask_for_deletion}
|
|
775
|
+
f"({hint}) - {ask_for_deletion}"
|
|
776
776
|
)
|
|
777
777
|
if n_diff > 0:
|
|
778
778
|
if raise_error:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
lamindb_setup/__init__.py,sha256=
|
|
1
|
+
lamindb_setup/__init__.py,sha256=mCahlCfmgFyDdpkDRVZFQnJDPKLOtPIcgiNfMAUqAkw,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
|
|
@@ -8,7 +8,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
|
-
lamindb_setup/_init_instance.py,sha256=
|
|
11
|
+
lamindb_setup/_init_instance.py,sha256=pR_pK38okij7CfnQDecJLKR5lhhTeE4oZ14Lb9bMMQg,12388
|
|
12
12
|
lamindb_setup/_migrate.py,sha256=P4n3x0SYzO9szjF2-JMa7z4mQadtWjHv5ow4HbCDZLI,8864
|
|
13
13
|
lamindb_setup/_register_instance.py,sha256=alQuYp2f8Ct8xvRC1gt8p_HZ0tqCd3gZD3kiPBLPpsI,1269
|
|
14
14
|
lamindb_setup/_schema.py,sha256=b3uzhhWpV5mQtDwhMINc2MabGCnGLESy51ito3yl6Wc,679
|
|
@@ -16,31 +16,31 @@ lamindb_setup/_schema_metadata.py,sha256=L0QjUsRmL63txvqptj4t_wh4ZamQ15mKSYsSMrH
|
|
|
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
|
|
19
|
-
lamindb_setup/core/__init__.py,sha256=
|
|
19
|
+
lamindb_setup/core/__init__.py,sha256=BxIVMX5HQq8oZ1OuY_saUEJz5Tdd7gaCPngxVu5iou4,417
|
|
20
20
|
lamindb_setup/core/_aws_credentials.py,sha256=uKMQO9q42Hnepz8aj3RxwLKDWUJx8pNOYrFnnNh5X40,5325
|
|
21
21
|
lamindb_setup/core/_aws_storage.py,sha256=nEjeUv4xUVpoV0Lx-zjjmyb9w804bDyaeiM-OqbfwM0,1799
|
|
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=XqXZatJOIDXukfdwL3Buq3WXZK-VVGg5OFRm2PrzO1o,16836
|
|
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
|
|
29
29
|
lamindb_setup/core/_settings.py,sha256=46axQ5HPvI0X9YuotgdpuSOfSo7qYU1DudIx3vxpFk0,4471
|
|
30
|
-
lamindb_setup/core/_settings_instance.py,sha256=
|
|
30
|
+
lamindb_setup/core/_settings_instance.py,sha256=rPTL_Iwv-ZVMRzu_EV_E7APFkEXLoD0TgUrz5293-vg,17586
|
|
31
31
|
lamindb_setup/core/_settings_load.py,sha256=63PTIVLk3oH1XUmznswygcOk_8VADrJLMB6O9AOppYg,3907
|
|
32
32
|
lamindb_setup/core/_settings_save.py,sha256=n_tYfb9EBSxwm4LHyPRHJptE5uB8lmHhcRkz1JkAmhg,2781
|
|
33
|
-
lamindb_setup/core/_settings_storage.py,sha256=
|
|
33
|
+
lamindb_setup/core/_settings_storage.py,sha256=bvEOm2aH4M6xBTfTARcWkx6b-jtKYl_AIUbH5yQC9GI,13435
|
|
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=o_MH8Ja_00nA9fQjZh7zlmLHvBeQlTrlNfO0GVivjew,3433
|
|
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
|
-
lamindb_setup/core/hashing.py,sha256=
|
|
40
|
+
lamindb_setup/core/hashing.py,sha256=Y2cvEaqtm3KwpHqj5ZG2f_sLaXhsQT4oDrmJdHbOQeo,3116
|
|
41
41
|
lamindb_setup/core/types.py,sha256=bcYnZ0uM_2NXKJCl94Mmc-uYrQlRUUVKG3sK2N-F-N4,532
|
|
42
|
-
lamindb_setup/core/upath.py,sha256=
|
|
43
|
-
lamindb_setup-0.
|
|
44
|
-
lamindb_setup-0.
|
|
45
|
-
lamindb_setup-0.
|
|
46
|
-
lamindb_setup-0.
|
|
42
|
+
lamindb_setup/core/upath.py,sha256=2N2IPRGwTBaamU9E_2CIEbKObwYRU_7yLfi0ATaBwWI,27146
|
|
43
|
+
lamindb_setup-0.76.0.dist-info/LICENSE,sha256=UOZ1F5fFDe3XXvG4oNnkL1-Ecun7zpHzRxjp-XsMeAo,11324
|
|
44
|
+
lamindb_setup-0.76.0.dist-info/WHEEL,sha256=Sgu64hAMa6g5FdzHxXv9Xdse9yxpGGMeagVtPMWpJQY,99
|
|
45
|
+
lamindb_setup-0.76.0.dist-info/METADATA,sha256=6muSAoC177Ogn0kEBEGO7W-kfZrBHLamrTVJW4BuGQE,1638
|
|
46
|
+
lamindb_setup-0.76.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|