1
1
"""
2
- Utility methods to print system info for debugging.
2
+ Utility methods to print system information for debugging.
3
3
4
4
Adapted from :func:`rioxarray.show_versions` and :func:`pandas.show_versions`.
5
5
"""
6
6
7
- import importlib
8
7
import platform
9
8
import shutil
10
9
import subprocess
11
10
import sys
12
- from importlib .metadata import version
11
+ from importlib .metadata import PackageNotFoundError , requires , version
13
12
from typing import TextIO
14
13
15
14
from packaging .requirements import Requirement
@@ -25,25 +24,17 @@ def _get_clib_info() -> dict[str, str]:
25
24
"""
26
25
Get information about the GMT shared library.
27
26
"""
28
- with Session () as ses :
29
- return ses .info
27
+ with Session () as lib :
28
+ return lib .info
30
29
31
30
32
31
def _get_module_version (modname : str ) -> str | None :
33
32
"""
34
33
Get version information of a Python module.
35
34
"""
36
35
try :
37
- if modname in sys .modules :
38
- module = sys .modules [modname ]
39
- else :
40
- module = importlib .import_module (modname )
41
-
42
- try :
43
- return module .__version__
44
- except AttributeError :
45
- return module .version
46
- except ImportError :
36
+ return version (modname )
37
+ except PackageNotFoundError :
47
38
return None
48
39
49
40
@@ -85,13 +76,12 @@ def _check_ghostscript_version(gs_version: str | None) -> str | None:
85
76
f"Ghostscript v{ gs_version } has known bugs. "
86
77
"Please consider upgrading to version v10.02 or later."
87
78
)
88
- case v if v >= Version ("10.02" ):
89
- if Version (__gmt_version__ ) < Version ("6.5.0" ):
90
- return (
91
- f"GMT v{ __gmt_version__ } doesn't support Ghostscript "
92
- f"v{ gs_version } . Please consider upgrading to GMT>=6.5.0 or "
93
- "downgrading to Ghostscript v9.56."
94
- )
79
+ case v if v >= Version ("10.02" ) and Version (__gmt_version__ ) < Version ("6.5.0" ):
80
+ return (
81
+ f"GMT v{ __gmt_version__ } doesn't support Ghostscript v{ gs_version } . "
82
+ "Please consider upgrading to GMT>=6.5.0 or downgrading to Ghostscript "
83
+ "v9.56."
84
+ )
95
85
return None
96
86
97
87
@@ -109,22 +99,14 @@ def show_versions(file: TextIO | None = sys.stdout):
109
99
It also warns users if the installed Ghostscript version has serious bugs or is
110
100
incompatible with the installed GMT version.
111
101
"""
112
-
113
102
sys_info = {
114
103
"python" : sys .version .replace ("\n " , " " ),
115
104
"executable" : sys .executable ,
116
105
"machine" : platform .platform (),
117
106
}
118
- dep_info = {
119
- Requirement (v ).name : _get_module_version (Requirement (v ).name )
120
- for v in importlib .metadata .requires ("pygmt" ) # type: ignore[union-attr]
121
- }
122
- dep_info .update (
123
- {
124
- "gdal" : _get_module_version ("osgeo.gdal" ),
125
- "ghostscript" : _get_ghostscript_version (),
126
- }
127
- )
107
+ requirements = [Requirement (v ).name for v in requires ("pygmt" )] + ["gdal" ] # type: ignore[union-attr]
108
+ dep_info = {name : _get_module_version (name ) for name in requirements }
109
+ dep_info .update ({"ghostscript" : _get_ghostscript_version ()})
128
110
129
111
lines = []
130
112
lines .append ("PyGMT information:" )
0 commit comments