diff --git a/src/haddock/modules/scoring/deeprank/deeprank.py b/src/haddock/modules/scoring/deeprank/deeprank.py index e7c6171cee..f5da9d0972 100644 --- a/src/haddock/modules/scoring/deeprank/deeprank.py +++ b/src/haddock/modules/scoring/deeprank/deeprank.py @@ -10,8 +10,23 @@ def deeprank_is_available() -> bool: - """Check whether the `deeprank_gnn` package is importable.""" - import deeprank_gnn # type: ignore # noqa: F401 + """Check whether deeprank-gnn-esm's requirements are met.""" + try: + import sqlite3 # noqa: F401 + except ImportError as err: + raise ImportError( + "The `deeprank` module requires a python interpreter built with " + "sqlite3 support, which is missing from your current " + "environment." + ) from err + + try: + import deeprank_gnn # type: ignore # noqa: F401 + except ImportError as err: + raise ImportError( + "The `deeprank` module requires the `deeprank_gnn` package, " + "which is not installed in your current environment." + ) from err return True diff --git a/tests/test_module_deeprank.py b/tests/test_module_deeprank.py index 105c870b3a..7c2eeabeef 100644 --- a/tests/test_module_deeprank.py +++ b/tests/test_module_deeprank.py @@ -1,12 +1,16 @@ """Tests for the deeprank scoring module wrapper.""" -import tempfile +import builtins import shutil +import tempfile from pathlib import Path import pytest -from haddock.modules.scoring.deeprank.deeprank import DeeprankWrapper +from haddock.modules.scoring.deeprank.deeprank import ( + DeeprankWrapper, + deeprank_is_available, +) from . import golden_data as GOLDEN_DATA from .conftest import has_deeprank @@ -43,6 +47,22 @@ def deeprank_wrapper_ensemble(): ) +def test_deeprank_is_available_requires_sqlite3(monkeypatch): + """Must raise a clear error when the interpreter lacks sqlite3 support.""" + real_import = builtins.__import__ + + # mock not being able to find `sqlite3` + def fake_import(name, *args, **kwargs): + if name == "sqlite3": + raise ImportError("No module named '_sqlite3'") + return real_import(name, *args, **kwargs) + + monkeypatch.setattr(builtins, "__import__", fake_import) + + with pytest.raises(ImportError, match="sqlite3"): + deeprank_is_available() + + @has_deeprank def test_run(deeprank_wrapper): """`run()` must return the score for the single input model."""