Skip to content

Commit

Permalink
fix(imaging): more reliable way to check if extra is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
helmut-hoffer-von-ankershoffen committed Dec 29, 2024
1 parent 09f0455 commit 144ee14
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"filename": "src/starbridge/hello/service.py",
"hashed_secret": "b96ff7d04dbdf5211aa6bf8ac3a557f30dc7469b",
"is_verified": false,
"line_number": 119,
"line_number": 113,
"is_secret": false
}
],
Expand All @@ -152,5 +152,5 @@
}
]
},
"generated_at": "2024-12-28T14:44:42Z"
"generated_at": "2024-12-29T18:21:09Z"
}
1 change: 1 addition & 0 deletions src/starbridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def _parse_env_args():

def _amend_library_path():
"""Patch environment variables before any other imports"""

if "DYLD_FALLBACK_LIBRARY_PATH" not in os.environ:
os.environ["DYLD_FALLBACK_LIBRARY_PATH"] = (
f"{os.getenv('HOMEBREW_PREFIX', '/opt/homebrew')}/lib/"
Expand Down
12 changes: 3 additions & 9 deletions src/starbridge/hello/service.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
"""Handles Hello operations."""

import base64
import imp
import io
import os

from mcp.types import BlobResourceContents, EmbeddedResource

try:
from PIL import Image

_has_imaging = True
except ImportError:
_has_imaging = False

from pydantic import AnyUrl

from starbridge.mcp import MCPBaseService, MCPContext, mcp_tool
Expand Down Expand Up @@ -44,12 +37,13 @@ def hello(self, locale: str = "en_US", context: MCPContext | None = None):
return "Hallo Welt!"
return "Hello World!"

if _has_imaging:
if imp.find_module("cairosvg"):

@mcp_tool()
def bridge(self, context: MCPContext | None = None):
"""Show image of starbridge"""
import cairosvg
from PIL import Image

return Image.open(
io.BytesIO(
Expand Down

0 comments on commit 144ee14

Please sign in to comment.