Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if a script requirement is available before install #20517

Merged
merged 4 commits into from Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions homeassistant/scripts/__init__.py
Expand Up @@ -9,7 +9,8 @@

from homeassistant.bootstrap import async_mount_local_lib_path
from homeassistant.config import get_default_config_dir
from homeassistant import requirements
from homeassistant.core import HomeAssistant
from homeassistant.requirements import pip_kwargs, PackageLoadable
from homeassistant.util.package import install_package, is_virtual_env


Expand Down Expand Up @@ -39,16 +40,25 @@ def run(args: List) -> int:

config_dir = extract_config_dir()

loop = asyncio.get_event_loop()

if not is_virtual_env():
asyncio.get_event_loop().run_until_complete(
async_mount_local_lib_path(config_dir))
loop.run_until_complete(async_mount_local_lib_path(config_dir))

pip_kwargs = requirements.pip_kwargs(config_dir)
_pip_kwargs = pip_kwargs(config_dir)

logging.basicConfig(stream=sys.stdout, level=logging.INFO)

hass = HomeAssistant(loop)
pkgload = PackageLoadable(hass)
for req in getattr(script, 'REQUIREMENTS', []):
returncode = install_package(req, **pip_kwargs)
try:
loop.run_until_complete(pkgload.loadable(req))
continue
except ImportError:
pass

returncode = install_package(req, **_pip_kwargs)

if not returncode:
print('Aborting script, could not install dependency', req)
Expand Down
2 changes: 0 additions & 2 deletions homeassistant/scripts/check_config.py
Expand Up @@ -22,8 +22,6 @@
from homeassistant.exceptions import HomeAssistantError

REQUIREMENTS = ('colorlog==4.0.2',)
if system() == 'Windows': # Ensure colorama installed for colorlog on Windows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this no longer necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s automatic these days. In the past you needed colorlog[windows]

See https://pypi.org/project/colorlog/ search windows/colorama

REQUIREMENTS += ('colorama<=1',)

_LOGGER = logging.getLogger(__name__)
# pylint: disable=protected-access
Expand Down