@@ -96,18 +96,6 @@ def _check_ghostscript_version(gs_version: str) -> str | None:
9696 return None
9797
9898
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-
11199def show_versions (file = sys .stdout ):
112100 """
113101 Print various dependency versions which are useful when submitting bug reports.
@@ -130,23 +118,28 @@ def show_versions(file=sys.stdout):
130118 "executable" : sys .executable ,
131119 "machine" : platform .platform (),
132120 }
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+ )
136131
137132 lines = []
138133 lines .append ("PyGMT information:" )
139134 lines .append (f" version: { __version__ } " )
140135 lines .append ("System information:" )
141136 lines .extend ([f" { key } : { val } " for key , val in sys_info .items ()])
142137 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 ()])
146139 lines .append ("GMT library information:" )
147140 lines .extend ([f" { key } : { val } " for key , val in _get_clib_info ().items ()])
148141
149- if warnmsg := _check_ghostscript_version (gs_version ):
142+ if warnmsg := _check_ghostscript_version (dep_info [ "ghostscript" ] ):
150143 lines .append ("WARNING:" )
151144 lines .append (f" { warnmsg } " )
152145
0 commit comments