Capture and log pip install error output (#7200)

Add an optional extended description…
This commit is contained in:
Pierre Ståhl authored and Pascal Vizeli committed 2017-04-21 14:15:05 +02:00
1 parent 0acc52b23b
commit f5dd25c87f
2 files changed
+42 -28

No files matched your search

+8 -5
View File
@@ -1,9 +1,9 @@
"""Helpers to install PyPi packages."""
import logging
import os
import subprocess
import sys
import threading
from subprocess import Popen, PIPE
from urllib.parse import urlparse
from typing import Optional
@@ -36,12 +36,15 @@ def install_package(package: str, upgrade: bool=True,
if constraints is not None:
args += ['--constraint', constraints]
try:
return subprocess.call(args) == 0
except subprocess.SubprocessError:
_LOGGER.exception('Unable to install package %s', package)
process = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
_, stderr = process.communicate()
if process.returncode != 0:
_LOGGER.error('Unable to install package %s: %s',
package, stderr.decode('utf-8').lstrip().strip())
return False
return True
def check_package_exists(package: str, lib_dir: str) -> bool:
"""Check if a package is installed globally or in lib_dir.