@@ -96,18 +96,6 @@ def _check_ghostscript_version(gs_version: str) -> str | None:
96
96
return None
97
97
98
98
99
- def _get_gdal_version ():
100
- """
101
- Get GDAL version.
102
- """
103
- try :
104
- from osgeo import gdal
105
-
106
- return gdal .__version__
107
- except ImportError :
108
- return None
109
-
110
-
111
99
def show_versions (file = sys .stdout ):
112
100
"""
113
101
Print various dependency versions which are useful when submitting bug reports.
@@ -130,23 +118,28 @@ def show_versions(file=sys.stdout):
130
118
"executable" : sys .executable ,
131
119
"machine" : platform .platform (),
132
120
}
133
- deps = [Requirement (v ).name for v in importlib .metadata .requires ("pygmt" )]
134
- gs_version = _get_ghostscript_version ()
135
- gdal_version = _get_gdal_version ()
121
+ dep_info = {
122
+ Requirement (v ).name : _get_module_version (Requirement (v ).name )
123
+ for v in importlib .metadata .requires ("pygmt" )
124
+ }
125
+ dep_info .update (
126
+ {
127
+ "gdal" : _get_module_version ("osgeo.gdal" ),
128
+ "ghostscript" : _get_ghostscript_version (),
129
+ }
130
+ )
136
131
137
132
lines = []
138
133
lines .append ("PyGMT information:" )
139
134
lines .append (f" version: { __version__ } " )
140
135
lines .append ("System information:" )
141
136
lines .extend ([f" { key } : { val } " for key , val in sys_info .items ()])
142
137
lines .append ("Dependency information:" )
143
- lines .extend ([f" { modname } : { _get_module_version (modname )} " for modname in deps ])
144
- lines .append (f" gdal: { gdal_version } " )
145
- lines .append (f" ghostscript: { gs_version } " )
138
+ lines .extend ([f" { key } : { val } " for key , val in dep_info .items ()])
146
139
lines .append ("GMT library information:" )
147
140
lines .extend ([f" { key } : { val } " for key , val in _get_clib_info ().items ()])
148
141
149
- if warnmsg := _check_ghostscript_version (gs_version ):
142
+ if warnmsg := _check_ghostscript_version (dep_info [ "ghostscript" ] ):
150
143
lines .append ("WARNING:" )
151
144
lines .append (f" { warnmsg } " )
152
145
0 commit comments