mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Increase robustness dependency installation
This commit is contained in:
parent
34b6627f9a
commit
c532a28a98
@ -7,6 +7,8 @@ import argparse
|
||||
import subprocess
|
||||
|
||||
DEPENDENCIES = ['requests>=2.0', 'pyyaml>=3.11', 'pytz>=2015.2']
|
||||
IS_VIRTUAL = (getattr(sys, 'base_prefix', sys.prefix) != sys.prefix or
|
||||
hasattr(sys, 'real_prefix'))
|
||||
|
||||
|
||||
def validate_python():
|
||||
@ -22,10 +24,13 @@ def validate_python():
|
||||
def install_package(package):
|
||||
"""Install a package on PyPi. Accepts pip compatible package strings.
|
||||
Return boolean if install successfull."""
|
||||
args = ['python3', '-m', 'pip', 'install', '--quiet', package]
|
||||
if sys.base_prefix == sys.prefix:
|
||||
args = [sys.executable, '-m', 'pip', 'install', '--quiet', package]
|
||||
if not IS_VIRTUAL:
|
||||
args.append('--user')
|
||||
return not subprocess.call(args)
|
||||
try:
|
||||
return 0 == subprocess.call(args)
|
||||
except subprocess.SubprocessError:
|
||||
return False
|
||||
|
||||
|
||||
def validate_dependencies():
|
||||
|
@ -5,4 +5,5 @@ import sys
|
||||
def is_virtual():
|
||||
""" Return if we run in a virtual environtment. """
|
||||
# Check supports venv && virtualenv
|
||||
return sys.base_prefix != sys.prefix or hasattr(sys, 'real_prefix')
|
||||
return (getattr(sys, 'base_prefix', sys.prefix) != sys.prefix or
|
||||
hasattr(sys, 'real_prefix'))
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Helpers to install PyPi packages."""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from . import environment as env
|
||||
|
||||
@ -11,9 +12,12 @@ def install_package(package, upgrade=False, user=INSTALL_USER):
|
||||
"""Install a package on PyPi. Accepts pip compatible package strings.
|
||||
Return boolean if install successfull."""
|
||||
# Not using 'import pip; pip.main([])' because it breaks the logger
|
||||
args = ['python3', '-m', 'pip', 'install', '--quiet', package]
|
||||
args = [sys.executable, '-m', 'pip', 'install', '--quiet', package]
|
||||
if upgrade:
|
||||
args.append('--upgrade')
|
||||
if user:
|
||||
args.append('--user')
|
||||
return not subprocess.call(args)
|
||||
try:
|
||||
return 0 == subprocess.call(args)
|
||||
except subprocess.SubprocessError:
|
||||
return False
|
||||
|
Loading…
x
Reference in New Issue
Block a user