Skip to content

Commit

Permalink
💚 Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
falexwolf committed Dec 31, 2024
1 parent 25c4f71 commit ee11da1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 57 deletions.
26 changes: 8 additions & 18 deletions lamindb_setup/_check_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,11 @@ def _get_current_instance_settings() -> InstanceSettings | None:

# we make this a private function because in all the places it's used,
# users should not see it
def _check_instance_setup(
from_lamindb: bool = False, from_module: str | None = None
) -> bool:
reload_module = from_lamindb or from_module is not None
from ._init_instance import get_schema_module_name, reload_schema_modules

def _check_instance_setup(from_module: str | None = None) -> bool:
if django.IS_SETUP:
# reload logic here because module might not yet have been imported
# upon first setup
if from_module is not None:
if from_module is not None and from_module != "lamindb":
il.reload(il.import_module(from_module))
return True
silence_loggers()
Expand All @@ -75,18 +70,13 @@ def _check_instance_setup(
return True
isettings = _get_current_instance_settings()
if isettings is not None:
if reload_module and settings.auto_connect:
if not django.IS_SETUP:
django.setup_django(isettings)
if from_module is not None:
# this only reloads `from_module`
il.reload(il.import_module(from_module))
else:
# this bulk reloads all schema modules
reload_schema_modules(isettings)
logger.important(f"connected lamindb: {isettings.slug}")
if from_module is not None and settings.auto_connect and not django.IS_SETUP:
django.setup_django(isettings)
if from_module != "lamindb":
il.reload(il.import_module(from_module))
logger.important(f"connected lamindb: {isettings.slug}")
return django.IS_SETUP
else:
if reload_module and settings.auto_connect:
if from_module is not None and settings.auto_connect:
logger.warning(InstanceNotSetupError.default_message)
return False
9 changes: 0 additions & 9 deletions lamindb_setup/_connect_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,6 @@ def connect(slug: str, **kwargs) -> str | tuple | None:
if kwarg not in valid_kwargs:
raise TypeError(f"connect() got unexpected keyword argument '{kwarg}'")

# migrate away from lnschema_core
try:
import lnschema_core

logger.important("found legacy lnschema_core, uninstalling it")
subprocess.run("pip uninstall -y lnschema-core", shell=True)
except ImportError:
pass

isettings: InstanceSettings = None # type: ignore
# _db is still needed because it is called in init
_db: str | None = kwargs.get("_db", None)
Expand Down
30 changes: 0 additions & 30 deletions lamindb_setup/_init_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,35 +99,6 @@ def register_user_and_storage_in_instance(isettings: InstanceSettings, usettings
logger.warning(f"instance seems not set up ({error})")


def reload_schema_modules(isettings: InstanceSettings, include_core: bool = True):
schema_names = ["lamindb"] if include_core else []
# schema_names += list(isettings.schema)
schema_module_names = [get_schema_module_name(n) for n in schema_names]

for schema_module_name in schema_module_names:
if schema_module_name in sys.modules:
schema_module = importlib.import_module(schema_module_name)
importlib.reload(schema_module)


def reload_lamindb_itself(isettings) -> bool:
reloaded = False
if "lamindb" in sys.modules:
import lamindb

importlib.reload(lamindb)
reloaded = True
return reloaded


def reload_lamindb(isettings: InstanceSettings):
log_message = settings.auto_connect
if not reload_lamindb_itself(isettings):
log_message = True
if log_message:
logger.important(f"connected lamindb: {isettings.slug}")


ERROR_SQLITE_CACHE = """
Your cached local SQLite file exists, while your cloud SQLite file ({}) doesn't.
Either delete your cache ({}) or add it back to the cloud (if delete was accidental).
Expand Down Expand Up @@ -378,7 +349,6 @@ def load_from_isettings(
if not isettings._get_settings_file().exists():
register_user(user)
isettings._persist(write_to_disk=write_settings)
reload_lamindb(isettings)


def validate_sqlite_state(isettings: InstanceSettings) -> None:
Expand Down

0 comments on commit ee11da1

Please sign in to comment.