Skip to content
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

MNT: add astropy.system_info report helper function #16335

Merged
merged 7 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 20 additions & 16 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,29 @@ body:
- type: textarea
attributes:
label: Versions
description: Version of relevant packages.
description: Please run the following script and paste the output
value: |
```python
import platform; print(platform.platform())
import sys; print("Python", sys.version)
import astropy; print("astropy", astropy.__version__)
import numpy; print("Numpy", numpy.__version__)
import erfa; print("pyerfa", erfa.__version__)
import astropy
try:
import scipy
print("Scipy", scipy.__version__)
except ImportError:
print("Scipy not installed")
try:
import matplotlib
print("Matplotlib", matplotlib.__version__)
except ImportError:
print("Matplotlib not installed")
astropy.system_info()
except AttributeError:
import platform; print(platform.platform())
import sys; print("Python", sys.version)
import astropy; print("astropy", astropy.__version__)
import numpy; print("Numpy", numpy.__version__)
import erfa; print("pyerfa", erfa.__version__)
try:
import scipy
print("Scipy", scipy.__version__)
except ImportError:
print("Scipy not installed")
try:
import matplotlib
print("Matplotlib", matplotlib.__version__)
except ImportError:
print("Matplotlib not installed")
```
```
# Copy the result here
# Paste the result here
```
3 changes: 3 additions & 0 deletions astropy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import sys
from pathlib import Path

from astropy.utils.system_info import system_info

from .version import version as __version__

# The location of the online documentation for astropy
Expand Down Expand Up @@ -208,6 +210,7 @@ def online_help(query):
"conf",
"physical_constants",
"astronomical_constants",
"system_info",
]


Expand Down
86 changes: 86 additions & 0 deletions astropy/utils/system_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
r"""
A helper script to automate system info in bug reports.

This can be run as::

python -c "import astropy; astropy.system_info()"

(note that the interpreter might be called python3 instead of python, depending
on your system's details)

This script should not require anything else than the standard library and is
subject to change without notice.
"""

__all__ = ["system_info"]

Check warning on line 15 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L15

Added line #L15 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

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

Defining __all__ makes this module look public, so there should be an explicit warning in the module docstring that the contents here are subject to change without notice.


import platform
from importlib.metadata import version
from importlib.util import find_spec

Check warning on line 19 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L17-L19

Added lines #L17 - L19 were not covered by tests


def _header(name: str) -> list[str]:
return [name, "-" * len(name)]

Check warning on line 23 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L22-L23

Added lines #L22 - L23 were not covered by tests


def _report_platform() -> list[str]:
return [

Check warning on line 27 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L26-L27

Added lines #L26 - L27 were not covered by tests
f"{platform.platform() = }",
f"{platform.version() = }",
f"{platform.python_version() = }",
]


def _report_packages() -> list[str]:
pkgs = [

Check warning on line 35 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L34-L35

Added lines #L34 - L35 were not covered by tests
"astropy",
"numpy",
"scipy",
"matplotlib",
"pandas",
]
lines = [f"{p:<20} {'--' if find_spec(p) is None else version(p)}" for p in pkgs]

Check warning on line 42 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L42

Added line #L42 was not covered by tests

# pyerfa may not export its package metadata (as of 2.0.1.4)
try:
import erfa

Check warning on line 46 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L45-L46

Added lines #L45 - L46 were not covered by tests
except ImportError:
v = "--"
else:
v = erfa.__version__
p = "pyerfa"
lines.append(f"{p:<20} {v}")
return lines

Check warning on line 53 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L50-L53

Added lines #L50 - L53 were not covered by tests


def system_info() -> None:

Check warning on line 56 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L56

Added line #L56 was not covered by tests
"""Print relevant system information for astropy bug reports.

Examples
--------
>>> import astropy
>>> astropy.system_info() # doctest: +ELLIPSIS
platform
--------
platform.platform() = ...
platform.version() = ...
platform.python_version() = ...
<BLANKLINE>
packages
--------
astropy ...
numpy ...
scipy ...
matplotlib ...
pandas ...
pyerfa ...

"""
report_lines = (

Check warning on line 79 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L79

Added line #L79 was not covered by tests
*_header("platform"),
*_report_platform(),
"",
*_header("packages"),
*_report_packages(),
)
print("\n".join(report_lines))

Check warning on line 86 in astropy/utils/system_info.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/system_info.py#L86

Added line #L86 was not covered by tests
2 changes: 2 additions & 0 deletions docs/changes/utils/16335.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added the ``astropy.system_info`` function to help document runtime systems in
bug reports.
2 changes: 2 additions & 0 deletions docs/utils/ref_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Utility Functions/Classes
.. automodapi:: astropy.utils.shapes
:no-inheritance-diagram:

.. automodapi:: astropy.utils.system_info
:no-inheritance-diagram:

File Downloads
==============
Expand Down