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 342cf6b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/skore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
"""Provide the Store class for managing information in a data science project."""
"""Configure logging and global settings."""

import logging

import rich.logging

# Temporary, pending resolution of #424
__version__ = "0.0.1"

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."""
86 changes: 86 additions & 0 deletions src/skore/utils/_show_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""
Utility methods to print system info for debugging.
adapted from :func:`sklearn.show_versions`
"""

import platform
import sys

from .. import __version__


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",
]

deps_info = {
"skore": __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():
"""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 342cf6b

Please sign in to comment.