Skip to content

Commit 05b3b23

Browse files
committed
Prioritize Comsol installation found on search path.
There may be situations where multiple installations of the same Comsol version exist on the same machine, but the (current) user wants to pick the one which has a single-user license in their name. The easiest way to do that is to just change that user's PATH variable once and for all. Related discussion: #172
1 parent 335e341 commit 05b3b23

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

mph/discovery.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
folder `.local` in the user's home directory is also searched to allow
1212
symbolic linking to a custom location.
1313
14-
In a last step, we also run the shell command `where comsol` (on Windows)
14+
Additionally, we also run the shell command `where comsol` (on Windows)
1515
or `which comsol` (on Linux and macOS) to find a Comsol installation
1616
that isn't in a default location, but for which the Comsol executable
1717
was added to the executable search path.
1818
1919
Note that duplicate installations will be ignored. That is, a Comsol
2020
installation found in a later step that reports the same version as one
2121
found in an earlier step will be ignored, regardless of install location.
22+
The one found on the search path, if any, will be prioritized.
2223
"""
2324

2425
from __future__ import annotations
@@ -232,7 +233,7 @@ def search_disk(architecture: str) -> list[Path]:
232233
return executables
233234

234235

235-
def lookup_comsol() -> Path | None:
236+
def search_path() -> Path | None:
236237
"""Returns Comsol executable if found on the system's search path."""
237238

238239
log.debug('Looking for Comsol executable on system search path.')
@@ -289,10 +290,14 @@ def find_backends() -> list[Backend]:
289290
raise NotImplementedError(error)
290291

291292
# Look up `comsol` command as if run in terminal.
292-
comsol = lookup_comsol()
293+
comsol = search_path()
293294
if comsol:
294295
if comsol not in executables:
295-
executables.append(comsol)
296+
executables.insert(0, comsol)
297+
# We put that Comsol executable first so that users have a way of
298+
# prioritizing one Comsol installation over another. This makes
299+
# sense for multiple installations of the same Comsol version, each
300+
# with a single-user license for a different user.
296301
else:
297302
log.debug('Ignoring executable as it was previously found.')
298303

0 commit comments

Comments
 (0)