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

[NF] Add get_info function #59

Merged
merged 5 commits into from Feb 28, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions fury/__init__.py
Expand Up @@ -5,8 +5,55 @@
from fury._version import get_versions

__version__ = get_versions()['version']
__revision_id__ = get_versions()['full-revisionid']
del get_versions


def get_info(verbose=False):
"""Return dict describing the context of this package.

Parameters
------------
pkg_path : str
path containing __init__.py for package
Returns
----------
context : dict
with named parameters of interest

"""
from fury.optpkg import optional_package
from os.path import dirname
import sys
import numpy
import scipy
import vtk

mpl, have_mpl, _ = optional_package('matplotlib')
dipy, have_dipy, _ = optional_package('dipy')

info = dict(fury_version=__version__,
pkg_path=dirname(__file__),
commit_hash=__revision_id__,
sys_version=sys.version,
sys_executable=sys.executable,
sys_platform=sys.platform,
numpy_version=numpy.__version__,
scipy_version=scipy.__version__,
vtk_version=vtk.vtkVersion.GetVTKVersion())

d_mpl = dict(matplotlib_version=mpl.__version__) if have_mpl else {}
d_dipy = dict(dipy_version=dipy.__version__) if have_dipy else {}

info.update(d_mpl)
info.update(d_dipy)

if verbose:
print('\n'.join(['{0}: {1}'.format(k, v) for k, v in info.items()]))

return info


# Ignore this specific warning below from vtk < 8.2.
# FutureWarning: Conversion of the second argument of issubdtype from
# `complex` to `np.complexfloating` is deprecated. In future, it will be
Expand Down
12 changes: 12 additions & 0 deletions fury/tests/test_optpkg.py
@@ -1,11 +1,23 @@
"""Function for testing optpkg module."""

import numpy.testing as npt
from fury import get_info
from fury.testing import assert_true, assert_false
from fury.optpkg import is_tripwire, TripWire, TripWireError, optional_package
from types import ModuleType


def test_get_info():
expected_keys = ['fury_version', 'pkg_path', 'commit_hash', 'sys_version',
'sys_executable', 'sys_platform', 'numpy_version',
'scipy_version', 'vtk_version']
info = get_info()
current_keys = info.keys()
for ek in expected_keys:
assert_true(ek in current_keys)
assert_true(info[ek] not in [None, ''])


def test_is_tripwire():
assert_false(is_tripwire(object()))
assert_true(is_tripwire(TripWire('some message')))
Expand Down