Skip to content

Commit

Permalink
feat: Add a convenient way of outputting system and dependency versio…
Browse files Browse the repository at this point in the history
…ns (#425)
  • Loading branch information
tuscland committed Oct 2, 2024
1 parent 4ca60a6 commit 7d0ad05
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/skore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""Provide the Store class for managing information in a data science project."""
"""Configure logging and global settings."""

import logging

import rich.logging

from skore.project import Project, load

from .utils._show_versions import show_versions

__all__ = [
"load",
"show_versions",
"Project",
]

Expand Down
1 change: 1 addition & 0 deletions src/skore/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Various utilities to help with development."""
84 changes: 84 additions & 0 deletions src/skore/utils/_show_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
Utility methods to print system info for debugging.
adapted from :func:`sklearn.show_versions`
"""

import platform
import sys


def _get_sys_info():
"""System information.
Returns
-------
sys_info : dict
system and Python version information
"""
python = sys.version.replace("\n", " ")

blob = [
("python", python),
("executable", sys.executable),
("machine", platform.platform()),
]

return dict(blob)


def _get_deps_info():
"""Overview of the installed version of main dependencies.
This function does not import the modules to collect the version numbers
but instead relies on standard Python package metadata.
Returns
-------
deps_info: dict
version information on relevant Python libraries
"""
deps = [
"pip",
"setuptools",
"diskcache",
"fastapi",
"rich",
"skops",
"uvicorn",
]

from importlib.metadata import PackageNotFoundError, version

deps_info = {
"skore": version("skore"),
}

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


def show_versions():
"""Print useful debugging information.
Examples
--------
>>> from skore import show_versions
>>> show_versions()
"""
sys_info = _get_sys_info()
deps_info = _get_deps_info()

print("\nSystem:") # noqa: T201
for k, stat in sys_info.items():
print(f"{k:>10}: {stat}") # noqa: T201

print("\nPython dependencies:") # noqa: T201
for k, stat in deps_info.items():
print(f"{k:>13}: {stat}") # noqa: T201

0 comments on commit 7d0ad05

Please sign in to comment.