From d75abe7a1b0c14130187c4b52ac75b43e73af556 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Thu, 5 Sep 2024 12:11:52 -0500 Subject: [PATCH] Add --status/--no-status options to 'shinylive assets download' --- CHANGELOG.md | 3 +++ shinylive/_assets.py | 4 ++++ shinylive/_main.py | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e528e41..1c3560c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [UNRELEASED] + +* Download status is now displayed while downloading Shinylive assets. ## [0.6.0] - 2024-09-03 diff --git a/shinylive/_assets.py b/shinylive/_assets.py index 350a4ff..b57aca3 100644 --- a/shinylive/_assets.py +++ b/shinylive/_assets.py @@ -17,6 +17,7 @@ def download_shinylive( destdir: str | Path | None = None, version: str = SHINYLIVE_ASSETS_VERSION, url: Optional[str] = None, + status: bool = True, ) -> None: if destdir is None: # Note that this is the cache directory, which is the parent of the assets @@ -36,6 +37,9 @@ def download_shinylive( last_update_time = start_time def reporthook(count: int, block_size: int, total_size: int): + if not status: + return + nonlocal last_update_time current_time = time.time() diff --git a/shinylive/_main.py b/shinylive/_main.py index 02b3cdd..71c9eed 100644 --- a/shinylive/_main.py +++ b/shinylive/_main.py @@ -226,14 +226,21 @@ def assets_info( default=None, help="URL to download from. If used, this will override --version.", ) +@click.option( + "--status/--no-status", + is_flag=True, + default=True, + help="Enable/disable status output during download.", +) def download( version: str, dir: Optional[str | Path], url: Optional[str], + status: bool, ) -> None: if version is None: # pyright: ignore[reportUnnecessaryComparison] version = SHINYLIVE_ASSETS_VERSION - _assets.download_shinylive(destdir=upgrade_dir(dir), version=version, url=url) + _assets.download_shinylive(destdir=upgrade_dir(dir), version=version, url=url, status=status) cleanup_help = f"Remove all versions of local assets except the currently-used version, {SHINYLIVE_ASSETS_VERSION}."