From 844766e450e553abae27c6037c7b645dab3170a6 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 29 Oct 2024 12:24:27 +0000 Subject: [PATCH] Make httpx optional in demo --- src/textual/demo/home.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/textual/demo/home.py b/src/textual/demo/home.py index 84c1cbdac8..18eb331256 100644 --- a/src/textual/demo/home.py +++ b/src/textual/demo/home.py @@ -1,7 +1,12 @@ import asyncio from importlib.metadata import version -import httpx +try: + import httpx + + HTTPX_AVAILABLE = True +except ImportError: + HTTPX_AVAILABLE = False from textual import work from textual.app import ComposeResult @@ -152,6 +157,12 @@ class StarCount(Vertical): @work async def get_stars(self): """Worker to get stars from GitHub API.""" + if not HTTPX_AVAILABLE: + self.notify( + "Install httpx with to update stars from the GitHub API.\n\n$ [b]pip install httpx[/b]", + title="GitHub Stars", + ) + return self.loading = True try: await asyncio.sleep(1) # Time to admire the loading indicator