diff --git a/README.md b/README.md index dabd93b..37f855c 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,17 @@ The BrainGlobe project is only possible due to grant funding and the generous su ## Installation The `brainglobe` package can be installed from [PyPI](https://pypi.org/project/brainglobe/) into a Python environment by running -```python +```sh pip install brainglobe ``` + +If you want to install the additional packages `morphapi` and `cellfinder`, you can specify them as optional dependencies: +```sh +pip install brainglobe[morphapi] # Include morphapi +pip install brainglobe[cellfinder] # Include cellfinder +pip install brainglobe[morphapi,cellfinder] # Include both morphapi and cellfinder +``` + Alternatively, you can download the source from [PyPI here](https://pypi.org/project/brainglobe/#files). ## Contributing diff --git a/brainglobe/__init__.py b/brainglobe/__init__.py index 4857f87..ea6872f 100644 --- a/brainglobe/__init__.py +++ b/brainglobe/__init__.py @@ -12,4 +12,18 @@ import brainreg import brainreg_segment import cellfinder_core -import morphapi + +# Determine if optional dependencies were installed, +# and expose if necessary. +# morphapi +_MORPHAPI_INSTALLED = True +try: + import morphapi +except ImportError: + _MORPHAPI_INSTALLED = False +# cellfinder - not exposed, but still check +_CELLFINDER_INSTALLED = True +try: + import cellfinder +except ImportError: + _CELLFINDER_INSTALLED = False diff --git a/pyproject.toml b/pyproject.toml index e6724a7..3fbacc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,12 +30,10 @@ dependencies = [ # "bg-atlasgen", [WIP] # "brainglobe-napari", [WIP] "brainglobe-napari-io", - "morphapi>=0.1.3.0", "cellfinder-napari", "brainreg-segment>=0.0.2", "brainreg", - "brainreg-napari", - "cellfinder" + "brainreg-napari" ] [project.optional-dependencies] @@ -50,6 +48,12 @@ dev = [ "ruff", "setuptools_scm", ] +morphapi = [ + "morphapi>=0.1.3.0" +] +cellfinder = [ + "cellfinder" +] [build-system] requires = [ diff --git a/tests/test_unit/test_tool_exposure.py b/tests/test_unit/test_tool_exposure.py index d1d1895..3d70ccb 100644 --- a/tests/test_unit/test_tool_exposure.py +++ b/tests/test_unit/test_tool_exposure.py @@ -9,8 +9,8 @@ "brainreg", "brainreg_segment", "cellfinder_core", - "morphapi", ] +OPTIONAL_TOOLS = ["morphapi", "cellfinder"] def test_tool_exposure() -> None: @@ -23,3 +23,23 @@ def test_tool_exposure() -> None: assert inspect.ismodule( getattr(bg, exposed_tool) ), f"brainglobe.{exposed_tool} is not a submodule" + + # Determine if optional dependencies were installed, + # and exposed if necessary + + # morphapi - should be exposed if installed + if bg._MORPHAPI_INSTALLED: + assert hasattr( + bg, "morphapi" + ), "morphapi is installed but not exposed." + assert inspect.ismodule( + bg.morphapi + ), "brainglobe.morphapi is not a module" + else: + assert not hasattr(bg, "morphapi") + + # cellfinder - should not be exposed if installed + if bg._CELLFINDER_INSTALLED: + assert not hasattr( + bg, "cellfinder" + ), "brainglobe.cellfinder is exposed"