Skip to content

Commit

Permalink
Merge pull request #5196 from Textualize/optional-httpx
Browse files Browse the repository at this point in the history
Make httpx optional in demo
  • Loading branch information
willmcgugan authored Oct 29, 2024
2 parents ac5d571 + 1bb1972 commit 40da260
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 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 40da260

Please sign in to comment.