lamindb_setup 0.76.5__py2.py3-none-any.whl → 0.76.7__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.
Files changed (47) hide show
  1. lamindb_setup/__init__.py +1 -1
  2. lamindb_setup/_cache.py +34 -34
  3. lamindb_setup/_check.py +7 -7
  4. lamindb_setup/_check_setup.py +79 -79
  5. lamindb_setup/_close.py +35 -35
  6. lamindb_setup/_connect_instance.py +433 -433
  7. lamindb_setup/_delete.py +137 -137
  8. lamindb_setup/_django.py +41 -41
  9. lamindb_setup/_exportdb.py +68 -68
  10. lamindb_setup/_importdb.py +50 -50
  11. lamindb_setup/_init_instance.py +374 -374
  12. lamindb_setup/_migrate.py +239 -236
  13. lamindb_setup/_register_instance.py +36 -36
  14. lamindb_setup/_schema.py +27 -27
  15. lamindb_setup/_schema_metadata.py +391 -391
  16. lamindb_setup/_set_managed_storage.py +55 -55
  17. lamindb_setup/_setup_user.py +118 -118
  18. lamindb_setup/_silence_loggers.py +44 -44
  19. lamindb_setup/core/__init__.py +21 -21
  20. lamindb_setup/core/_aws_credentials.py +151 -151
  21. lamindb_setup/core/_aws_storage.py +48 -48
  22. lamindb_setup/core/_deprecated.py +55 -55
  23. lamindb_setup/core/_docs.py +14 -14
  24. lamindb_setup/core/_hub_client.py +164 -161
  25. lamindb_setup/core/_hub_core.py +473 -473
  26. lamindb_setup/core/_hub_crud.py +211 -211
  27. lamindb_setup/core/_hub_utils.py +109 -109
  28. lamindb_setup/core/_private_django_api.py +88 -88
  29. lamindb_setup/core/_settings.py +138 -138
  30. lamindb_setup/core/_settings_instance.py +461 -460
  31. lamindb_setup/core/_settings_load.py +100 -100
  32. lamindb_setup/core/_settings_save.py +81 -81
  33. lamindb_setup/core/_settings_storage.py +393 -389
  34. lamindb_setup/core/_settings_store.py +72 -72
  35. lamindb_setup/core/_settings_user.py +51 -51
  36. lamindb_setup/core/_setup_bionty_sources.py +99 -99
  37. lamindb_setup/core/cloud_sqlite_locker.py +232 -232
  38. lamindb_setup/core/django.py +113 -113
  39. lamindb_setup/core/exceptions.py +12 -12
  40. lamindb_setup/core/hashing.py +114 -114
  41. lamindb_setup/core/types.py +19 -19
  42. lamindb_setup/core/upath.py +779 -779
  43. {lamindb_setup-0.76.5.dist-info → lamindb_setup-0.76.7.dist-info}/METADATA +4 -3
  44. lamindb_setup-0.76.7.dist-info/RECORD +46 -0
  45. {lamindb_setup-0.76.5.dist-info → lamindb_setup-0.76.7.dist-info}/WHEEL +1 -1
  46. lamindb_setup-0.76.5.dist-info/RECORD +0 -46
  47. {lamindb_setup-0.76.5.dist-info → lamindb_setup-0.76.7.dist-info}/LICENSE +0 -0
@@ -1,72 +1,72 @@
1
- import os
2
- from pathlib import Path
3
- from typing import Optional
4
-
5
- from pydantic_settings import BaseSettings, SettingsConfigDict
6
-
7
- if "LAMIN_SETTINGS_DIR" in os.environ:
8
- # Needed when running with AWS Lambda, as only tmp/ directory has a write access
9
- settings_dir = Path(f"{os.environ['LAMIN_SETTINGS_DIR']}/.lamin")
10
- else:
11
- # user_config_dir in appdirs is weird on MacOS!
12
- # hence, let's take home/.lamin
13
- settings_dir = Path.home() / ".lamin"
14
-
15
- settings_dir.mkdir(parents=True, exist_ok=True)
16
-
17
-
18
- def get_settings_file_name_prefix():
19
- if "LAMIN_ENV" in os.environ:
20
- if os.environ["LAMIN_ENV"] != "prod":
21
- return f"{os.environ['LAMIN_ENV']}--"
22
- return ""
23
-
24
-
25
- def current_instance_settings_file():
26
- return settings_dir / f"{get_settings_file_name_prefix()}current_instance.env"
27
-
28
-
29
- def current_user_settings_file():
30
- return settings_dir / f"{get_settings_file_name_prefix()}current_user.env"
31
-
32
-
33
- def instance_settings_file(name: str, owner: str):
34
- return (
35
- settings_dir / f"{get_settings_file_name_prefix()}instance--{owner}--{name}.env"
36
- )
37
-
38
-
39
- def user_settings_file_email(email: str):
40
- return settings_dir / f"{get_settings_file_name_prefix()}user--{email}.env"
41
-
42
-
43
- def user_settings_file_handle(handle: str):
44
- return settings_dir / f"{get_settings_file_name_prefix()}user--{handle}.env"
45
-
46
-
47
- def system_storage_settings_file():
48
- return settings_dir / "storage.env"
49
-
50
-
51
- class InstanceSettingsStore(BaseSettings):
52
- owner: str
53
- name: str
54
- storage_root: str
55
- storage_region: Optional[str] # take old type annotations here because pydantic
56
- db: Optional[str] # doesn't like new types on 3.9 even with future annotations
57
- schema_str: Optional[str]
58
- id: str
59
- git_repo: Optional[str]
60
- keep_artifacts_local: Optional[bool]
61
- model_config = SettingsConfigDict(env_prefix="lamindb_instance_", env_file=".env")
62
-
63
-
64
- class UserSettingsStore(BaseSettings):
65
- email: str
66
- password: str
67
- access_token: str
68
- uid: str
69
- uuid: str
70
- handle: str
71
- name: str
72
- model_config = SettingsConfigDict(env_prefix="lamin_user_", env_file=".env")
1
+ import os
2
+ from pathlib import Path
3
+ from typing import Optional
4
+
5
+ from pydantic_settings import BaseSettings, SettingsConfigDict
6
+
7
+ if "LAMIN_SETTINGS_DIR" in os.environ:
8
+ # Needed when running with AWS Lambda, as only tmp/ directory has a write access
9
+ settings_dir = Path(f"{os.environ['LAMIN_SETTINGS_DIR']}/.lamin")
10
+ else:
11
+ # user_config_dir in appdirs is weird on MacOS!
12
+ # hence, let's take home/.lamin
13
+ settings_dir = Path.home() / ".lamin"
14
+
15
+ settings_dir.mkdir(parents=True, exist_ok=True)
16
+
17
+
18
+ def get_settings_file_name_prefix():
19
+ if "LAMIN_ENV" in os.environ:
20
+ if os.environ["LAMIN_ENV"] != "prod":
21
+ return f"{os.environ['LAMIN_ENV']}--"
22
+ return ""
23
+
24
+
25
+ def current_instance_settings_file():
26
+ return settings_dir / f"{get_settings_file_name_prefix()}current_instance.env"
27
+
28
+
29
+ def current_user_settings_file():
30
+ return settings_dir / f"{get_settings_file_name_prefix()}current_user.env"
31
+
32
+
33
+ def instance_settings_file(name: str, owner: str):
34
+ return (
35
+ settings_dir / f"{get_settings_file_name_prefix()}instance--{owner}--{name}.env"
36
+ )
37
+
38
+
39
+ def user_settings_file_email(email: str):
40
+ return settings_dir / f"{get_settings_file_name_prefix()}user--{email}.env"
41
+
42
+
43
+ def user_settings_file_handle(handle: str):
44
+ return settings_dir / f"{get_settings_file_name_prefix()}user--{handle}.env"
45
+
46
+
47
+ def system_storage_settings_file():
48
+ return settings_dir / "storage.env"
49
+
50
+
51
+ class InstanceSettingsStore(BaseSettings):
52
+ owner: str
53
+ name: str
54
+ storage_root: str
55
+ storage_region: Optional[str] # take old type annotations here because pydantic
56
+ db: Optional[str] # doesn't like new types on 3.9 even with future annotations
57
+ schema_str: Optional[str]
58
+ id: str
59
+ git_repo: Optional[str]
60
+ keep_artifacts_local: Optional[bool]
61
+ model_config = SettingsConfigDict(env_prefix="lamindb_instance_", env_file=".env")
62
+
63
+
64
+ class UserSettingsStore(BaseSettings):
65
+ email: str
66
+ password: str
67
+ access_token: str
68
+ uid: str
69
+ uuid: str
70
+ handle: str
71
+ name: str
72
+ model_config = SettingsConfigDict(env_prefix="lamin_user_", env_file=".env")
@@ -1,51 +1,51 @@
1
- from __future__ import annotations
2
-
3
- from dataclasses import dataclass
4
- from typing import TYPE_CHECKING, Optional
5
-
6
- if TYPE_CHECKING:
7
- from uuid import UUID
8
-
9
-
10
- class user_description:
11
- email = """User email."""
12
- password = """API key or legacy password."""
13
- uid = """Universal user ID."""
14
- handle = "Unique handle."
15
- name = "Full name."
16
-
17
-
18
- @dataclass
19
- class UserSettings:
20
- """User data. All synched from cloud."""
21
-
22
- handle: str = "anonymous"
23
- """Unique handle."""
24
- email: str = None # type: ignore
25
- """User email."""
26
- password: str | None = None
27
- """API key or legacy password."""
28
- access_token: str | None = None
29
- """User access token."""
30
- uid: str = "null"
31
- """Universal user ID."""
32
- _uuid: UUID | None = None
33
- """Lamin's internal user ID."""
34
- name: str | None = None
35
- """Full name."""
36
-
37
- def __repr__(self) -> str:
38
- """Rich string representation."""
39
- representation = f"Current user: {self.handle}"
40
- attrs = ["handle", "email", "uid"]
41
- for attr in attrs:
42
- value = getattr(self, attr)
43
- representation += f"\n- {attr}: {value}"
44
- return representation
45
-
46
- @property
47
- def id(self):
48
- """Integer id valid in current intance."""
49
- from lnschema_core.users import current_user_id
50
-
51
- return current_user_id()
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import TYPE_CHECKING, Optional
5
+
6
+ if TYPE_CHECKING:
7
+ from uuid import UUID
8
+
9
+
10
+ class user_description:
11
+ email = """User email."""
12
+ password = """API key or legacy password."""
13
+ uid = """Universal user ID."""
14
+ handle = "Unique handle."
15
+ name = "Full name."
16
+
17
+
18
+ @dataclass
19
+ class UserSettings:
20
+ """User data. All synched from cloud."""
21
+
22
+ handle: str = "anonymous"
23
+ """Unique handle."""
24
+ email: str = None # type: ignore
25
+ """User email."""
26
+ password: str | None = None
27
+ """API key or legacy password."""
28
+ access_token: str | None = None
29
+ """User access token."""
30
+ uid: str = "null"
31
+ """Universal user ID."""
32
+ _uuid: UUID | None = None
33
+ """Lamin's internal user ID."""
34
+ name: str | None = None
35
+ """Full name."""
36
+
37
+ def __repr__(self) -> str:
38
+ """Rich string representation."""
39
+ representation = f"Current user: {self.handle}"
40
+ attrs = ["handle", "email", "uid"]
41
+ for attr in attrs:
42
+ value = getattr(self, attr)
43
+ representation += f"\n- {attr}: {value}"
44
+ return representation
45
+
46
+ @property
47
+ def id(self):
48
+ """Integer id valid in current intance."""
49
+ from lnschema_core.users import current_user_id
50
+
51
+ return current_user_id()
@@ -1,99 +1,99 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
-
5
- from django.db.utils import OperationalError, ProgrammingError
6
-
7
- if TYPE_CHECKING:
8
- from ._settings_instance import InstanceSettings
9
-
10
- # bionty.Source -> bionty.base
11
- RENAME = {"name": "source", "description": "source_name"}
12
-
13
-
14
- def write_bionty_sources(isettings: InstanceSettings) -> None:
15
- """Write bionty sources to Source table."""
16
- if "bionty" not in isettings.schema:
17
- return None
18
- import shutil
19
-
20
- import bionty
21
- import bionty.base as bionty_base
22
- from bionty._bionty import list_biorecord_models
23
- from bionty.base.dev._handle_sources import parse_sources_yaml
24
- from bionty.models import Source
25
-
26
- bionty_models = list_biorecord_models(bionty)
27
-
28
- shutil.copy(
29
- bionty_base.settings.current_sources, bionty_base.settings.lamindb_sources
30
- )
31
-
32
- all_sources = parse_sources_yaml(bionty_base.settings.local_sources)
33
- all_sources_dict = all_sources.to_dict(orient="records")
34
-
35
- def _get_currently_used(key: str):
36
- return (
37
- bionty_base.display_currently_used_sources()
38
- .reset_index()
39
- .set_index(["entity", key])
40
- )
41
-
42
- currently_used = _get_currently_used("organism")
43
-
44
- all_records = []
45
- for kwargs in all_sources_dict:
46
- act = currently_used.loc[(kwargs["entity"], kwargs["organism"])].to_dict()
47
- if (act["source"] == kwargs["source"]) and (
48
- act["version"] == kwargs["version"]
49
- ):
50
- kwargs["currently_used"] = True
51
-
52
- # when the database is not yet migrated but setup is updated
53
- # won't need this once lamindb is released with the new pin
54
- kwargs["run"] = None # can't yet access tracking information
55
- kwargs["in_db"] = False
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']}"
60
- record = Source(**kwargs)
61
- all_records.append(record)
62
-
63
- Source.objects.bulk_create(all_records, ignore_conflicts=True)
64
-
65
-
66
- def load_bionty_sources(isettings: InstanceSettings):
67
- """Write currently_used bionty sources to LAMINDB_VERSIONS_PATH in bionty."""
68
- if "bionty" not in isettings.schema:
69
- return None
70
-
71
- import bionty.base as bionty_base
72
- from bionty.base.dev._handle_sources import parse_currently_used_sources
73
- from bionty.base.dev._io import write_yaml
74
- from bionty.models import Source
75
-
76
- try:
77
- # need try except because of integer primary key migration
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
- kwargs["entity"] = kwargs["entity"].replace("bionty.", "")
84
- write_yaml(
85
- parse_currently_used_sources(active_records),
86
- bionty_base.settings.lamindb_sources,
87
- )
88
- except (OperationalError, ProgrammingError):
89
- pass
90
-
91
-
92
- def delete_bionty_sources_yaml():
93
- """Delete LAMINDB_SOURCES_PATH in bionty."""
94
- try:
95
- import bionty.base as bionty_base
96
-
97
- bionty_base.settings.lamindb_sources.unlink(missing_ok=True)
98
- except ModuleNotFoundError:
99
- pass
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ from django.db.utils import OperationalError, ProgrammingError
6
+
7
+ if TYPE_CHECKING:
8
+ from ._settings_instance import InstanceSettings
9
+
10
+ # bionty.Source -> bionty.base
11
+ RENAME = {"name": "source", "description": "source_name"}
12
+
13
+
14
+ def write_bionty_sources(isettings: InstanceSettings) -> None:
15
+ """Write bionty sources to Source table."""
16
+ if "bionty" not in isettings.schema:
17
+ return None
18
+ import shutil
19
+
20
+ import bionty
21
+ import bionty.base as bionty_base
22
+ from bionty._bionty import list_biorecord_models
23
+ from bionty.base.dev._handle_sources import parse_sources_yaml
24
+ from bionty.models import Source
25
+
26
+ bionty_models = list_biorecord_models(bionty)
27
+
28
+ shutil.copy(
29
+ bionty_base.settings.current_sources, bionty_base.settings.lamindb_sources
30
+ )
31
+
32
+ all_sources = parse_sources_yaml(bionty_base.settings.local_sources)
33
+ all_sources_dict = all_sources.to_dict(orient="records")
34
+
35
+ def _get_currently_used(key: str):
36
+ return (
37
+ bionty_base.display_currently_used_sources()
38
+ .reset_index()
39
+ .set_index(["entity", key])
40
+ )
41
+
42
+ currently_used = _get_currently_used("organism")
43
+
44
+ all_records = []
45
+ for kwargs in all_sources_dict:
46
+ act = currently_used.loc[(kwargs["entity"], kwargs["organism"])].to_dict()
47
+ if (act["source"] == kwargs["source"]) and (
48
+ act["version"] == kwargs["version"]
49
+ ):
50
+ kwargs["currently_used"] = True
51
+
52
+ # when the database is not yet migrated but setup is updated
53
+ # won't need this once lamindb is released with the new pin
54
+ kwargs["run"] = None # can't yet access tracking information
55
+ kwargs["in_db"] = False
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']}"
60
+ record = Source(**kwargs)
61
+ all_records.append(record)
62
+
63
+ Source.objects.bulk_create(all_records, ignore_conflicts=True)
64
+
65
+
66
+ def load_bionty_sources(isettings: InstanceSettings):
67
+ """Write currently_used bionty sources to LAMINDB_VERSIONS_PATH in bionty."""
68
+ if "bionty" not in isettings.schema:
69
+ return None
70
+
71
+ import bionty.base as bionty_base
72
+ from bionty.base.dev._handle_sources import parse_currently_used_sources
73
+ from bionty.base.dev._io import write_yaml
74
+ from bionty.models import Source
75
+
76
+ try:
77
+ # need try except because of integer primary key migration
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
+ kwargs["entity"] = kwargs["entity"].replace("bionty.", "")
84
+ write_yaml(
85
+ parse_currently_used_sources(active_records),
86
+ bionty_base.settings.lamindb_sources,
87
+ )
88
+ except (OperationalError, ProgrammingError):
89
+ pass
90
+
91
+
92
+ def delete_bionty_sources_yaml():
93
+ """Delete LAMINDB_SOURCES_PATH in bionty."""
94
+ try:
95
+ import bionty.base as bionty_base
96
+
97
+ bionty_base.settings.lamindb_sources.unlink(missing_ok=True)
98
+ except ModuleNotFoundError:
99
+ pass