Skip to content

Commit

Permalink
ENH: emit warning if SciPy is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Feb 11, 2024
1 parent df08529 commit dbb7ba4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ name = "ampform"
requires-python = ">=3.7"

[project.optional-dependencies]
all = ["ampform[viz]"]
all = [
"ampform[scipy]",
"ampform[viz]",
]
dev = [
"ampform[all]",
"ampform[doc]",
Expand All @@ -62,7 +65,7 @@ dev = [
]
doc = [
"Sphinx >=3",
"ampform[viz]",
"ampform[all]",
"black",
"ipympl",
"matplotlib",
Expand Down Expand Up @@ -102,13 +105,15 @@ mypy = [
"mypy >=0.730",
"sphinx-api-relink >=0.0.3",
]
scipy = ["scipy"]
sty = [
"ampform[format]",
"ampform[lint]",
"ampform[test]", # for pytest type hints
"pre-commit >=1.4.0",
]
test = [
"ampform[scipy]",
"black",
"ipywidgets", # symplot
"nbmake",
Expand All @@ -117,7 +122,6 @@ test = [
"pytest-cov",
"pytest-profiling",
"pytest-xdist",
"scipy",
]
viz = ["graphviz"]

Expand Down Expand Up @@ -185,6 +189,10 @@ warn_unused_configs = true
ignore_missing_imports = true
module = ["graphviz.*"]

[[tool.mypy.overrides]]
ignore_missing_imports = true
module = ["scipy.*"]

[[tool.mypy.overrides]]
ignore_missing_imports = true
module = ["ipywidgets.*"]
Expand Down
13 changes: 13 additions & 0 deletions src/ampform/sympy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import pickle
import re
import warnings
from abc import abstractmethod
from os.path import abspath, dirname, expanduser
from textwrap import dedent
Expand Down Expand Up @@ -364,6 +365,7 @@ def doit(self, **hints):
return self.func(*args)

Check warning on line 365 in src/ampform/sympy/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/sympy/__init__.py#L365

Added line #L365 was not covered by tests

def _numpycode(self, printer, *args):
_warn_if_scipy_not_installed()
integration_vars, limits = _unpack_integral_limits(self)
if len(limits) != 1 or len(integration_vars) != 1:
msg = f"Cannot handle {len(limits)}-dimensional integrals"
Expand All @@ -383,3 +385,14 @@ def _numpycode(self, printer, *args):
f" epsabs={self.abs_tolerance}, epsrel={self.abs_tolerance},"
f" limit={self.limit})[0]"
)


def _warn_if_scipy_not_installed() -> None:
try:
import scipy # noqa: F401 # pyright: ignore[reportUnusedImport, reportMissingImports]
except ImportError:
warnings.warn(

Check warning on line 394 in src/ampform/sympy/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/sympy/__init__.py#L393-L394

Added lines #L393 - L394 were not covered by tests
"Scipy is not installed. Install with 'pip install scipy' or with 'pip"
" install ampform[scipy]'",
stacklevel=1,
)

0 comments on commit dbb7ba4

Please sign in to comment.