Skip to content

Commit

Permalink
Make httpx optional in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Oct 29, 2024
1 parent ac5d571 commit 844766e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/textual/demo/home.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 844766e

Please sign in to comment.