Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packages not on conda-forge are now optional dependencies #11

Merged
merged 6 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"