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

Add show_versions() function for printing debugging information used in issue reports #466

Merged
merged 17 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,5 @@ PASTE ERROR MESSAGE HERE

**System information**

* Operating system:
* Python installation (Anaconda, system, ETS):
* Version of GMT:
* Version of Python:
* Version of this package:
* If using conda, paste the output of `conda list` below:

<details>
<summary>output of conda list</summary>
<pre>
PASTE OUTPUT OF CONDA LIST HERE
</pre>
</details>
Please post the output of `python -c "import pygmt; pygmt.show_versions()"`:

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test:
# Run a tmp folder to make sure the tests are run on the installed version
mkdir -p $(TESTDIR)
@echo ""
@cd $(TESTDIR); python -c "import $(PROJECT); $(PROJECT).print_clib_info()"
@cd $(TESTDIR); python -c "import $(PROJECT); $(PROJECT).show_versions()"
@echo ""
cd $(TESTDIR); pytest $(PYTEST_ARGS) $(PROJECT)
cp $(TESTDIR)/.coverage* .
Expand Down
1 change: 1 addition & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Miscellaneous
which
test
print_clib_info
show_versions


.. automodule:: pygmt.datasets
Expand Down
2 changes: 1 addition & 1 deletion doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ well (be sure to have your conda env activated)::
Test your installation by running the following inside a Python interpreter::

import pygmt
pygmt.print_clib_info()
pygmt.show_versions()
pygmt.test()


Expand Down
73 changes: 71 additions & 2 deletions pygmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,82 @@ def print_clib_info():
"""
from .clib import Session

lines = ["Loaded libgmt:"]
lines = ["GMT library information:"]
with Session() as ses:
for key in sorted(ses.info):
lines.append(" {}: {}".format(key, ses.info[key]))
print("\n".join(lines))


def show_versions():
"""
Print useful debugging information for issue reports.
seisman marked this conversation as resolved.
Show resolved Hide resolved
"""
seisman marked this conversation as resolved.
Show resolved Hide resolved
import sys
import platform
import importlib
import subprocess

def _get_module_version(modname):
"""Get version information of a Python module."""
try:
if modname in sys.modules:
module = sys.modules[modname]
else:
module = importlib.import_module(modname)

try:
return module.__version__
except AttributeError:
return module.version
except ImportError:
return None


def _get_ghostscript_version():
seisman marked this conversation as resolved.
Show resolved Hide resolved
"""Check ghostscript version."""
os_name = sys.platform
if os_name.startswith("linux") or os_name == "darwin":
cmds = ["gs"]
elif os_name == "win32":
cmds = ["gswin64c.exe", "gswin32c.exe"]
else:
return None

for gs_cmd in cmds:
try:
version = subprocess.check_output(
[gs_cmd, "--version"], text=True
).strip()
return version
except FileNotFoundError:
continue
return None


sys_info = {
seisman marked this conversation as resolved.
Show resolved Hide resolved
"python": sys.version.replace("\n", " "),
"executable": sys.executable,
"machine": platform.platform(),
}

deps = ["numpy", "pandas", "xarray", "netCDF4", "packaging"]

print("PyGMT information:")
print(f" version: {__version__}")

print("System information:")
for k, v in sys_info.items():
print(f" {k}: {v}")

print("Dependency information:")
for modname in deps:
print(f" {modname}: {_get_module_version(modname)}")
print(" ghostscript:", _get_ghostscript_version())

print_clib_info()


def test(doctest=True, verbose=True, coverage=False, figures=True):
"""
Run the test suite.
Expand Down Expand Up @@ -81,7 +150,7 @@ def test(doctest=True, verbose=True, coverage=False, figures=True):
"""
import pytest

print_clib_info()
show_versions()

package = __name__

Expand Down