-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a convenient way of outputting system and dependency versio…
…ns (#425)
- Loading branch information
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Various utilities to help with development.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |