From ee11da17d6eb8581bd1b80afb2d6ff7e251f2333 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Tue, 31 Dec 2024 17:43:59 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=9A=20Fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lamindb_setup/_check_setup.py | 26 ++++++++------------------ lamindb_setup/_connect_instance.py | 9 --------- lamindb_setup/_init_instance.py | 30 ------------------------------ 3 files changed, 8 insertions(+), 57 deletions(-) diff --git a/lamindb_setup/_check_setup.py b/lamindb_setup/_check_setup.py index 9f89946e..49eab390 100644 --- a/lamindb_setup/_check_setup.py +++ b/lamindb_setup/_check_setup.py @@ -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() @@ -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 diff --git a/lamindb_setup/_connect_instance.py b/lamindb_setup/_connect_instance.py index 5163052a..7a9a5a4e 100644 --- a/lamindb_setup/_connect_instance.py +++ b/lamindb_setup/_connect_instance.py @@ -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) diff --git a/lamindb_setup/_init_instance.py b/lamindb_setup/_init_instance.py index 577e0684..d191ca43 100644 --- a/lamindb_setup/_init_instance.py +++ b/lamindb_setup/_init_instance.py @@ -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). @@ -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: