Skip to content

Commit 40da260

Browse files
authored
Merge pull request Textualize#5196 from Textualize/optional-httpx
Make httpx optional in demo
2 parents ac5d571 + 1bb1972 commit 40da260

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/textual/demo/home.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import asyncio
22
from importlib.metadata import version
33

4-
import httpx
4+
try:
5+
import httpx
6+
7+
HTTPX_AVAILABLE = True
8+
except ImportError:
9+
HTTPX_AVAILABLE = False
510

611
from textual import work
712
from textual.app import ComposeResult
@@ -152,6 +157,12 @@ class StarCount(Vertical):
152157
@work
153158
async def get_stars(self):
154159
"""Worker to get stars from GitHub API."""
160+
if not HTTPX_AVAILABLE:
161+
self.notify(
162+
"Install httpx to update stars from the GitHub API.\n\n$ [b]pip install httpx[/b]",
163+
title="GitHub Stars",
164+
)
165+
return
155166
self.loading = True
156167
try:
157168
await asyncio.sleep(1) # Time to admire the loading indicator

0 commit comments

Comments
 (0)