lamindb_setup 1.9.0__py3-none-any.whl → 1.9.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 (39) hide show
  1. lamindb_setup/__init__.py +107 -107
  2. lamindb_setup/_cache.py +87 -87
  3. lamindb_setup/_check_setup.py +166 -166
  4. lamindb_setup/_connect_instance.py +328 -342
  5. lamindb_setup/_delete.py +141 -141
  6. lamindb_setup/_disconnect.py +32 -32
  7. lamindb_setup/_init_instance.py +440 -440
  8. lamindb_setup/_migrate.py +266 -266
  9. lamindb_setup/_register_instance.py +35 -35
  10. lamindb_setup/_schema_metadata.py +441 -441
  11. lamindb_setup/_set_managed_storage.py +70 -70
  12. lamindb_setup/_setup_user.py +133 -133
  13. lamindb_setup/core/__init__.py +21 -21
  14. lamindb_setup/core/_aws_options.py +223 -223
  15. lamindb_setup/core/_hub_client.py +248 -248
  16. lamindb_setup/core/_hub_core.py +665 -665
  17. lamindb_setup/core/_hub_crud.py +227 -227
  18. lamindb_setup/core/_private_django_api.py +83 -83
  19. lamindb_setup/core/_settings.py +377 -377
  20. lamindb_setup/core/_settings_instance.py +569 -569
  21. lamindb_setup/core/_settings_load.py +141 -141
  22. lamindb_setup/core/_settings_save.py +95 -95
  23. lamindb_setup/core/_settings_storage.py +429 -429
  24. lamindb_setup/core/_settings_store.py +91 -91
  25. lamindb_setup/core/_settings_user.py +55 -55
  26. lamindb_setup/core/_setup_bionty_sources.py +44 -44
  27. lamindb_setup/core/cloud_sqlite_locker.py +240 -240
  28. lamindb_setup/core/django.py +305 -296
  29. lamindb_setup/core/exceptions.py +1 -1
  30. lamindb_setup/core/hashing.py +134 -134
  31. lamindb_setup/core/types.py +1 -1
  32. lamindb_setup/core/upath.py +1013 -1013
  33. lamindb_setup/errors.py +70 -70
  34. lamindb_setup/types.py +20 -20
  35. {lamindb_setup-1.9.0.dist-info → lamindb_setup-1.9.1.dist-info}/METADATA +1 -1
  36. lamindb_setup-1.9.1.dist-info/RECORD +50 -0
  37. lamindb_setup-1.9.0.dist-info/RECORD +0 -50
  38. {lamindb_setup-1.9.0.dist-info → lamindb_setup-1.9.1.dist-info}/LICENSE +0 -0
  39. {lamindb_setup-1.9.0.dist-info → lamindb_setup-1.9.1.dist-info}/WHEEL +0 -0
@@ -1,91 +1,91 @@
1
- import os
2
- from pathlib import Path
3
- from typing import Optional
4
-
5
- from lamin_utils import logger
6
- from platformdirs import site_config_dir
7
- from pydantic_settings import BaseSettings, SettingsConfigDict
8
-
9
- if "LAMIN_SETTINGS_DIR" in os.environ:
10
- # Needed when running with AWS Lambda, as only tmp/ directory has a write access
11
- settings_dir = Path(f"{os.environ['LAMIN_SETTINGS_DIR']}/.lamin")
12
- else:
13
- # user_config_dir is weird on MacOS!
14
- # hence, let's take home/.lamin
15
- settings_dir = Path.home() / ".lamin"
16
-
17
-
18
- try:
19
- settings_dir.mkdir(parents=True, exist_ok=True)
20
- except Exception as e:
21
- logger.warning(f"Failed to create lamin settings directory at {settings_dir}: {e}")
22
-
23
-
24
- system_settings_dir = Path(site_config_dir(appname="lamindb", appauthor="laminlabs"))
25
-
26
-
27
- def get_settings_file_name_prefix():
28
- if "LAMIN_ENV" in os.environ:
29
- if os.environ["LAMIN_ENV"] != "prod":
30
- return f"{os.environ['LAMIN_ENV']}--"
31
- return ""
32
-
33
-
34
- def current_instance_settings_file():
35
- return settings_dir / f"{get_settings_file_name_prefix()}current_instance.env"
36
-
37
-
38
- def current_user_settings_file():
39
- return settings_dir / f"{get_settings_file_name_prefix()}current_user.env"
40
-
41
-
42
- def instance_settings_file(name: str, owner: str):
43
- return (
44
- settings_dir / f"{get_settings_file_name_prefix()}instance--{owner}--{name}.env"
45
- )
46
-
47
-
48
- def user_settings_file_email(email: str):
49
- return settings_dir / f"{get_settings_file_name_prefix()}user--{email}.env"
50
-
51
-
52
- def user_settings_file_handle(handle: str):
53
- return settings_dir / f"{get_settings_file_name_prefix()}user--{handle}.env"
54
-
55
-
56
- # here user means the user directory on os, not a lamindb user
57
- def platform_user_storage_settings_file():
58
- return settings_dir / "storage.env"
59
-
60
-
61
- def system_settings_file():
62
- return system_settings_dir / "system.env"
63
-
64
-
65
- class InstanceSettingsStore(BaseSettings):
66
- api_url: Optional[str] = None
67
- owner: str
68
- name: str
69
- storage_root: str
70
- storage_region: Optional[str] # take old type annotations here because pydantic
71
- db: Optional[str] # doesn't like new types on 3.9 even with future annotations
72
- schema_str: Optional[str]
73
- schema_id: Optional[str] = None
74
- fine_grained_access: bool = False
75
- db_permissions: Optional[str] = None
76
- id: str
77
- git_repo: Optional[str]
78
- keep_artifacts_local: Optional[bool]
79
- model_config = SettingsConfigDict(env_prefix="lamindb_instance_", env_file=".env")
80
-
81
-
82
- class UserSettingsStore(BaseSettings):
83
- email: str
84
- password: str
85
- access_token: str
86
- api_key: Optional[str] = None
87
- uid: str
88
- uuid: str
89
- handle: str
90
- name: str
91
- 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 lamin_utils import logger
6
+ from platformdirs import site_config_dir
7
+ from pydantic_settings import BaseSettings, SettingsConfigDict
8
+
9
+ if "LAMIN_SETTINGS_DIR" in os.environ:
10
+ # Needed when running with AWS Lambda, as only tmp/ directory has a write access
11
+ settings_dir = Path(f"{os.environ['LAMIN_SETTINGS_DIR']}/.lamin")
12
+ else:
13
+ # user_config_dir is weird on MacOS!
14
+ # hence, let's take home/.lamin
15
+ settings_dir = Path.home() / ".lamin"
16
+
17
+
18
+ try:
19
+ settings_dir.mkdir(parents=True, exist_ok=True)
20
+ except Exception as e:
21
+ logger.warning(f"Failed to create lamin settings directory at {settings_dir}: {e}")
22
+
23
+
24
+ system_settings_dir = Path(site_config_dir(appname="lamindb", appauthor="laminlabs"))
25
+
26
+
27
+ def get_settings_file_name_prefix():
28
+ if "LAMIN_ENV" in os.environ:
29
+ if os.environ["LAMIN_ENV"] != "prod":
30
+ return f"{os.environ['LAMIN_ENV']}--"
31
+ return ""
32
+
33
+
34
+ def current_instance_settings_file():
35
+ return settings_dir / f"{get_settings_file_name_prefix()}current_instance.env"
36
+
37
+
38
+ def current_user_settings_file():
39
+ return settings_dir / f"{get_settings_file_name_prefix()}current_user.env"
40
+
41
+
42
+ def instance_settings_file(name: str, owner: str):
43
+ return (
44
+ settings_dir / f"{get_settings_file_name_prefix()}instance--{owner}--{name}.env"
45
+ )
46
+
47
+
48
+ def user_settings_file_email(email: str):
49
+ return settings_dir / f"{get_settings_file_name_prefix()}user--{email}.env"
50
+
51
+
52
+ def user_settings_file_handle(handle: str):
53
+ return settings_dir / f"{get_settings_file_name_prefix()}user--{handle}.env"
54
+
55
+
56
+ # here user means the user directory on os, not a lamindb user
57
+ def platform_user_storage_settings_file():
58
+ return settings_dir / "storage.env"
59
+
60
+
61
+ def system_settings_file():
62
+ return system_settings_dir / "system.env"
63
+
64
+
65
+ class InstanceSettingsStore(BaseSettings):
66
+ api_url: Optional[str] = None
67
+ owner: str
68
+ name: str
69
+ storage_root: str
70
+ storage_region: Optional[str] # take old type annotations here because pydantic
71
+ db: Optional[str] # doesn't like new types on 3.9 even with future annotations
72
+ schema_str: Optional[str]
73
+ schema_id: Optional[str] = None
74
+ fine_grained_access: bool = False
75
+ db_permissions: Optional[str] = None
76
+ id: str
77
+ git_repo: Optional[str]
78
+ keep_artifacts_local: Optional[bool]
79
+ model_config = SettingsConfigDict(env_prefix="lamindb_instance_", env_file=".env")
80
+
81
+
82
+ class UserSettingsStore(BaseSettings):
83
+ email: str
84
+ password: str
85
+ access_token: str
86
+ api_key: Optional[str] = None
87
+ uid: str
88
+ uuid: str
89
+ handle: str
90
+ name: str
91
+ model_config = SettingsConfigDict(env_prefix="lamin_user_", env_file=".env")
@@ -1,55 +1,55 @@
1
- from __future__ import annotations
2
-
3
- from dataclasses import dataclass
4
- from typing import TYPE_CHECKING
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 = None
25
- """User email."""
26
- api_key: str | None = None
27
- """API key."""
28
- password: str | None = None
29
- """legacy API key or legacy password."""
30
- access_token: str | None = None
31
- """User access token."""
32
- uid: str = "null"
33
- """Universal user ID."""
34
- _uuid: UUID | None = None
35
- """Lamin's internal user ID."""
36
- name: str | None = None
37
- """Full name."""
38
-
39
- def __repr__(self) -> str:
40
- """Rich string representation."""
41
- representation = "Current user:"
42
- attrs = ["handle", "uid"]
43
- for attr in attrs:
44
- value = getattr(self, attr)
45
- representation += f"\n - {attr}: {value}"
46
- return representation
47
-
48
- @property
49
- def id(self):
50
- """Integer id valid in current instance."""
51
- from lamindb.base.users import current_user_id
52
-
53
- # there is no cache needed here because current_user_id()
54
- # has its own cache
55
- return current_user_id()
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import TYPE_CHECKING
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 = None
25
+ """User email."""
26
+ api_key: str | None = None
27
+ """API key."""
28
+ password: str | None = None
29
+ """legacy API key or legacy password."""
30
+ access_token: str | None = None
31
+ """User access token."""
32
+ uid: str = "null"
33
+ """Universal user ID."""
34
+ _uuid: UUID | None = None
35
+ """Lamin's internal user ID."""
36
+ name: str | None = None
37
+ """Full name."""
38
+
39
+ def __repr__(self) -> str:
40
+ """Rich string representation."""
41
+ representation = "Current user:"
42
+ attrs = ["handle", "uid"]
43
+ for attr in attrs:
44
+ value = getattr(self, attr)
45
+ representation += f"\n - {attr}: {value}"
46
+ return representation
47
+
48
+ @property
49
+ def id(self):
50
+ """Integer id valid in current instance."""
51
+ from lamindb.base.users import current_user_id
52
+
53
+ # there is no cache needed here because current_user_id()
54
+ # has its own cache
55
+ return current_user_id()
@@ -1,44 +1,44 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
-
5
- if TYPE_CHECKING:
6
- from ._settings_instance import InstanceSettings
7
-
8
-
9
- def write_bionty_sources(isettings: InstanceSettings) -> None:
10
- """Write public bionty sources to bt.Source table."""
11
- if "bionty" not in isettings.modules:
12
- return None
13
-
14
- import bionty
15
- import bionty.base as bionty_base
16
- from bionty._biorecord import list_biorecord_models
17
- from bionty.base.dev._handle_sources import parse_sources_yaml
18
- from bionty.models import Source
19
-
20
- bionty_models = list_biorecord_models(bionty)
21
-
22
- all_sources = parse_sources_yaml(bionty_base.settings.public_sources)
23
- all_sources_dict = all_sources.to_dict(orient="records")
24
-
25
- currently_used = (
26
- bionty_base.display_currently_used_sources(mute=True)
27
- .reset_index()
28
- .set_index(["entity", "organism"])
29
- )
30
-
31
- all_records = []
32
- for kwargs in all_sources_dict:
33
- act = currently_used.loc[(kwargs["entity"], kwargs["organism"])].to_dict()
34
- if (act["name"] == kwargs["name"]) and (act["version"] == kwargs["version"]):
35
- kwargs["currently_used"] = True
36
-
37
- kwargs["run"] = None # can't yet access tracking information
38
- kwargs["in_db"] = False
39
- if kwargs["entity"] in bionty_models:
40
- kwargs["entity"] = f"bionty.{kwargs['entity']}"
41
- record = Source(**kwargs)
42
- all_records.append(record)
43
-
44
- Source.objects.bulk_create(all_records, ignore_conflicts=True)
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from ._settings_instance import InstanceSettings
7
+
8
+
9
+ def write_bionty_sources(isettings: InstanceSettings) -> None:
10
+ """Write public bionty sources to bt.Source table."""
11
+ if "bionty" not in isettings.modules:
12
+ return None
13
+
14
+ import bionty
15
+ import bionty.base as bionty_base
16
+ from bionty._biorecord import list_biorecord_models
17
+ from bionty.base.dev._handle_sources import parse_sources_yaml
18
+ from bionty.models import Source
19
+
20
+ bionty_models = list_biorecord_models(bionty)
21
+
22
+ all_sources = parse_sources_yaml(bionty_base.settings.public_sources)
23
+ all_sources_dict = all_sources.to_dict(orient="records")
24
+
25
+ currently_used = (
26
+ bionty_base.display_currently_used_sources(mute=True)
27
+ .reset_index()
28
+ .set_index(["entity", "organism"])
29
+ )
30
+
31
+ all_records = []
32
+ for kwargs in all_sources_dict:
33
+ act = currently_used.loc[(kwargs["entity"], kwargs["organism"])].to_dict()
34
+ if (act["name"] == kwargs["name"]) and (act["version"] == kwargs["version"]):
35
+ kwargs["currently_used"] = True
36
+
37
+ kwargs["run"] = None # can't yet access tracking information
38
+ kwargs["in_db"] = False
39
+ if kwargs["entity"] in bionty_models:
40
+ kwargs["entity"] = f"bionty.{kwargs['entity']}"
41
+ record = Source(**kwargs)
42
+ all_records.append(record)
43
+
44
+ Source.objects.bulk_create(all_records, ignore_conflicts=True)