Capture and log pip install error output (#7200)
Add an optional extended description…
This commit is contained in:
1 parent
0acc52b23b
commit
f5dd25c87f
2 files changed
+42
-28
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user