Skip to content

Commit

Permalink
Packages not on conda-forge are now optional dependencies (#11)
Browse files Browse the repository at this point in the history
* Make morphapi and cellfinder optional, adjust tests

* Add optional dependencies to readme

* Tidy up submdule presence tests

* Revert "Tidy up submdule presence tests"

This reverts commit 43a95dd.

* Adjust tests to make mypy happy

* pass is not a test, but import module is
  • Loading branch information
willGraham01 authored Jun 21, 2023
1 parent c02e162 commit d17b34b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion brainglobe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -50,6 +48,12 @@ dev = [
"ruff",
"setuptools_scm",
]
morphapi = [
"morphapi>=0.1.3.0"
]
cellfinder = [
"cellfinder"
]

[build-system]
requires = [
Expand Down
22 changes: 21 additions & 1 deletion tests/test_unit/test_tool_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"brainreg",
"brainreg_segment",
"cellfinder_core",
"morphapi",
]
OPTIONAL_TOOLS = ["morphapi", "cellfinder"]


def test_tool_exposure() -> None:
Expand All @@ -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"

0 comments on commit d17b34b

Please sign in to comment.