From 6eb6b70ba0b1f69cd1cb457b1114746ca03d4699 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Mon, 17 Jul 2023 11:56:35 -0600 Subject: [PATCH] Resolve exception in FileDownloader.get_os_version when lsb_release is missing --- pyomo/common/download.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pyomo/common/download.py b/pyomo/common/download.py index a3d5b3e90a3..79d5302a58e 100644 --- a/pyomo/common/download.py +++ b/pyomo/common/download.py @@ -15,6 +15,7 @@ import os import platform import re +import shutil import sys import subprocess @@ -99,14 +100,15 @@ def _get_distver_from_redhat_release(cls): @classmethod def _get_distver_from_lsb_release(cls): + lsb_release = shutil.which('lsb_release') dist = subprocess.run( - ['lsb_release', '-si'], + [lsb_release, '-si'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, ) ver = subprocess.run( - ['lsb_release', '-sr'], + [lsb_release, '-sr'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, @@ -152,14 +154,7 @@ def _get_os_version(cls): dist, ver = cls._get_distver_from_distro() elif os.path.exists('/etc/redhat-release'): dist, ver = cls._get_distver_from_redhat_release() - elif ( - subprocess.run( - ['lsb_release'], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - ).returncode - == 0 - ): + elif shutil.which('lsb_release'): dist, ver = cls._get_distver_from_lsb_release() elif os.path.exists('/etc/os-release'): # Note that (at least on centos), os_release is an