Skip to content

Commit 66d4d5c

Browse files
authored
Refactor the _get_ghostscript_version function to avoid try-except in loops (#2880)
1 parent 638ce40 commit 66d4d5c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

pygmt/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def show_versions(file=sys.stdout):
107107

108108
import importlib
109109
import platform
110+
import shutil
110111
import subprocess
111112

112113
from packaging.requirements import Requirement
@@ -141,12 +142,10 @@ def _get_ghostscript_version():
141142
return None
142143

143144
for gs_cmd in cmds:
144-
try:
145+
if (gsfullpath := shutil.which(gs_cmd)) is not None:
145146
return subprocess.check_output(
146-
[gs_cmd, "--version"], universal_newlines=True
147+
[gsfullpath, "--version"], universal_newlines=True
147148
).strip()
148-
except FileNotFoundError:
149-
continue
150149
return None
151150

152151
sys_info = {

0 commit comments

Comments
 (0)