Skip to content

Commit

Permalink
fix: Installer regression after upgrading Textual (#2867)
Browse files Browse the repository at this point in the history
Backported-from: main (24.09)
Backported-to: 24.03
Backport-of: 2867
  • Loading branch information
achimnol committed Sep 25, 2024
1 parent a77a4cc commit 15a000d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions changes/2867.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a regression in progress bar rendering of the TUI installer after upgrading the Textual library
20 changes: 8 additions & 12 deletions src/ai/backend/install/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from rich.text import Text
from textual.app import App
from textual.containers import Vertical
from textual.widgets import Label, ProgressBar, Static
from textual.widgets import ProgressBar

from ai.backend.common.etcd import AsyncEtcd, ConfigScopes

Expand Down Expand Up @@ -61,7 +61,7 @@
ServerAddr,
ServiceConfig,
)
from .widgets import SetupLog
from .widgets import ProgressItem, SetupLog

current_log: ContextVar[SetupLog] = ContextVar("current_log")
PASSPHRASE_CHARACTER_POOL: Final[list[str]] = (
Expand Down Expand Up @@ -1002,11 +1002,9 @@ async def _fetch_package(self, name: str, vpane: Vertical) -> None:
pkg_url = f"https://github.com/lablup/backend.ai/releases/download/{self.dist_info.version}/{pkg_name}"
csum_url = pkg_url + ".sha256"
self.log.write(f"Downloading {pkg_url}...")
item = Static(classes="progress-item")
label = Label(Text.from_markup(f"[blue](download)[/] {pkg_name}"), classes="progress-name")
progress = ProgressBar(classes="progress-download")
item.mount_all([label, progress])
vpane.mount(item)
item = ProgressItem(f"[blue](download)[/] {pkg_name}")
await vpane.mount(item)
progress = item.get_child_by_type(ProgressBar)
async with self.wget_sema:
await wget(pkg_url, dst_path, progress)
await wget(csum_url, csum_path)
Expand All @@ -1026,11 +1024,9 @@ async def _install_package(self, name: str, vpane: Vertical, *, fat: bool) -> No
pkg_name = self.mangle_pkgname(name, fat=fat)
src_path = self.dist_info.package_dir / pkg_name
dst_path = self.dist_info.target_path / pkg_name
item = Static(classes="progress-item")
label = Label(Text.from_markup(f"[blue](install)[/] {pkg_name}"), classes="progress-name")
progress = ProgressBar(classes="progress-install")
item.mount_all([label, progress])
vpane.mount(item)
item = ProgressItem(f"[blue](install)[/] {pkg_name}")
await vpane.mount(item)
progress = item.get_child_by_type(ProgressBar)
progress.update(total=src_path.stat().st_size)
async with (
aiofiles.open(src_path, "rb") as src,
Expand Down
20 changes: 19 additions & 1 deletion src/ai/backend/install/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
from textual.containers import Horizontal
from textual.validation import ValidationResult, Validator
from textual.widget import Widget
from textual.widgets import Button, Input, Label, RichLog, Static
from textual.widgets import (
Button,
Input,
Label,
ProgressBar,
RichLog,
Static,
)


class DirectoryPathValidator(Validator):
Expand All @@ -22,6 +29,17 @@ def validate(self, value: str) -> ValidationResult:
return self.failure("The path is not a directory")


class ProgressItem(Static):
def __init__(self, label: str, *args, **kwargs) -> None:
kwargs["classes"] = " ".join((kwargs.get("classes", ""), "progress-item"))
super().__init__(*args, **kwargs)
self._label = label

def compose(self) -> ComposeResult:
yield Label(Text.from_markup(self._label), classes="progress-name")
yield ProgressBar(classes="progress-download")


class SetupLog(RichLog):
BINDINGS = [
Binding("enter", "continue", show=False),
Expand Down

0 comments on commit 15a000d

Please sign in to comment.