Skip to content

Commit

Permalink
FIX-#447: Add show_versions helper for debugging (#450)
Browse files Browse the repository at this point in the history
* initial impl for show_versions

* add matplotlib and altair versions

* Update lux/utils/debug_utils.py

Co-authored-by: Doris Lee <[email protected]>

* Update lux/utils/debug_utils.py

Co-authored-by: Doris Lee <[email protected]>

* Update lux/utils/debug_utils.py

Co-authored-by: Doris Lee <[email protected]>

* add docs + test

* add jupyter information

Co-authored-by: Doris Lee <[email protected]>
  • Loading branch information
cgarciae and dorisjlee authored Feb 7, 2022
1 parent a4781dc commit a402c49
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions lux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 52 additions & 0 deletions lux/utils/debug_utils.py
Original file line number Diff line number Diff line change
@@ -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()
20 changes: 20 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a402c49

Please sign in to comment.