Skip to content

Commit

Permalink
🚸 Do not error if a schema module of an instance isn't installed (#883)
Browse files Browse the repository at this point in the history
* πŸ‘· Do not install findrefs

* 🚸 Do not error if a schema module of an instance isn't installed

* 🎨 Better

* πŸ’š Fix

* πŸ’š Fix
  • Loading branch information
falexwolf authored Oct 11, 2024
1 parent c4fafda commit 3abffba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lamindb_setup/_init_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@
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]
for name in name_attempts:
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):
Expand Down
12 changes: 11 additions & 1 deletion lamindb_setup/core/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"""
Expand Down

0 comments on commit 3abffba

Please sign in to comment.