Skip to content

feat: add print_debug_info function #2913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 16, 2025
Merged
44 changes: 14 additions & 30 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,20 @@ body:
attributes:
value: |
Please provide the following information.
- type: input
id: Zarr-version
attributes:
label: Zarr version
description: Value of ``zarr.__version__``
placeholder: v2.10.2, v2.11.3, v2.12.0, etc.
validations:
required: true
- type: input
id: Numcodecs-version
attributes:
label: Numcodecs version
description: Value of ``numcodecs.__version__``
placeholder: v0.8.1, v0.9.0, v0.10.0, etc.
validations:
required: true
- type: input
id: Python-version
attributes:
label: Python Version
description: Version of Python interpreter
placeholder: 3.10, 3.11, 3.12 etc.
validations:
required: true
- type: input
id: OS
attributes:
label: Operating System
description: Operating System
placeholder: (Linux/Windows/Mac)
- type: textarea
id: version-info
attributes:
label: Versions
description: Output of ``zarr.print_debug_info()``
placeholder: |
platform: macOS-15.3-arm64-arm-64bit-Mach-O
python: 3.13.2

zarr: 3.0.5

numcodecs: 0.15.1
numpy: 2.2.3
fsspec: 2025.3.0
validations:
required: true
- type: input
Expand Down
1 change: 1 addition & 0 deletions changes/2913.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a `print_debug_info` function for bug reports.
20 changes: 20 additions & 0 deletions src/zarr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
# in case setuptools scm screw up and find version to be 0.0.0
assert not __version__.startswith("0.0.0")


def print_debug_info() -> None:
"""
Print version info for use in bug reports.
"""
import platform
from importlib import import_module

Check warning on line 45 in src/zarr/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/__init__.py#L44-L45

Added lines #L44 - L45 were not covered by tests

print(f"platform: {platform.platform()}")
print(f"python: {platform.python_version()}\n")

Check warning on line 48 in src/zarr/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/__init__.py#L47-L48

Added lines #L47 - L48 were not covered by tests

print(f"zarr: {__version__}\n")
for package in ["numcodecs", "numpy", "fsspec", "s3fs", "botocore", "gcsfs"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we include the full list of required and optional dependencies here?

Required dependencies: donfig | numcodecs | numpy | packaging | typing-extensions
Optional dependencies: botocore | cupy-cuda12x | fsspec| numcodecs | rich | s3fs | universal-pathlib | obstore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added all of them. They're in a list because introspecting the package to grab it's own dependencies seemed to add a bit of unnecessary complication

try:
print(f"{package}: {import_module(package).__version__}")
except ModuleNotFoundError:
continue

Check warning on line 55 in src/zarr/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/__init__.py#L50-L55

Added lines #L50 - L55 were not covered by tests


__all__ = [
"Array",
"AsyncArray",
Expand Down Expand Up @@ -65,6 +84,7 @@
"open_consolidated",
"open_group",
"open_like",
"print_debug_info",
"save",
"save_array",
"save_group",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ def test_exports() -> None:

for export in __all__:
getattr(zarr, export)


def test_print_debug_info() -> None:
"""
Ensure that print_debug_info does not raise an error
"""
from zarr import print_debug_info

print_debug_info()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make this test a bit more meaningful, let's capture the output and assert that it matches our basic expectations. https://docs.pytest.org/en/stable/how-to/capture-stdout-stderr.html#accessing-captured-output-from-a-test-function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested two outputs that should always be there. I didn't test every output because at some point that just becomes rewriting the fucntion