Skip to content

Commit d5d0b35

Browse files
committed
Wrap run(which ...) in try.. except to avoid failing on systems where which is not installed
1 parent 5dcc92d commit d5d0b35

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

xcoll/scattering_routines/geant4/environment.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,26 @@ def __init__(self):
2626
self._in_constructor = False
2727
self._geant4_sourced = False
2828
self._bdsim_sourced = False
29-
cmd = run(['which', 'geant4-config'], capture_output=True)
30-
if cmd.returncode == 0:
31-
path = FsPath(cmd.stdout.decode().strip())
32-
if path.exists():
33-
self._geant4 = path
34-
self._geant4_sourced = True
35-
cmd = run(['which', 'bdsim'], capture_output=True)
36-
if cmd.returncode == 0:
37-
path = FsPath(cmd.stdout.decode().strip())
38-
if path.exists():
39-
self._bdsim = path
40-
self._bdsim_sourced = True
29+
try:
30+
cmd = run(['which', 'geant4-config'], capture_output=True)
31+
except FileNotFoundError:
32+
pass
33+
else:
34+
if cmd.returncode == 0:
35+
path = FsPath(cmd.stdout.decode().strip())
36+
if path.exists():
37+
self._geant4 = path
38+
self._geant4_sourced = True
39+
try:
40+
cmd = run(['which', 'bdsim'], capture_output=True)
41+
except FileNotFoundError:
42+
pass
43+
else:
44+
if cmd.returncode == 0:
45+
path = FsPath(cmd.stdout.decode().strip())
46+
if path.exists():
47+
self._bdsim = path
48+
self._bdsim_sourced = True
4149

4250
@property
4351
def compiled(self):

0 commit comments

Comments
 (0)