Skip to content

Commit a941224

Browse files
ianhid-v-bdstansby
authored
feat: add print_debug_info function (#2913)
* feat: add function * doc: add docstring * doc: add change log for print_debug_info * Update .github/ISSUE_TEMPLATE/bug_report.yml * feat: expand debug printout + better test * feat: debug - also print out rich * test: print debug test for upstream * feat: better formatting for print_debug_info * restore original issue template --------- Co-authored-by: Davis Bennett <[email protected]> Co-authored-by: David Stansby <[email protected]>
1 parent d57fbf7 commit a941224

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

changes/2913.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added a `print_debug_info` function for bug reports.

src/zarr/__init__.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,54 @@
3737
# in case setuptools scm screw up and find version to be 0.0.0
3838
assert not __version__.startswith("0.0.0")
3939

40+
41+
def print_debug_info() -> None:
42+
"""
43+
Print version info for use in bug reports.
44+
"""
45+
import platform
46+
from importlib.metadata import version
47+
48+
def print_packages(packages: list[str]) -> None:
49+
not_installed = []
50+
for package in packages:
51+
try:
52+
print(f"{package}: {version(package)}")
53+
except ModuleNotFoundError:
54+
not_installed.append(package)
55+
if not_installed:
56+
print("\n**Not Installed:**")
57+
for package in not_installed:
58+
print(package)
59+
60+
required = [
61+
"packaging",
62+
"numpy",
63+
"numcodecs",
64+
"typing_extensions",
65+
"donfig",
66+
]
67+
optional = [
68+
"botocore",
69+
"cupy-cuda12x",
70+
"fsspec",
71+
"numcodecs",
72+
"s3fs",
73+
"gcsfs",
74+
"universal-pathlib",
75+
"rich",
76+
"obstore",
77+
]
78+
79+
print(f"platform: {platform.platform()}")
80+
print(f"python: {platform.python_version()}")
81+
print(f"zarr: {__version__}\n")
82+
print("**Required dependencies:**")
83+
print_packages(required)
84+
print("\n**Optional dependencies:**")
85+
print_packages(optional)
86+
87+
4088
__all__ = [
4189
"Array",
4290
"AsyncArray",
@@ -67,6 +115,7 @@
67115
"open_consolidated",
68116
"open_group",
69117
"open_like",
118+
"print_debug_info",
70119
"save",
71120
"save_array",
72121
"save_group",

tests/test_zarr.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
import zarr
24

35

@@ -9,3 +11,19 @@ def test_exports() -> None:
911

1012
for export in __all__:
1113
getattr(zarr, export)
14+
15+
16+
def test_print_debug_info(capsys: pytest.CaptureFixture[str]) -> None:
17+
"""
18+
Ensure that print_debug_info does not raise an error
19+
"""
20+
from importlib.metadata import version
21+
22+
from zarr import __version__, print_debug_info
23+
24+
print_debug_info()
25+
captured = capsys.readouterr()
26+
# test that at least some of what we expect is
27+
# printed out
28+
assert f"zarr: {__version__}" in captured.out
29+
assert f"numpy: {version('numpy')}" in captured.out

0 commit comments

Comments
 (0)