From a7f3946e454a72380f687cda58731dc1998e1fa6 Mon Sep 17 00:00:00 2001 From: Robin De Schepper Date: Tue, 31 Oct 2023 11:51:36 +0100 Subject: [PATCH] shield bsb-arbor with a mocked import --- bsb/simulators/arbor/__init__.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bsb/simulators/arbor/__init__.py b/bsb/simulators/arbor/__init__.py index 5985a4034..6afd91387 100644 --- a/bsb/simulators/arbor/__init__.py +++ b/bsb/simulators/arbor/__init__.py @@ -1,3 +1,26 @@ +import types + +# fixme: Once this adapter is moved to bsb-arbor, arbor can be a hard dependency at import +# time, and this code can be removed. +try: + import arbor +except ImportError as e: + import sys + from bsb.reporting import warn + + errmsg = f"Can't use bsb-arbor: Arbor is not importable: {e}" + warn(errmsg) + + class ArborMock(types.ModuleType): + class recipe: + def __getattr__(self, item): + raise AttributeError(errmsg) + + def __getattr__(self, item): + raise AttributeError(errmsg) + + sys.modules["arbor"] = ArborMock(name="arbor") + from bsb.simulation import SimulationBackendPlugin from .simulation import ArborSimulation from .adapter import ArborAdapter