diff options
author | Dmitrii Agibov <dmitrii.agibov@arm.com> | 2022-12-13 09:39:21 +0000 |
---|---|---|
committer | Dmitrii Agibov <dmitrii.agibov@arm.com> | 2022-12-16 09:25:21 +0000 |
commit | 8da6441c87532d20d3c8dad538e46dc99d073927 (patch) | |
tree | 6afb7f0c82c5c357f7497413f0e18473e84d472c /src/mlia/utils | |
parent | ba9aeace4c3d3f4f31830d68b5cc7dd3f4bf1dde (diff) | |
download | mlia-8da6441c87532d20d3c8dad538e46dc99d073927.tar.gz |
MLIA-460 Revisit backend management
- Provide command for backend installation in case
if backend is not available
- Fix issue with connection timeout during downloading
- Show installation tools output only in verbose mode
Change-Id: Ic0e495ba19879cc2cda4fd0bce20b57ba896cfeb
Diffstat (limited to 'src/mlia/utils')
-rw-r--r-- | src/mlia/utils/download.py | 3 | ||||
-rw-r--r-- | src/mlia/utils/py_manager.py | 41 |
2 files changed, 32 insertions, 12 deletions
diff --git a/src/mlia/utils/download.py b/src/mlia/utils/download.py index c8d0b69..e00be28 100644 --- a/src/mlia/utils/download.py +++ b/src/mlia/utils/download.py @@ -46,9 +46,10 @@ def download( show_progress: bool = False, label: str | None = None, chunk_size: int = 8192, + timeout: int = 30, ) -> None: """Download the file.""" - with requests.get(url, stream=True, timeout=10.0) as resp: + with requests.get(url, stream=True, timeout=timeout) as resp: resp.raise_for_status() content_chunks = resp.iter_content(chunk_size=chunk_size) diff --git a/src/mlia/utils/py_manager.py b/src/mlia/utils/py_manager.py index 5f98fcc..d7821d3 100644 --- a/src/mlia/utils/py_manager.py +++ b/src/mlia/utils/py_manager.py @@ -3,10 +3,16 @@ """Util functions for managing python packages.""" from __future__ import annotations +import logging +import subprocess # nosec import sys from importlib.metadata import distribution from importlib.metadata import PackageNotFoundError -from subprocess import check_call # nosec + +from mlia.core.errors import InternalError + + +logger = logging.getLogger(__name__) class PyPackageManager: @@ -45,16 +51,29 @@ class PyPackageManager: """Execute pip command.""" assert sys.executable, "Unable to launch pip command" - check_call( - [ - sys.executable, - "-m", - "pip", - "--disable-pip-version-check", - subcommand, - *params, - ] - ) + try: + output = subprocess.check_output( # nosec + [ + sys.executable, + "-m", + "pip", + "--disable-pip-version-check", + subcommand, + *params, + ], + stderr=subprocess.STDOUT, + text=True, + ) + returncode = 0 + except subprocess.CalledProcessError as err: + output = err.output + returncode = err.returncode + + for line in output.splitlines(): + logger.debug(line.rstrip()) + + if returncode != 0: + raise InternalError("Unable to install python package") def get_package_manager() -> PyPackageManager: |