mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Cleaned up main file to remove dependency management.
This commit is contained in:
parent
3839c3d0ef
commit
18e32165a4
@ -4,12 +4,14 @@ from __future__ import print_function
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
import subprocess
|
||||
import importlib
|
||||
|
||||
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'))
|
||||
from homeassistant import bootstrap
|
||||
import homeassistant.config as config_util
|
||||
from homeassistant.components import frontend, demo
|
||||
|
||||
USER_DATA_DIR = os.getenv('APPDATA') if os.name == "nt" \
|
||||
else os.path.expanduser('~')
|
||||
|
||||
|
||||
def validate_python():
|
||||
@ -31,54 +33,6 @@ def ensure_pip():
|
||||
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 = [sys.executable, '-m', 'pip', 'install', '--quiet', package]
|
||||
if not IS_VIRTUAL:
|
||||
args.append('--user')
|
||||
try:
|
||||
return 0 == subprocess.call(args)
|
||||
except subprocess.SubprocessError:
|
||||
return False
|
||||
|
||||
|
||||
def validate_dependencies():
|
||||
""" Validate all dependencies that HA uses. """
|
||||
ensure_pip()
|
||||
|
||||
print("Validating dependencies...")
|
||||
import_fail = False
|
||||
|
||||
for requirement in DEPENDENCIES:
|
||||
if not install_package(requirement):
|
||||
import_fail = True
|
||||
print('Fatal Error: Unable to install dependency', requirement)
|
||||
|
||||
if import_fail:
|
||||
print(("Install dependencies by running: "
|
||||
"python3 -m pip install -r requirements.txt"))
|
||||
sys.exit()
|
||||
|
||||
|
||||
def ensure_path_and_load_bootstrap():
|
||||
""" Ensure sys load path is correct and load Home Assistant bootstrap. """
|
||||
try:
|
||||
from homeassistant import bootstrap
|
||||
|
||||
except ImportError:
|
||||
# This is to add support to load Home Assistant using
|
||||
# `python3 homeassistant` instead of `python3 -m homeassistant`
|
||||
|
||||
# Insert the parent directory of this file into the module search path
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from homeassistant import bootstrap
|
||||
|
||||
return bootstrap
|
||||
|
||||
|
||||
def validate_git_submodules():
|
||||
""" Validate the git submodules are cloned. """
|
||||
try:
|
||||
@ -94,13 +48,25 @@ def ensure_config_path(config_dir):
|
||||
""" Gets the path to the configuration file.
|
||||
Creates one if it not exists. """
|
||||
|
||||
lib_dir = os.path.join(config_dir, 'lib')
|
||||
|
||||
# Test if configuration directory exists
|
||||
if not os.path.isdir(config_dir):
|
||||
print(('Fatal Error: Unable to find specified configuration '
|
||||
'directory {} ').format(config_dir))
|
||||
sys.exit()
|
||||
try:
|
||||
os.mkdir(config_dir)
|
||||
except OSError:
|
||||
print(('Fatal Error: Unable to create specified configuration '
|
||||
'directory {} ').format(config_dir))
|
||||
sys.exit()
|
||||
|
||||
import homeassistant.config as config_util
|
||||
# Test if library directory exists
|
||||
if not os.path.isdir(lib_dir):
|
||||
try:
|
||||
os.mkdir(lib_dir)
|
||||
except OSError:
|
||||
print(('Fatal Error: Unable to create library '
|
||||
'directory {} ').format(lib_dir))
|
||||
sys.exit()
|
||||
|
||||
config_path = config_util.ensure_config_exists(config_dir)
|
||||
|
||||
@ -117,7 +83,7 @@ def get_arguments():
|
||||
parser.add_argument(
|
||||
'-c', '--config',
|
||||
metavar='path_to_config_dir',
|
||||
default="config",
|
||||
default=os.path.join(USER_DATA_DIR, '.homeassistant'),
|
||||
help="Directory that contains the Home Assistant configuration")
|
||||
parser.add_argument(
|
||||
'--demo-mode',
|
||||
@ -134,12 +100,6 @@ def get_arguments():
|
||||
def main():
|
||||
""" Starts Home Assistant. """
|
||||
validate_python()
|
||||
validate_dependencies()
|
||||
|
||||
# Windows needs this to pick up new modules
|
||||
importlib.invalidate_caches()
|
||||
|
||||
bootstrap = ensure_path_and_load_bootstrap()
|
||||
|
||||
validate_git_submodules()
|
||||
|
||||
@ -149,8 +109,6 @@ def main():
|
||||
config_path = ensure_config_path(config_dir)
|
||||
|
||||
if args.demo_mode:
|
||||
from homeassistant.components import frontend, demo
|
||||
|
||||
hass = bootstrap.from_config_dict({
|
||||
frontend.DOMAIN: {},
|
||||
demo.DOMAIN: {}
|
||||
@ -159,11 +117,10 @@ def main():
|
||||
hass = bootstrap.from_config_file(config_path)
|
||||
|
||||
if args.open_ui:
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||
|
||||
def open_browser(event):
|
||||
""" Open the webinterface in a browser. """
|
||||
if hass.config.api is not None:
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||
import webbrowser
|
||||
webbrowser.open(hass.config.api.base_url)
|
||||
|
||||
|
3
setup.py
3
setup.py
@ -30,8 +30,7 @@ setup(
|
||||
package_data=PACKAGE_DATA,
|
||||
zip_safe=False,
|
||||
platforms='any',
|
||||
install_requires=['requests==2.7.0', 'pyyaml==3.11', 'pytz==2015.4',
|
||||
'netdisco==0.3', 'astral==0.8.1'],
|
||||
install_requires=['requests==2.7.0', 'pyyaml==3.11', 'pytz==2015.4'],
|
||||
keywords=['home', 'automation'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
|
Loading…
x
Reference in New Issue
Block a user