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

Add sharp.show_versions() function #31

Merged
merged 1 commit into from
Feb 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions sharp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@
# We are not importing the rest of sharp during the build
# process, as it may not be compiled yet
else:
# from . import utils

from ._version import __version__
from . import qoi
from . import visualization
from . import utils
from .base import ShaRP
from ._version import __version__
from .utils._show_versions import show_versions

__all__ = ["__version__", "ShaRP"]
__all__ = [
"qoi",
"visualization",
"utils",
# Non-modules:
"ShaRP",
"show_versions",
"__version__",
]
92 changes: 92 additions & 0 deletions sharp/utils/_show_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""
Utility method which prints system info to help with debugging,
and filing issues on GitHub.
Adapted from :func:`sklearn.show_versions`,
which was adapted from :func:`pandas.show_versions`
"""

from .. import __version__


def _get_deps_info():
"""Overview of the installed version of main dependencies

Returns
-------
deps_info: dict
version information on relevant Python libraries
"""
deps = [
"pip",
"setuptools",
"sharp",
"numpy",
"pandas",
"scikit-learn",
"tqdm",
"matplotlib",
"Cython",
"scipy",
"keras",
"tensorflow",
"joblib",
]

deps_info = {
"sharp": __version__,
}

from importlib.metadata import PackageNotFoundError, version

for modname in deps:
try:
deps_info[modname] = version(modname)
except PackageNotFoundError:
deps_info[modname] = None
return deps_info


def show_versions(github=False):
"""Print debugging information.

.. versionadded:: 0.4.3

Parameters
----------
github : bool,
If true, wrap system info with GitHub markup.
"""

from sklearn.utils._show_versions import _get_sys_info

_sys_info = _get_sys_info()
_deps_info = _get_deps_info()
_github_markup = (
"<details>"
"<summary>System, Dependency Information</summary>\n\n"
"**System Information**\n\n"
"{0}\n"
"**Python Dependencies**\n\n"
"{1}\n"
"</details>"
)

if github:
_sys_markup = ""
_deps_markup = ""

for k, stat in _sys_info.items():
_sys_markup += f"* {k:<16}: `{stat}`\n"
for k, stat in _deps_info.items():
_deps_markup += f"* {k:<16}: `{stat}`\n"

print(_github_markup.format(_sys_markup, _deps_markup))

else:
print("\nSystem:")
for k, stat in _sys_info.items():
print(f"{k:>16}: {stat}")

print("\nPython dependencies:")
for k, stat in _deps_info.items():
print(f"{k:>16}: {stat}")
67 changes: 67 additions & 0 deletions sharp/utils/tests/test_show_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Test for the show_versions helper. Based on the sklearn tests."""

from sharp.utils._show_versions import _get_deps_info, show_versions


def test_get_deps_info():
_deps_info = _get_deps_info()

assert "pip" in _deps_info
assert "setuptools" in _deps_info
assert "sharp" in _deps_info
assert "numpy" in _deps_info
assert "pandas" in _deps_info
assert "scikit-learn" in _deps_info
assert "matplotlib" in _deps_info
assert "tqdm" in _deps_info
assert "Cython" in _deps_info
assert "scipy" in _deps_info
assert "keras" in _deps_info
assert "tensorflow" in _deps_info
assert "joblib" in _deps_info


def test_show_versions_default(capsys):
show_versions()
out, err = capsys.readouterr()
assert "python" in out
assert "executable" in out
assert "machine" in out
assert "pip" in out
assert "setuptools" in out
assert "sharp" in out
assert "numpy" in out
assert "pandas" in out
assert "scikit-learn" in out
assert "matplotlib" in out
assert "tqdm" in out
assert "Cython" in out
assert "scipy" in out
assert "keras" in out
assert "tensorflow" in out
assert "joblib" in out


def test_show_versions_github(capsys):
show_versions(github=True)
out, err = capsys.readouterr()
assert "<details><summary>System, Dependency Information</summary>" in out
assert "**System Information**" in out
assert "* python" in out
assert "* executable" in out
assert "* machine" in out
assert "**Python Dependencies**" in out
assert "* pip" in out
assert "* setuptools" in out
assert "* sharp" in out
assert "* numpy" in out
assert "* pandas" in out
assert "* scikit-learn" in out
assert "* matplotlib" in out
assert "* tqdm" in out
assert "* Cython" in out
assert "* scipy" in out
assert "* keras" in out
assert "* tensorflow" in out
assert "* joblib" in out
assert "</details>" in out
Loading