From 8da4053c300414b1bc543393c938077362caa57f Mon Sep 17 00:00:00 2001 From: AbdealiJK Date: Sat, 11 Jun 2016 08:48:23 +0530 Subject: [PATCH] setup.py: Don't fail if pip fails in cmake err msg When cmake is not found, the error message suggests what to do to install cmake. But if `distro` is not found and cannot be installed, the distro specific error message cannot be shown. Hence, we simply ignore this and continue on. Also, make the pip install quiet so that if there is an error message in that, the user does not get confused by it. --- setup.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/setup.py b/setup.py index 695690b76..400eccf1a 100644 --- a/setup.py +++ b/setup.py @@ -468,26 +468,30 @@ class build(_build): message = msg_pkgmanager.format('OSX', manager) break elif sys.platform.startswith('linux'): - distname = None try: import distro - except ImportError: + except ImportError as err: import pip - pip_exit = pip.main(['install', 'distro']) + pip_exit = pip.main(['install', '-q', 'distro']) if pip_exit > 0: - raise SystemExit('Pip was unable to install `distro`') - import distro - distname = distro.id() - if distname in ('debian', 'ubuntu'): - message = msg_pkgmanager.format( - distname.title(), 'apt-get') - elif distname in ('fedora', 'centos', 'redhat'): - pkgmanagers = ("dnf", "yum") - for manager in pkgmanagers: - if find_executable(manager) is not None: - message = msg_pkgmanager.format( - distname.title(), manager) - break + log.debug("Unable to install `distro` to identify " + "the recommended command. Falling back " + "to default error message.") + distro = err + else: + import distro + if not isinstance(distro, ImportError): + distname = distro.id() + if distname in ('debian', 'ubuntu'): + message = msg_pkgmanager.format( + distname.title(), 'apt-get') + elif distname in ('fedora', 'centos', 'redhat'): + pkgmanagers = ("dnf", "yum") + for manager in pkgmanagers: + if find_executable(manager) is not None: + message = msg_pkgmanager.format( + distname.title(), manager) + break raise DistutilsSetupError( "Cannot find cmake, ensure it is installed and in the path.\n" + message + "\n"