From ea85c5fa9239e37f42d25137b54bae796abcd748 Mon Sep 17 00:00:00 2001 From: Yaakov Selkowitz Date: Tue, 2 Jan 2024 22:47:29 -0500 Subject: [PATCH] Make progress_bar an extra feature This allows the 'rich' dependency, which has additional dependencies and is not available in RHEL, to be optional. Fixes: #360 Signed-off-by: Yaakov Selkowitz --- podman/domain/images_manager.py | 14 +++++++++++++- requirements.txt | 1 - rpm/python-podman.spec | 6 ++++++ setup.cfg | 3 +++ test-requirements.txt | 1 - 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/podman/domain/images_manager.py b/podman/domain/images_manager.py index 17c15b9f..3f94791c 100644 --- a/podman/domain/images_manager.py +++ b/podman/domain/images_manager.py @@ -6,7 +6,6 @@ import urllib.parse from typing import Any, Dict, Generator, Iterator, List, Mapping, Optional, Union import requests -from rich.progress import Progress, TextColumn, BarColumn, TaskProgressColumn, TimeRemainingColumn from podman import api from podman.api import Literal @@ -17,6 +16,17 @@ from podman.domain.registry_data import RegistryData from podman.errors import APIError, ImageNotFound +try: + from rich.progress import ( + Progress, + TextColumn, + BarColumn, + TaskProgressColumn, + TimeRemainingColumn, + ) +except (ImportError, ModuleNotFoundError): + Progress = None + logger = logging.getLogger("podman.images") @@ -314,6 +324,8 @@ def pull( # progress bar progress_bar = kwargs.get("progress_bar", False) if progress_bar: + if Progress is None: + raise ModuleNotFoundError('progress_bar requires \'rich.progress\' module') params["compatMode"] = True stream = True diff --git a/requirements.txt b/requirements.txt index 15620b95..67b5399f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,3 @@ sphinx tomli>=1.2.3; python_version<'3.11' urllib3 wheel -rich >= 12.5.1 diff --git a/rpm/python-podman.spec b/rpm/python-podman.spec index be7630c3..15015595 100644 --- a/rpm/python-podman.spec +++ b/rpm/python-podman.spec @@ -81,6 +81,11 @@ export PBR_VERSION="0.0.0" %pyproject_save_files %{pypi_name} %endif +%if !%{defined rhel8_py} +%check +%pyproject_check_import -e podman.api.typing_extensions +%endif + %if %{defined rhel8_py} %files -n python%{python3_pkgversion}-%{pypi_name} %dir %{python3_sitelib}/%{pypi_name}-*-py%{python3_version}.egg-info @@ -88,6 +93,7 @@ export PBR_VERSION="0.0.0" %dir %{python3_sitelib}/%{pypi_name} %{python3_sitelib}/%{pypi_name}/* %else +%pyproject_extras_subpkg -n python%{python3_pkgversion}-%{pypi_name} progress_bar %files -n python%{python3_pkgversion}-%{pypi_name} -f %{pyproject_files} %endif %license LICENSE diff --git a/setup.cfg b/setup.cfg index 123f8034..bf0281d8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,6 +38,9 @@ install_requires = requests >=2.24 tomli>=1.2.3; python_version<'3.11' urllib3 + +[options.extras_require] +progress_bar = rich >= 12.5.1 # typing_extensions are included for RHEL 8.5 diff --git a/test-requirements.txt b/test-requirements.txt index 4b51b081..b208312e 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,4 +7,3 @@ pylint pytest requests-mock >= 1.11.0 tox -rich >= 12.5.1