Skip to content

Commit 7c94386

Browse files
authored
Add lsdb.show_versions() (#1229)
* Add lsdb.show_versions() * Ignore line un-reachable under testing conditions. * Coverage pragma
1 parent 82f018f commit 7c94386

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

.github/ISSUE_TEMPLATE/1-bug_report.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ assignees: ''
1111

1212
**Environment Information**
1313

14+
<details>
15+
<summary>INSTALLED VERSIONS</summary>
16+
17+
Paste the output from `lsdb.show_versions()`
18+
19+
</details>
1420

1521
<details>
1622
<summary>Traceback</summary>
@@ -23,6 +29,6 @@ FILL IN YOUR STACK TRACE HERE
2329
Please check the following:
2430

2531
- [ ] I have described the situation in which the bug arose, including what code was executed, and any applicable data others will need to reproduce the problem.
26-
- [ ] I have included information about my environment, including the version of this package (e.g. `lsdb.__version__`)
32+
- [ ] I have included information about my environment, including the version of this package (e.g. `lsdb.show_versions()`)
2733
- [ ] I have included available evidence of the unexpected behavior (including error messages, screenshots, and/or plots) as well as a description of what I expected instead.
2834
- [ ] If I have a solution in mind, I have provided an explanation and/or pseudocode and/or task list.

src/lsdb/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .catalog import Catalog, MarginCatalog
55
from .core.crossmatch.crossmatch import crossmatch
66
from .core.search.region_search import BoxSearch, ConeSearch, PixelSearch, PolygonSearch
7+
from .io.show_versions import show_versions
78
from .loaders.dataframe.from_astropy import from_astropy
89
from .loaders.dataframe.from_dataframe import from_dataframe
910
from .loaders.hats.read_hats import open_catalog, read_hats

src/lsdb/io/show_versions.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import importlib
2+
import os
3+
import platform
4+
import struct
5+
import sys
6+
7+
8+
def _get_sys_info() -> dict[str, str]:
9+
uname_result = platform.uname()
10+
return {
11+
"python": platform.python_version(),
12+
"python-bits": str(struct.calcsize("P") * 8),
13+
"OS": uname_result.system,
14+
"OS-release": uname_result.release,
15+
"Version": uname_result.version,
16+
"machine": uname_result.machine,
17+
"processor": uname_result.processor,
18+
"byteorder": sys.byteorder,
19+
"LC_ALL": os.environ.get("LC_ALL") or "",
20+
"LANG": os.environ.get("LANG") or "",
21+
}
22+
23+
24+
def _get_dependency_info() -> dict[str, str]:
25+
deps = [
26+
"lsdb",
27+
"hats",
28+
"nested-pandas",
29+
"pandas",
30+
"numpy",
31+
"dask",
32+
"pyarrow",
33+
"fsspec",
34+
]
35+
36+
result: dict[str, str] = {}
37+
for modname in deps:
38+
try:
39+
result[modname] = importlib.metadata.version(modname)
40+
except Exception: # pylint: disable=broad-exception-caught # pragma: no cover
41+
result[modname] = "N/A"
42+
return result
43+
44+
45+
def show_versions():
46+
"""Print runtime versions and system info, useful for bug reports."""
47+
sys_info = _get_sys_info()
48+
deps = _get_dependency_info()
49+
50+
maxlen = max(len(x) for x in deps) + 1
51+
print("\n-------- SYSTEM INFO --------")
52+
for k, v in sys_info.items():
53+
print(f"{k:<{maxlen}}: {v}")
54+
print("-------- INSTALLED VERSIONS --------")
55+
for k, v in deps.items():
56+
print(f"{k:<{maxlen}}: {v}")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import lsdb
2+
3+
4+
def test_show_versions(capsys):
5+
lsdb.show_versions()
6+
captured = capsys.readouterr().out
7+
assert captured.startswith("\n-------- SYSTEM INFO --------")
8+
assert "lsdb" in captured
9+
assert "hats" in captured
10+
assert "nested-pandas" in captured
11+
assert "pyarrow" in captured
12+
assert "fsspec" in captured

0 commit comments

Comments
 (0)