diff --git a/lamindb_setup/_init_instance.py b/lamindb_setup/_init_instance.py index 11d864eb..3a4c3fd1 100644 --- a/lamindb_setup/_init_instance.py +++ b/lamindb_setup/_init_instance.py @@ -26,7 +26,7 @@ from .core.types import UPathStr -def get_schema_module_name(schema_name) -> str: +def get_schema_module_name(schema_name, raise_import_error: bool = True) -> str | None: import importlib.util name_attempts = [f"lnschema_{schema_name.replace('-', '_')}", schema_name] @@ -34,9 +34,11 @@ def get_schema_module_name(schema_name) -> str: module_spec = importlib.util.find_spec(name) if module_spec is not None: return name - raise ImportError( - f"Python package for '{schema_name}' is not installed.\nIf your package is on PyPI, run `pip install {schema_name}`" - ) + message = f"Schema module '{schema_name}' is not installed → no access to its labels & registries (resolve via `pip install {schema_name}`)" + if raise_import_error: + raise ImportError(message) + logger.warning(message.lower()) + return None def register_storage_in_instance(ssettings: StorageSettings): diff --git a/lamindb_setup/core/django.py b/lamindb_setup/core/django.py index 992ad625..517c4834 100644 --- a/lamindb_setup/core/django.py +++ b/lamindb_setup/core/django.py @@ -55,7 +55,17 @@ def setup_django( from .._init_instance import get_schema_module_name schema_names = ["core"] + list(isettings.schema) - installed_apps = [get_schema_module_name(n) for n in schema_names] + raise_import_error = True if init else False + installed_apps = [ + package_name + for n in schema_names + if ( + package_name := get_schema_module_name( + n, raise_import_error=raise_import_error + ) + ) + is not None + ] if view_schema: installed_apps = installed_apps[::-1] # to fix how apps appear installed_apps += ["schema_graph", "django.contrib.staticfiles"] diff --git a/noxfile.py b/noxfile.py index a6ee138a..918aa499 100644 --- a/noxfile.py +++ b/noxfile.py @@ -27,7 +27,7 @@ def lint(session: nox.Session) -> None: ["hub-local", "hub-prod", "hub-cloud", "storage", "docs"], ) def install(session: nox.Session, group: str) -> None: - no_deps_packages = "git+https://github.com/laminlabs/lnschema-core git+https://github.com/laminlabs/wetlab git+https://github.com/laminlabs/lamin-cli git+https://github.com/laminlabs/findrefs" + no_deps_packages = "git+https://github.com/laminlabs/lnschema-core git+https://github.com/laminlabs/wetlab git+https://github.com/laminlabs/lamin-cli" schema_deps = f"""uv pip install --system git+https://github.com/laminlabs/bionty git+https://github.com/laminlabs/lamindb uv pip install --system --no-deps {no_deps_packages} """