Skip to content

Commit

Permalink
Make scooby soft dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
prisae authored Jul 3, 2019
1 parent 62a2533 commit ddfcc09
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 25 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ language: python
matrix:
include:
- python: 3.5
env: PYTHON=3.5 PCKGS="numexpr matplotlib" CHAN="defaults" TEST="--mpl" INST="pytest-mpl"
env: PYTHON=3.5 PCKGS="numexpr matplotlib" CHAN="defaults" TEST="--mpl" INST="pytest-mpl scooby"
- python: 3.6
env: PYTHON=3.6 PCKGS="numexpr matplotlib" CHAN="defaults" TEST="--mpl" INST="pytest-mpl"
env: PYTHON=3.6 PCKGS="numexpr matplotlib" CHAN="defaults" TEST="--mpl" INST="pytest-mpl scooby"
- python: 3.6 # => 3.7
env: PYTHON=3.7 PCKGS="numexpr matplotlib" CHAN="defaults" TEST="--mpl" INST="pytest-mpl"
env: PYTHON=3.7 PCKGS="numexpr matplotlib" CHAN="defaults" TEST="--mpl" INST="pytest-mpl scooby"
- python: 3.6 # => 3.6 with conda-forge
env: PYTHON=3.6 PCKGS="numexpr matplotlib" CHAN="conda-forge" TEST="--mpl" INST="pytest-mpl"
- python: 3.6 # => 3.6 with without matplotlib, numexpr
Expand All @@ -30,7 +30,7 @@ install:
# Install and activate environment, install packages
- conda create -q -n test-environment -c $CHAN python=$PYTHON numpy scipy pytest pytest-cov $PCKGS
- source activate test-environment
- pip install coveralls pytest-flake8 scooby $INST
- pip install coveralls pytest-flake8 $INST
- python setup.py install
- cp tests/matplotlibrc .

Expand Down
20 changes: 17 additions & 3 deletions empymod/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@


# Mandatory imports
import scooby
import warnings
import numpy as np
from scipy import special
from datetime import timedelta
from timeit import default_timer

# scooby is a soft dependency for empymod
try:
from scooby import Report as ScoobyReport
except ImportError:
class ScoobyReport:
def __init__(self, additional, core, optional, ncol, text_width, sort):
print("\n* WARNING :: `empymod.Report` requires `scooby`."
"\n Install it via `pip install scooby`.\n")

# Optional imports
try:
Expand Down Expand Up @@ -1977,10 +1984,10 @@ def spline_backwards_hankel(ht, htarg, opt):


# 6. Report
class Report(scooby.Report):
class Report(ScoobyReport):
r"""Print date, time, and version information.
Use scooby to print date, time, and package version information in any
Use ``scooby`` to print date, time, and package version information in any
environment (Jupyter notebook, IPython console, Python console, QT
console), either as html-table (notebook) or as plain text (anywhere).
Expand Down Expand Up @@ -2010,6 +2017,13 @@ class Report(scooby.Report):
Sort the packages when the report is shown
NOTE
----
The package ``scooby`` has to be installed in order to use ``Report``:
``pip install scooby``.
Examples
--------
>>> import pytest
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ numpydoc >= 0.9
# scipy 0.19.0 has a memory leak in quad
# github.com/scipy/scipy/pull/7216
scipy != 0.19.0

scooby >= 0.3.0
4 changes: 2 additions & 2 deletions runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PCKGS="numpy scipy pytest pytest-cov"
NMXPR="numexpr matplotlib IPython"
STR2="** WITH numexpr/matplotlib/IPython "
PROPS="--mpl --flake8"
INST="pytest-flake8 pytest-mpl"
INST="pytest-flake8 pytest-mpl scooby"
SD="_soft-dep"
WARN=""

Expand Down Expand Up @@ -94,7 +94,7 @@ for i in ${PYTHON3VERSION[@]}; do

# Install flake8
if [ ! -d "$HOME/anaconda3/envs"+$NAME ]; then
pip install scooby $INST &> $PRINT
pip install $INST &> $PRINT
fi

# Run tests
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@
install_requires=[
'numpy',
'scipy!=0.19.0',
'scooby>=0.3.0'
],
)
39 changes: 26 additions & 13 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import scooby
import pytest
import numpy as np
from numpy.testing import assert_allclose
Expand All @@ -10,6 +9,12 @@
use_vml = False
use_ne_eval = False

# Optional import
try:
import scooby
except ImportError:
scooby = False

from empymod import utils, filters


Expand Down Expand Up @@ -1035,23 +1040,31 @@ def test_spline_backwards_hankel():


def test_report(capsys):
out, _ = capsys.readouterr() # Empty capsys

# Reporting is now done by the external package scooby.
# We just ensure the shown packages do not change (core and optional).
out1 = utils.Report()
out2 = scooby.Report(
core=['numpy', 'scipy', 'empymod'],
optional=['numexpr', 'IPython', 'matplotlib'],
ncol=3)
if scooby:
out1 = utils.Report()
out2 = scooby.Report(
core=['numpy', 'scipy', 'empymod'],
optional=['numexpr', 'IPython', 'matplotlib'],
ncol=3)

# Ensure they're the same; exclude time to avoid errors.
assert out1.__repr__()[115:] == out2.__repr__()[115:]

# Ensure they're the same; exclude time to avoid errors.
assert out1.__repr__()[115:] == out2.__repr__()[115:]
else: # soft dependency
_ = utils.Report()
out, _ = capsys.readouterr() # Empty capsys
assert 'WARNING :: `empymod.Report` requires `scooby`' in out


def test_versions_backwards():
out1 = utils.Report()
out2 = utils.Versions()
out3 = utils.versions()
if scooby:
out1 = utils.Report()
out2 = utils.Versions()
out3 = utils.versions()

assert out1.__repr__() == out2.__repr__()
assert out1.__repr__() == out3.__repr__()
assert out1.__repr__() == out2.__repr__()
assert out1.__repr__() == out3.__repr__()

0 comments on commit ddfcc09

Please sign in to comment.