diff --git a/poetry.lock b/poetry.lock index 87abc59..2d60b8d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -727,9 +727,10 @@ tomli = {version = ">=2.0.1", markers = "python_full_version < \"3.11.0\""} name = "dnspython" version = "2.8.0" description = "DNS toolkit" -optional = false +optional = true python-versions = ">=3.10" groups = ["main"] +markers = "extra == \"mongo\"" files = [ {file = "dnspython-2.8.0-py3-none-any.whl", hash = "sha256:01d9bbc4a2d76bf0db7c1f729812ded6d912bd318d3b1cf81d30c0f845dbf3af"}, {file = "dnspython-2.8.0.tar.gz", hash = "sha256:181d3c6996452cb1189c4046c61599b84a5a86e099562ffde77d26984ff26d0f"}, @@ -2817,9 +2818,10 @@ windows-terminal = ["colorama (>=0.4.6)"] name = "pymongo" version = "4.16.0" description = "PyMongo - the Official MongoDB Python driver" -optional = false +optional = true python-versions = ">=3.9" groups = ["main"] +markers = "extra == \"mongo\"" files = [ {file = "pymongo-4.16.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:ed162b2227f98d5b270ecbe1d53be56c8c81db08a1a8f5f02d89c7bb4d19591d"}, {file = "pymongo-4.16.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:4a9390dce61d705a88218f0d7b54d7e1fa1b421da8129fc7c009e029a9a6b81e"}, @@ -3916,7 +3918,10 @@ enabler = ["pytest-enabler (>=2.2)"] test = ["big-O", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more_itertools", "pytest (>=6,!=8.1.*)", "pytest-ignore-flaky"] type = ["pytest-mypy"] +[extras] +mongo = ["pymongo"] + [metadata] lock-version = "2.1" python-versions = ">=3.10,<3.13" -content-hash = "a84161e61d7038911ac4ec9ff6673c66f3ad6f6fd9da3dbf134dd99cabbf456e" +content-hash = "130bbfbfb0199343bbef654d8dc4d5fef367c57625ce9cb9ef30fa1b82efd12f" diff --git a/pyproject.toml b/pyproject.toml index f64fc70..3fae3cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,12 +16,13 @@ dependencies = [ "streamlit>=1.49.0", "python-box (>=7.3.2,<8.0.0)", "uvicorn (>=0.40.0,<0.41.0)", - "pymongo (>=4.15.5,<5.0.0)", "bs4 (>=0.0.2,<0.0.3)", "dotenv (>=0.9.9,<0.10.0)", "pydantic (>=2.12.5,<3.0.0)", "click (>=8.3.1,<9.0.0)", ] +[project.optional-dependencies] +mongo = ["pymongo (>=4.15.5,<5.0.0)"] [tool.poetry] @@ -30,6 +31,7 @@ packages = [ { include = "assets/images/logo.png", from = "src" }, ] +include = [{ path = "templates/**/*", format = ["sdist", "wheel"] }] [project.scripts] sample = "sample.cli:cli" diff --git a/src/sample/api/fast_api.py b/src/sample/api/fast_api.py index e9467aa..4a79dd7 100644 --- a/src/sample/api/fast_api.py +++ b/src/sample/api/fast_api.py @@ -37,12 +37,12 @@ class GreetResponse(BaseModel): message: str -@app.get("/version",tags=["Meta"]) +@app.get("/version", tags=["Meta"]) def version(): return {"version": app.version} -@app.get("/", response_class=HTMLResponse,tags=["Meta"]) +@app.get("/", response_class=HTMLResponse, tags=["Meta"]) async def read_root(request: Request): return """ @@ -84,7 +84,7 @@ async def read_root(request: Request): """ -@app.get("/health",tags=["Meta"]) +@app.get("/health", tags=["Meta"]) def health_check(): return {"status": "ok"} @@ -106,7 +106,12 @@ def start(): import uvicorn print(f"🧵 {__version__}\n") - connect_db() + try: + connect_db() + except Exception: + print( + "⚠️ Could not connect to the database.Please check database configuration." + ) uvicorn.run("sample.api.fast_api:app", host="127.0.0.1", port=5000, reload=True) diff --git a/src/sample/cli.py b/src/sample/cli.py index 98fd6b7..6f63be0 100644 --- a/src/sample/cli.py +++ b/src/sample/cli.py @@ -1,28 +1,35 @@ import click + from . import __version__ -@click.group(invoke_without_command=True) +@click.group( + invoke_without_command=True, + help=""" +Sample command-line tools. + +To configure MongoDB support, install with: + + pip install sample[mongo] +""", +) @click.option("--version", is_flag=True, help="Show the Sample version and exit.") @click.pass_context def cli(ctx, version): - """Sample command-line tools.""" if version: click.echo(__version__) ctx.exit() -@cli.command() +@cli.command(help="Run the Sample Streamlit app.") def dev(): - """Run the Sample Streamlit app.""" from sample.__main__ import main main() -@cli.command() +@cli.command(help="Run the Sample FastAPI backend.") def api(): - """Run the Sample FastAPI backend.""" from sample.api.fast_api import start start() diff --git a/src/sample/features/greeting.py b/src/sample/features/greeting.py index 3a8154a..7eb35d7 100644 --- a/src/sample/features/greeting.py +++ b/src/sample/features/greeting.py @@ -8,7 +8,14 @@ def greet(): st.header(APP_TITLE) name = st.text_input("Enter your name") - connect_db() + + # Try connecting, but don't crash if it fails + try: + connect_db() + except Exception: + st.warning( + "⚠️ Could not connect to the database. Please check database configuration." + ) clean_name = normalize_name(name) diff --git a/templates/faq.css b/templates/faq.css index 2f03b85..06c6edd 100644 --- a/templates/faq.css +++ b/templates/faq.css @@ -15,7 +15,7 @@ --bg: #2a2a2a; --border: #3a3a3a; --border-hover: #4a4a4a; - --summary-color: #283649; + --summary-color: #4b72a6; --text-color: #764ba2; } }