mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 04:05:20 +01:00
Create progress file for pip installs (#24297)
* Create progress file for pip installs * fix dedlock * unflacky test * Address comments * Lint * Types
This commit is contained in:
committed by
Paulus Schoutsen
parent
d7c8adc085
commit
bf52aa8ccc
@@ -1,6 +1,6 @@
|
||||
"""Module to handle installing requirements."""
|
||||
import asyncio
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
import logging
|
||||
import os
|
||||
from typing import Any, Dict, List, Optional
|
||||
@@ -11,6 +11,7 @@ from homeassistant.core import HomeAssistant
|
||||
DATA_PIP_LOCK = 'pip_lock'
|
||||
DATA_PKG_CACHE = 'pkg_cache'
|
||||
CONSTRAINT_FILE = 'package_constraints.txt'
|
||||
PROGRESS_FILE = '.pip_progress'
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -24,15 +25,16 @@ async def async_process_requirements(hass: HomeAssistant, name: str,
|
||||
if pip_lock is None:
|
||||
pip_lock = hass.data[DATA_PIP_LOCK] = asyncio.Lock()
|
||||
|
||||
pip_install = partial(pkg_util.install_package,
|
||||
**pip_kwargs(hass.config.config_dir))
|
||||
kwargs = pip_kwargs(hass.config.config_dir)
|
||||
|
||||
async with pip_lock:
|
||||
for req in requirements:
|
||||
if pkg_util.is_installed(req):
|
||||
continue
|
||||
|
||||
ret = await hass.async_add_executor_job(pip_install, req)
|
||||
ret = await hass.async_add_executor_job(
|
||||
_install, hass, req, kwargs
|
||||
)
|
||||
|
||||
if not ret:
|
||||
_LOGGER.error("Not initializing %s because could not install "
|
||||
@@ -42,6 +44,16 @@ async def async_process_requirements(hass: HomeAssistant, name: str,
|
||||
return True
|
||||
|
||||
|
||||
def _install(hass: HomeAssistant, req: str, kwargs: Dict) -> bool:
|
||||
"""Install requirement."""
|
||||
progress_path = Path(hass.config.path(PROGRESS_FILE))
|
||||
progress_path.touch()
|
||||
try:
|
||||
return pkg_util.install_package(req, **kwargs)
|
||||
finally:
|
||||
progress_path.unlink()
|
||||
|
||||
|
||||
def pip_kwargs(config_dir: Optional[str]) -> Dict[str, Any]:
|
||||
"""Return keyword arguments for PIP install."""
|
||||
is_docker = pkg_util.is_docker_env()
|
||||
|
||||
Reference in New Issue
Block a user