Skip to content

Commit

Permalink
♻️ Replace InstanceSettings.identifier with InstanceSettings.slug
Browse files Browse the repository at this point in the history
  • Loading branch information
falexwolf committed Mar 6, 2024
1 parent 001b102 commit 638d384
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lamindb_setup/_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def close(mute: bool = False) -> None:
Returns `None` if succeeds, otherwise an exception is raised.
"""
if current_instance_settings_file().exists():
instance = settings.instance.identifier
instance = settings.instance.slug
try:
settings.instance._update_cloud_sqlite_file()
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion lamindb_setup/_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def delete(instance_name: str, force: bool = False):

delete_settings(settings_file)
if settings._instance_exists:
if instance_identifier == settings.instance.identifier:
if instance_identifier == settings.instance.slug:
close(mute=True) # close() does further operations, unlocking...
settings._instance_settings = None
delete_cache(isettings.storage.cache_dir)
Expand Down
2 changes: 1 addition & 1 deletion lamindb_setup/_init_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def reload_lamindb(isettings: InstanceSettings):
import lamindb

importlib.reload(lamindb)
logger.important(f"lamindb instance: {isettings.identifier}")
logger.important(f"lamindb instance: {isettings.slug}")
else:
# only log if we're outside lamindb
# lamindb itself logs upon import!
Expand Down
5 changes: 1 addition & 4 deletions lamindb_setup/_load_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ def load(
)
else:
# compare normalized identifier with a potentially previously loaded identifier
if (
settings._instance_exists
and f"{owner}/{name}" != settings.instance.identifier
):
if settings._instance_exists and f"{owner}/{name}" != settings.instance.slug:
close_instance(mute=True)

settings_file = instance_settings_file(name, owner)
Expand Down
2 changes: 1 addition & 1 deletion lamindb_setup/_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def deploy(cls) -> None:
if collaborator is None or collaborator["role"] != "admin":
raise SystemExit(
"❌ Only admins can deploy migrations, please ensure that you're an"
f" admin: https://lamin.ai/{settings.instance.identifier}/settings"
f" admin: https://lamin.ai/{settings.instance.slug}/settings"
)
# we need lamindb to be installed, otherwise we can't populate the version
# information in the hub
Expand Down
16 changes: 11 additions & 5 deletions lamindb_setup/core/_settings_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(

def __repr__(self):
"""Rich string representation."""
representation = f"Current instance: {self.identifier}"
representation = f"Current instance: {self.slug}"
attrs = ["owner", "name", "storage", "db", "schema"]
for attr in attrs:
value = getattr(self, attr)
Expand Down Expand Up @@ -80,10 +80,16 @@ def name(self) -> str:

@property
def identifier(self) -> str:
"""Unique semantic identifier.
"""Unique semantic identifier."""
logger.warning(
"InstanceSettings.identifier is deprecated and will be removed, use"
" InstanceSettings.slug instead"
)
return self.slug

See remote instances at https://lamin.ai/owner/name.
"""
@property
def slug(self) -> str:
"""Unique semantic identifier of form `"{account_handle}/{instance_name}"`."""
return f"{self.owner}/{self.name}"

@property
Expand Down Expand Up @@ -120,7 +126,7 @@ def _update_cloud_sqlite_file(self, unlock_cloud_sqlite: bool = True) -> None:
sqlite_file = self._sqlite_file
logger.warning(
f"updating & unlocking cloud SQLite '{sqlite_file}' of instance"
f" '{self.identifier}'"
f" '{self.slug}'"
)
cache_file = self.storage.cloud_to_local_no_update(sqlite_file)
sqlite_file.upload_from(cache_file, print_progress=True) # type: ignore
Expand Down

0 comments on commit 638d384

Please sign in to comment.