File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ Added a `print_debug_info ` function for bug reports.
Original file line number Diff line number Diff line change 3737# in case setuptools scm screw up and find version to be 0.0.0
3838assert 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" ,
67115 "open_consolidated" ,
68116 "open_group" ,
69117 "open_like" ,
118+ "print_debug_info" ,
70119 "save" ,
71120 "save_array" ,
72121 "save_group" ,
Original file line number Diff line number Diff line change 1+ import pytest
2+
13import 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
You can’t perform that action at this time.
0 commit comments