From d869ba0b015f0bdaf4990cdd0b4f2f806a9ed4fa Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Fri, 3 May 2024 23:27:31 +0100 Subject: [PATCH] =?UTF-8?q?Avoid=20assuming=20there=E2=80=99s=20a=20PATH?= =?UTF-8?q?=20variable=20defined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is helpful in restricted environments, and this is the only place where `mx --version` breaks at the moment. Signed-off-by: Stefan Marr --- src/mx/_impl/mx_proftool.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mx/_impl/mx_proftool.py b/src/mx/_impl/mx_proftool.py index 6d2e361c..f4047105 100644 --- a/src/mx/_impl/mx_proftool.py +++ b/src/mx/_impl/mx_proftool.py @@ -921,6 +921,9 @@ def demangled_name(self, short_class_names: bool = False): def _which(executable): + if 'PATH' not in os.environ: + return None + for path in os.environ['PATH'].split(os.pathsep): f = os.path.join(path.strip('"'), executable) if os.path.isfile(f) and os.access(f, os.X_OK):