Skip to content

Commit

Permalink
Test Keras is present (#374)
Browse files Browse the repository at this point in the history
* check if Keras present

* change TF to Keras in CI

* remove comment

* change dependencies in pyproject.toml for Keras 3.0
  • Loading branch information
sfmig committed Feb 7, 2024
1 parent 3046294 commit 99cbda0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test_include_guard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
import cellfinder.core
import cellfinder.napari
- name: Uninstall tensorflow
run: python -m pip uninstall -y tensorflow
- name: Uninstall keras
run: python -m pip uninstall -y keras

- name: Test (broken) import
id: broken_import
Expand Down
19 changes: 8 additions & 11 deletions cellfinder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
except PackageNotFoundError as e:
raise PackageNotFoundError("cellfinder package not installed") from e

# If tensorflow is not present, tools cannot be used.
# If Keras is not present with a backend, tools cannot be used.
# Throw an error in this case to prevent invocation of functions.
try:
TF_VERSION = version("tensorflow")
KERAS_VERSION = version("keras")
except PackageNotFoundError as e:
try:
TF_VERSION = version("tensorflow-macos")
except PackageNotFoundError as e:
raise PackageNotFoundError(
f"cellfinder tools cannot be invoked without tensorflow. "
f"Please install tensorflow into your environment to use cellfinder tools. "
f"For more information, please see "
f"https://github.com/brainglobe/brainglobe-meta#readme."
) from e
raise PackageNotFoundError(
f"cellfinder tools cannot be invoked without Keras. "
f"Please install tensorflow into your environment to use cellfinder tools. "
f"For more information, please see "
f"https://github.com/brainglobe/brainglobe-meta#readme."
) from e

__author__ = "Adam Tyson, Christian Niedworok, Charly Rousseau"
__license__ = "BSD-3-Clause"
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ dependencies = [
"numpy",
"scikit-image",
"scikit-learn",
# See https://github.com/brainglobe/cellfinder-core/issues/103 for < 2.12.0 pin
"tensorflow-macos>=2.5.0,<2.12.0; platform_system=='Darwin' and platform_machine=='arm64'",
"tensorflow>=2.5.0,<2.12.0; platform_system!='Darwin' or platform_machine!='arm64'",
"keras",
"tf-nightly==2.16.0.dev20240101", # pinning to same TF as Keras 3.0
"tifffile",
"tqdm",
]
Expand Down

0 comments on commit 99cbda0

Please sign in to comment.