lamindb_setup 0.77.4__py2.py3-none-any.whl → 0.77.5__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 (46) 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 +431 -444
  7. lamindb_setup/_django.py +41 -41
  8. lamindb_setup/_entry_points.py +22 -22
  9. lamindb_setup/_exportdb.py +68 -68
  10. lamindb_setup/_importdb.py +50 -50
  11. lamindb_setup/_init_instance.py +417 -374
  12. lamindb_setup/_migrate.py +239 -239
  13. lamindb_setup/_register_instance.py +36 -36
  14. lamindb_setup/_schema.py +27 -27
  15. lamindb_setup/_schema_metadata.py +411 -411
  16. lamindb_setup/_set_managed_storage.py +55 -55
  17. lamindb_setup/_setup_user.py +137 -137
  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_core.py +611 -590
  25. lamindb_setup/core/_hub_crud.py +211 -211
  26. lamindb_setup/core/_hub_utils.py +109 -109
  27. lamindb_setup/core/_private_django_api.py +88 -88
  28. lamindb_setup/core/_settings.py +138 -138
  29. lamindb_setup/core/_settings_instance.py +480 -467
  30. lamindb_setup/core/_settings_load.py +105 -105
  31. lamindb_setup/core/_settings_save.py +81 -81
  32. lamindb_setup/core/_settings_storage.py +412 -405
  33. lamindb_setup/core/_settings_store.py +75 -75
  34. lamindb_setup/core/_settings_user.py +53 -53
  35. lamindb_setup/core/_setup_bionty_sources.py +101 -101
  36. lamindb_setup/core/cloud_sqlite_locker.py +237 -232
  37. lamindb_setup/core/django.py +114 -114
  38. lamindb_setup/core/exceptions.py +12 -12
  39. lamindb_setup/core/hashing.py +114 -114
  40. lamindb_setup/core/types.py +19 -19
  41. lamindb_setup/core/upath.py +779 -779
  42. {lamindb_setup-0.77.4.dist-info → lamindb_setup-0.77.5.dist-info}/METADATA +1 -1
  43. lamindb_setup-0.77.5.dist-info/RECORD +47 -0
  44. {lamindb_setup-0.77.4.dist-info → lamindb_setup-0.77.5.dist-info}/WHEEL +1 -1
  45. lamindb_setup-0.77.4.dist-info/RECORD +0 -47
  46. {lamindb_setup-0.77.4.dist-info → lamindb_setup-0.77.5.dist-info}/LICENSE +0 -0
@@ -1,88 +1,88 @@
1
- from __future__ import annotations
2
-
3
- import os
4
- from pathlib import Path
5
-
6
-
7
- def find_vscode_stubs_folder() -> Path | None:
8
- # Possible locations of VSCode extensions
9
- possible_locations = [
10
- Path.home() / ".vscode" / "extensions", # Linux and macOS
11
- Path.home() / ".vscode-server" / "extensions", # Remote development
12
- Path(os.environ.get("APPDATA", "")) / "Code" / "User" / "extensions", # Windows
13
- Path("/usr/share/code/resources/app/extensions"), # Some Linux distributions
14
- ]
15
- for location in possible_locations:
16
- if location.exists():
17
- # Look for Pylance extension folder
18
- pylance_folders = list(location.glob("ms-python.vscode-pylance-*"))
19
- if pylance_folders:
20
- # Sort to get the latest version
21
- latest_pylance = sorted(pylance_folders)[-1]
22
- stubs_folder = (
23
- latest_pylance / "dist" / "bundled" / "stubs" / "django-stubs"
24
- )
25
- if stubs_folder.exists():
26
- return stubs_folder
27
-
28
- return None
29
-
30
-
31
- def private_django_api(reverse=False):
32
- from django import db
33
-
34
- # the order here matters
35
- # changing it might break the tests
36
- attributes = [
37
- "DoesNotExist",
38
- "MultipleObjectsReturned",
39
- "add_to_class",
40
- "adelete",
41
- "refresh_from_db",
42
- "asave",
43
- "clean",
44
- "clean_fields",
45
- "date_error_message",
46
- "get_constraints",
47
- "get_deferred_fields",
48
- "prepare_database_save",
49
- "save_base",
50
- "serializable_value",
51
- "unique_error_message",
52
- "validate_constraints",
53
- "validate_unique",
54
- ]
55
- if reverse:
56
- attributes.append("arefresh_from_db")
57
- attributes.append("full_clean")
58
- else:
59
- attributes.append("a_refresh_from_db")
60
- attributes.append("full__clean")
61
-
62
- django_path = Path(db.__file__).parent.parent
63
-
64
- encoding = "utf8" if os.name == "nt" else None
65
-
66
- def prune_file(file_path):
67
- content = file_path.read_text(encoding=encoding)
68
- original_content = content
69
-
70
- for attr in attributes:
71
- old_name = f"_{attr}" if reverse else attr
72
- new_name = attr if reverse else f"_{attr}"
73
- content = content.replace(old_name, new_name)
74
-
75
- if not reverse:
76
- content = content.replace("Field_DoesNotExist", "FieldDoesNotExist")
77
- content = content.replace("Object_DoesNotExist", "ObjectDoesNotExist")
78
-
79
- if content != original_content:
80
- file_path.write_text(content, encoding=encoding)
81
-
82
- for file_path in django_path.rglob("*.py"):
83
- prune_file(file_path)
84
-
85
- pylance_path = find_vscode_stubs_folder()
86
- if pylance_path is not None:
87
- for file_path in pylance_path.rglob("*.pyi"):
88
- prune_file(file_path)
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ from pathlib import Path
5
+
6
+
7
+ def find_vscode_stubs_folder() -> Path | None:
8
+ # Possible locations of VSCode extensions
9
+ possible_locations = [
10
+ Path.home() / ".vscode" / "extensions", # Linux and macOS
11
+ Path.home() / ".vscode-server" / "extensions", # Remote development
12
+ Path(os.environ.get("APPDATA", "")) / "Code" / "User" / "extensions", # Windows
13
+ Path("/usr/share/code/resources/app/extensions"), # Some Linux distributions
14
+ ]
15
+ for location in possible_locations:
16
+ if location.exists():
17
+ # Look for Pylance extension folder
18
+ pylance_folders = list(location.glob("ms-python.vscode-pylance-*"))
19
+ if pylance_folders:
20
+ # Sort to get the latest version
21
+ latest_pylance = sorted(pylance_folders)[-1]
22
+ stubs_folder = (
23
+ latest_pylance / "dist" / "bundled" / "stubs" / "django-stubs"
24
+ )
25
+ if stubs_folder.exists():
26
+ return stubs_folder
27
+
28
+ return None
29
+
30
+
31
+ def private_django_api(reverse=False):
32
+ from django import db
33
+
34
+ # the order here matters
35
+ # changing it might break the tests
36
+ attributes = [
37
+ "DoesNotExist",
38
+ "MultipleObjectsReturned",
39
+ "add_to_class",
40
+ "adelete",
41
+ "refresh_from_db",
42
+ "asave",
43
+ "clean",
44
+ "clean_fields",
45
+ "date_error_message",
46
+ "get_constraints",
47
+ "get_deferred_fields",
48
+ "prepare_database_save",
49
+ "save_base",
50
+ "serializable_value",
51
+ "unique_error_message",
52
+ "validate_constraints",
53
+ "validate_unique",
54
+ ]
55
+ if reverse:
56
+ attributes.append("arefresh_from_db")
57
+ attributes.append("full_clean")
58
+ else:
59
+ attributes.append("a_refresh_from_db")
60
+ attributes.append("full__clean")
61
+
62
+ django_path = Path(db.__file__).parent.parent
63
+
64
+ encoding = "utf8" if os.name == "nt" else None
65
+
66
+ def prune_file(file_path):
67
+ content = file_path.read_text(encoding=encoding)
68
+ original_content = content
69
+
70
+ for attr in attributes:
71
+ old_name = f"_{attr}" if reverse else attr
72
+ new_name = attr if reverse else f"_{attr}"
73
+ content = content.replace(old_name, new_name)
74
+
75
+ if not reverse:
76
+ content = content.replace("Field_DoesNotExist", "FieldDoesNotExist")
77
+ content = content.replace("Object_DoesNotExist", "ObjectDoesNotExist")
78
+
79
+ if content != original_content:
80
+ file_path.write_text(content, encoding=encoding)
81
+
82
+ for file_path in django_path.rglob("*.py"):
83
+ prune_file(file_path)
84
+
85
+ pylance_path = find_vscode_stubs_folder()
86
+ if pylance_path is not None:
87
+ for file_path in pylance_path.rglob("*.pyi"):
88
+ prune_file(file_path)
@@ -1,138 +1,138 @@
1
- from __future__ import annotations
2
-
3
- import os
4
- from typing import TYPE_CHECKING
5
-
6
- from ._settings_load import (
7
- load_instance_settings,
8
- load_or_create_user_settings,
9
- )
10
- from ._settings_store import current_instance_settings_file, settings_dir
11
-
12
- if TYPE_CHECKING:
13
- from pathlib import Path
14
-
15
- from lamindb_setup.core import InstanceSettings, StorageSettings, UserSettings
16
-
17
-
18
- class SetupSettings:
19
- """Setup settings."""
20
-
21
- _using_key: str | None = None # set through lamindb.settings
22
-
23
- _user_settings: UserSettings | None = None
24
- _instance_settings: InstanceSettings | None = None
25
-
26
- _user_settings_env: str | None = None
27
- _instance_settings_env: str | None = None
28
-
29
- _auto_connect_path: Path = settings_dir / "auto_connect"
30
- _private_django_api_path: Path = settings_dir / "private_django_api"
31
-
32
- @property
33
- def _instance_settings_path(self) -> Path:
34
- return current_instance_settings_file()
35
-
36
- @property
37
- def settings_dir(self) -> Path:
38
- """The directory that holds locally persisted settings."""
39
- return settings_dir
40
-
41
- @property
42
- def auto_connect(self) -> bool:
43
- """Auto-connect to loaded instance upon lamindb import.
44
-
45
- `lamin init` and `lamin load` switch this to `True`.
46
-
47
- `ln.connect()` doesn't change the value of this setting.
48
- """
49
- return self._auto_connect_path.exists()
50
-
51
- @auto_connect.setter
52
- def auto_connect(self, value: bool) -> None:
53
- if value:
54
- self._auto_connect_path.touch()
55
- else:
56
- self._auto_connect_path.unlink(missing_ok=True)
57
-
58
- @property
59
- def private_django_api(self) -> bool:
60
- """Turn internal Django API private to clean up the API (default `False`).
61
-
62
- This patches your local pip-installed django installation. You can undo
63
- the patch by setting this back to `False`.
64
- """
65
- return self._private_django_api_path.exists()
66
-
67
- @private_django_api.setter
68
- def private_django_api(self, value: bool) -> None:
69
- from ._private_django_api import private_django_api
70
-
71
- # we don't want to call private_django_api() twice
72
- if value and not self.private_django_api:
73
- private_django_api()
74
- self._private_django_api_path.touch()
75
- elif not value and self.private_django_api:
76
- private_django_api(reverse=True)
77
- self._private_django_api_path.unlink(missing_ok=True)
78
-
79
- @property
80
- def user(self) -> UserSettings:
81
- """Settings of current user."""
82
- env_changed = (
83
- self._user_settings_env is not None
84
- and self._user_settings_env != get_env_name()
85
- )
86
- if self._user_settings is None or env_changed:
87
- self._user_settings = load_or_create_user_settings()
88
- self._user_settings_env = get_env_name()
89
- if self._user_settings and self._user_settings.uid is None:
90
- raise RuntimeError("Need to login, first: lamin login <email>")
91
- return self._user_settings # type: ignore
92
-
93
- @property
94
- def instance(self) -> InstanceSettings:
95
- """Settings of current LaminDB instance."""
96
- env_changed = (
97
- self._instance_settings_env is not None
98
- and self._instance_settings_env != get_env_name()
99
- )
100
- if self._instance_settings is None or env_changed:
101
- self._instance_settings = load_instance_settings()
102
- self._instance_settings_env = get_env_name()
103
- return self._instance_settings # type: ignore
104
-
105
- @property
106
- def storage(self) -> StorageSettings:
107
- """Settings of default storage."""
108
- return self.instance.storage
109
-
110
- @property
111
- def _instance_exists(self):
112
- try:
113
- self.instance # noqa
114
- return True
115
- # this is implicit logic that catches if no instance is loaded
116
- except SystemExit:
117
- return False
118
-
119
- def __repr__(self) -> str:
120
- """Rich string representation."""
121
- repr = self.user.__repr__()
122
- repr += f"\nAuto-connect in Python: {self.auto_connect}\n"
123
- repr += f"Private Django API: {self.private_django_api}\n"
124
- if self._instance_exists:
125
- repr += self.instance.__repr__()
126
- else:
127
- repr += "\nNo instance connected"
128
- return repr
129
-
130
-
131
- def get_env_name():
132
- if "LAMIN_ENV" in os.environ:
133
- return os.environ["LAMIN_ENV"]
134
- else:
135
- return "prod"
136
-
137
-
138
- settings = SetupSettings()
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ from typing import TYPE_CHECKING
5
+
6
+ from ._settings_load import (
7
+ load_instance_settings,
8
+ load_or_create_user_settings,
9
+ )
10
+ from ._settings_store import current_instance_settings_file, settings_dir
11
+
12
+ if TYPE_CHECKING:
13
+ from pathlib import Path
14
+
15
+ from lamindb_setup.core import InstanceSettings, StorageSettings, UserSettings
16
+
17
+
18
+ class SetupSettings:
19
+ """Setup settings."""
20
+
21
+ _using_key: str | None = None # set through lamindb.settings
22
+
23
+ _user_settings: UserSettings | None = None
24
+ _instance_settings: InstanceSettings | None = None
25
+
26
+ _user_settings_env: str | None = None
27
+ _instance_settings_env: str | None = None
28
+
29
+ _auto_connect_path: Path = settings_dir / "auto_connect"
30
+ _private_django_api_path: Path = settings_dir / "private_django_api"
31
+
32
+ @property
33
+ def _instance_settings_path(self) -> Path:
34
+ return current_instance_settings_file()
35
+
36
+ @property
37
+ def settings_dir(self) -> Path:
38
+ """The directory that holds locally persisted settings."""
39
+ return settings_dir
40
+
41
+ @property
42
+ def auto_connect(self) -> bool:
43
+ """Auto-connect to loaded instance upon lamindb import.
44
+
45
+ `lamin init` and `lamin load` switch this to `True`.
46
+
47
+ `ln.connect()` doesn't change the value of this setting.
48
+ """
49
+ return self._auto_connect_path.exists()
50
+
51
+ @auto_connect.setter
52
+ def auto_connect(self, value: bool) -> None:
53
+ if value:
54
+ self._auto_connect_path.touch()
55
+ else:
56
+ self._auto_connect_path.unlink(missing_ok=True)
57
+
58
+ @property
59
+ def private_django_api(self) -> bool:
60
+ """Turn internal Django API private to clean up the API (default `False`).
61
+
62
+ This patches your local pip-installed django installation. You can undo
63
+ the patch by setting this back to `False`.
64
+ """
65
+ return self._private_django_api_path.exists()
66
+
67
+ @private_django_api.setter
68
+ def private_django_api(self, value: bool) -> None:
69
+ from ._private_django_api import private_django_api
70
+
71
+ # we don't want to call private_django_api() twice
72
+ if value and not self.private_django_api:
73
+ private_django_api()
74
+ self._private_django_api_path.touch()
75
+ elif not value and self.private_django_api:
76
+ private_django_api(reverse=True)
77
+ self._private_django_api_path.unlink(missing_ok=True)
78
+
79
+ @property
80
+ def user(self) -> UserSettings:
81
+ """Settings of current user."""
82
+ env_changed = (
83
+ self._user_settings_env is not None
84
+ and self._user_settings_env != get_env_name()
85
+ )
86
+ if self._user_settings is None or env_changed:
87
+ self._user_settings = load_or_create_user_settings()
88
+ self._user_settings_env = get_env_name()
89
+ if self._user_settings and self._user_settings.uid is None:
90
+ raise RuntimeError("Need to login, first: lamin login <email>")
91
+ return self._user_settings # type: ignore
92
+
93
+ @property
94
+ def instance(self) -> InstanceSettings:
95
+ """Settings of current LaminDB instance."""
96
+ env_changed = (
97
+ self._instance_settings_env is not None
98
+ and self._instance_settings_env != get_env_name()
99
+ )
100
+ if self._instance_settings is None or env_changed:
101
+ self._instance_settings = load_instance_settings()
102
+ self._instance_settings_env = get_env_name()
103
+ return self._instance_settings # type: ignore
104
+
105
+ @property
106
+ def storage(self) -> StorageSettings:
107
+ """Settings of default storage."""
108
+ return self.instance.storage
109
+
110
+ @property
111
+ def _instance_exists(self):
112
+ try:
113
+ self.instance # noqa
114
+ return True
115
+ # this is implicit logic that catches if no instance is loaded
116
+ except SystemExit:
117
+ return False
118
+
119
+ def __repr__(self) -> str:
120
+ """Rich string representation."""
121
+ repr = self.user.__repr__()
122
+ repr += f"\nAuto-connect in Python: {self.auto_connect}\n"
123
+ repr += f"Private Django API: {self.private_django_api}\n"
124
+ if self._instance_exists:
125
+ repr += self.instance.__repr__()
126
+ else:
127
+ repr += "\nNo instance connected"
128
+ return repr
129
+
130
+
131
+ def get_env_name():
132
+ if "LAMIN_ENV" in os.environ:
133
+ return os.environ["LAMIN_ENV"]
134
+ else:
135
+ return "prod"
136
+
137
+
138
+ settings = SetupSettings()