1
mirror of https://github.com/home-assistant/core synced 2024-07-30 21:18:57 +02:00

Auto install core dependencies on boot

This commit is contained in:
Paulus Schoutsen 2015-07-06 23:59:21 -07:00
parent 4be9519e76
commit 90739c9df9

View File

@ -4,15 +4,9 @@ from __future__ import print_function
import sys
import os
import argparse
import importlib
import subprocess
# Home Assistant dependencies, mapped module -> package name
DEPENDENCIES = {
'requests': 'requests',
'yaml': 'pyyaml',
'pytz': 'pytz',
}
DEPENDENCIES = ['requests>=2.0', 'pyyaml>=3.11', 'pytz>=2015.2']
def validate_python():
@ -24,21 +18,29 @@ def validate_python():
sys.exit()
# Copy of homeassistant.util.package because we can't import yet
def install_package(package):
"""Install a package on PyPi. Accepts pip compatible package strings.
Return boolean if install successfull."""
args = ['python3', '-m', 'pip', 'install', '--disable-pip-version-check',
'--quiet', package]
if sys.base_prefix == sys.prefix:
args.append('--user')
return not subprocess.call(args)
def validate_dependencies():
""" Validate all dependencies that HA uses. """
import_fail = False
for module, name in DEPENDENCIES.items():
try:
importlib.import_module(module)
except ImportError:
for requirement in DEPENDENCIES:
if not install_package(requirement):
import_fail = True
print(
'Fatal Error: Unable to find dependency {}'.format(name))
print('Fatal Error: Unable to install dependency', requirement)
if import_fail:
print(("Install dependencies by running: "
"pip3 install -r requirements.txt"))
"python3 -m pip install -r requirements.txt"))
sys.exit()