From a402c493bed13c85076438f53010acaf107bd75f Mon Sep 17 00:00:00 2001 From: Cristian Garcia Date: Mon, 7 Feb 2022 15:10:03 -0500 Subject: [PATCH] FIX-#447: Add show_versions helper for debugging (#450) * initial impl for show_versions * add matplotlib and altair versions * Update lux/utils/debug_utils.py Co-authored-by: Doris Lee * Update lux/utils/debug_utils.py Co-authored-by: Doris Lee * Update lux/utils/debug_utils.py Co-authored-by: Doris Lee * add docs + test * add jupyter information Co-authored-by: Doris Lee --- lux/__init__.py | 1 + lux/utils/debug_utils.py | 52 ++++++++++++++++++++++++++++++++++++++++ tests/test_utils.py | 20 ++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 lux/utils/debug_utils.py create mode 100644 tests/test_utils.py diff --git a/lux/__init__.py b/lux/__init__.py index aef0cc87..4e8599f1 100644 --- a/lux/__init__.py +++ b/lux/__init__.py @@ -21,6 +21,7 @@ from ._version import __version__, version_info from lux._config import config from lux._config.config import warning_format +from lux.utils.debug_utils import show_versions from lux._config import Config diff --git a/lux/utils/debug_utils.py b/lux/utils/debug_utils.py new file mode 100644 index 00000000..2b280cda --- /dev/null +++ b/lux/utils/debug_utils.py @@ -0,0 +1,52 @@ +import re +import subprocess +from typing import Optional + + +def show_versions(return_string: bool = False) -> Optional[str]: + """ + Prints the versions of the principal packages used by Lux for debugging purposes. + + Parameters + ---------- + return_string: Whether to return the versions as a string or print them. + + Returns + ------- + If return_string is True, returns a string with the versions else the versions + are printed and None is returned. + """ + import platform + + import altair + import lux + import luxwidget + import matplotlib + import pandas as pd + + jupyter_versions_str = subprocess.check_output(["jupyter", "--version"]) + jupyter_versions = re.findall(r"(\S+)\s+: (.+)\S*", jupyter_versions_str.decode("utf-8")) + + df = pd.DataFrame( + [ + ("python", platform.python_version()), + ("lux", lux.__version__), + ("pandas", pd.__version__), + ("luxwidget", luxwidget.__version__), + ("matplotlib", matplotlib.__version__), + ("altair", altair.__version__), + ] + + jupyter_versions, + columns=["", "Version"], + ) + + str_rep = df.to_string(index=False, justify="left") + + if return_string: + return str_rep + else: + print(str_rep) + + +if __name__ == "__main__": + show_versions() diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 00000000..70423214 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,20 @@ +import lux + + +class TestDebugUtils: + def test_show_info(self): + + versions = lux.show_versions(return_string=True) + + assert versions is not None + + assert "python" in versions + assert "lux" in versions + assert "pandas" in versions + assert "luxwidget" in versions + assert "matplotlib" in versions + assert "altair" in versions + + +if __name__ == "__main__": + TestDebugUtils().test_show_info()