Skip to content

Commit

Permalink
Merge pull request #2110 from gadhvirushiraj/rushiDev
Browse files Browse the repository at this point in the history
Fix version_table to work without Cython installed
  • Loading branch information
hodgestar committed Mar 11, 2023
2 parents 40ff8e1 + a5fdd1f commit ae6d693
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/changes/2110.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
qutip.ipynbtools.version_table() can now be called without Cython installed
10 changes: 8 additions & 2 deletions qutip/ipynbtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@
import qutip
import numpy
import scipy
import Cython
import matplotlib
import IPython

try:
import Cython
_cython_available = True
except ImportError:
_cython_available = False


def version_table(verbose=False):
"""
Expand All @@ -67,13 +72,14 @@ def version_table(verbose=False):
("Numpy", numpy.__version__),
("SciPy", scipy.__version__),
("matplotlib", matplotlib.__version__),
("Cython", Cython.__version__),
("Number of CPUs", available_cpu_count()),
("BLAS Info", _blas_info()),
("IPython", IPython.__version__),
("Python", sys.version),
("OS", "%s [%s]" % (os.name, sys.platform))
]
if _cython_available:
packages.append(("Cython", Cython.__version__))

for name, version in packages:
html += "<tr><td>%s</td><td>%s</td></tr>" % (name, version)
Expand Down
24 changes: 24 additions & 0 deletions qutip/tests/test_ipynbtools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from qutip.ipynbtools import version_table
import pytest


@pytest.mark.parametrize('verbose', [False, True])
def test_version_table(verbose):
html_data = version_table(verbose=verbose).data
assert "<th>Software</th>" in html_data
assert "<th>Version</th>" in html_data
assert "<td>QuTiP</td>" in html_data
assert "<td>Numpy</td>" in html_data
assert "<td>SciPy</td>" in html_data
assert "<td>matplotlib</td>" in html_data
assert "<td>IPython</td>" in html_data
if verbose:
assert "<td>Installation path</td>" in html_data
if pytest.importorskip("getpass") is not None:
assert "<td>User</td>" in html_data


@pytest.mark.skipif(not pytest.importorskip("Cython"), reason="cython not installed")
def test_version_table_with_cython():
html_data = version_table().data
assert "<td>Cython</td>" in html_data

0 comments on commit ae6d693

Please sign in to comment.