Repository: joaopfonseca/ml-research (language: python)

Issue:
Add ``mlresearch.show_versions()`` functions for bug reports
See ``scikit-learn`` and ``imbalanced-learn`` for reference.

**Note:** Update CONTRIBUTING.md accordingly


Discussion / hints:

Fix patch:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 15587b7..c1e2fbe 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -136,14 +136,8 @@ following rules before submitting:
    can be found by runnning the following code snippet:
 
    ```python
-   import platform; print(platform.platform())
-   import sys; print("Python", sys.version)
-   import numpy; print("NumPy", numpy.__version__)
-   import pandas; print("Pandas", pandas.__version__)
-   import scipy; print("SciPy", scipy.__version__)
-   import sklearn; print("Scikit-Learn", sklearn.__version__)
-   import imblearn; print("Imbalanced-Learn", imblearn.__version__)
-   import mlresearch; print("ML-Research", mlresearch.__version__)
+   from mlresearch
+   mlresearch.show_versions(github=True)
    ```
 
 -  Please be specific about what estimators and/or functions are involved
diff --git a/mlresearch/utils/_show_versions.py b/mlresearch/utils/_show_versions.py
new file mode 100644
index 0000000..b1e4369
--- /dev/null
+++ b/mlresearch/utils/_show_versions.py
@@ -0,0 +1,93 @@
+"""
+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",
+        "ml-research",
+        "numpy",
+        "pandas",
+        "scikit-learn",
+        "imbalanced-learn",
+        "matplotlib",
+        "tqdm",
+        "Cython",
+        "scipy",
+        "keras",
+        "tensorflow",
+        "joblib",
+    ]
+
+    deps_info = {
+        "ml-research": __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}")


Test patch:
diff --git a/mlresearch/utils/tests/test_show_versions.py b/mlresearch/utils/tests/test_show_versions.py
new file mode 100644
index 0000000..dc178b4
--- /dev/null
+++ b/mlresearch/utils/tests/test_show_versions.py
@@ -0,0 +1,70 @@
+"""Test for the show_versions helper. Based on the sklearn tests."""
+
+from mlresearch.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 "ml-research" in _deps_info
+    assert "numpy" in _deps_info
+    assert "pandas" in _deps_info
+    assert "scikit-learn" in _deps_info
+    assert "imbalanced-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 "ml-research" in out
+    assert "numpy" in out
+    assert "pandas" in out
+    assert "scikit-learn" in out
+    assert "imbalanced-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 "* ml-research" in out
+    assert "* numpy" in out
+    assert "* pandas" in out
+    assert "* scikit-learn" in out
+    assert "* imbalanced-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