Skip to content

Commit f27e373

Browse files
ZethsonKoncopd
andauthored
✨ Add Settings __repr__ (#2874)
Signed-off-by: Lukas Heumos <[email protected]> Co-authored-by: Sergei Rybakov <[email protected]>
1 parent cffe65a commit f27e373

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lamindb/core/_settings.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import TYPE_CHECKING
55

66
import lamindb_setup as ln_setup
7-
from lamin_utils import logger
7+
from lamin_utils import colors, logger
88
from lamindb_setup._set_managed_storage import set_managed_storage
99
from lamindb_setup.core._settings import settings as setup_settings
1010
from lamindb_setup.core._settings_instance import sanitize_git_repo_url
@@ -43,6 +43,36 @@ def __init__(self):
4343
logger.set_verbosity(self._verbosity_int)
4444
self._sync_git_repo: str | None = None
4545

46+
def __repr__(self) -> str: # pragma: no cover
47+
cls_name = colors.green(self.__class__.__name__)
48+
verbosity_color = colors.yellow if self.verbosity == "warning" else colors.green
49+
verbosity_str = verbosity_color(self.verbosity)
50+
51+
storage_root = self._storage_settings.root_as_str
52+
storage_str = colors.italic(storage_root)
53+
54+
instance_str = colors.italic(self.instance_uid)
55+
track_color = colors.green if self.track_run_inputs else colors.yellow
56+
track_str = track_color(str(self.track_run_inputs))
57+
58+
lines = [
59+
f"{cls_name}",
60+
f" instance: {instance_str}",
61+
f" storage: {storage_str}",
62+
f" verbosity: {verbosity_str}",
63+
f" track_run_inputs: {track_str}",
64+
]
65+
66+
if self.sync_git_repo:
67+
repo_name = (
68+
self.sync_git_repo.split("/")[-1]
69+
if "/" in self.sync_git_repo
70+
else self.sync_git_repo
71+
)
72+
lines.append(f" sync_git_repo: {colors.italic(repo_name)}")
73+
74+
return "\n".join(lines)
75+
4676
@property
4777
def creation(self) -> CreationSettings:
4878
"""SQLRecord creation settings.

tests/core/test_settings.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import lamindb as ln
2+
3+
4+
def test_settings_repr():
5+
repr_str = repr(ln.settings)
6+
7+
lines = repr_str.split("\n")
8+
assert "Settings" in lines[0]
9+
assert all(line.startswith(" ") for line in lines[1:])
10+
11+
content = "\n".join(lines[1:])
12+
assert content.find("instance:") < content.find("storage:")
13+
assert content.find("storage:") < content.find("verbosity:")
14+
assert content.find("verbosity:") < content.find("track_run_inputs:")

0 commit comments

Comments
 (0)