From 413cce0e743b00db1e843ea27c0004539c3881e2 Mon Sep 17 00:00:00 2001 From: Heisenberg208 Date: Wed, 18 Feb 2026 22:54:42 +0530 Subject: [PATCH 1/2] [RZP-260009]: refactor: update optional dependencies for MongoDB and improve database connection handling --- poetry.lock | 11 ++++++++--- pyproject.toml | 4 +++- src/sample/api/fast_api.py | 13 +++++++++---- src/sample/features/greeting.py | 9 ++++++++- templates/faq.css | 6 +++--- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/poetry.lock b/poetry.lock index 7b43c5b..ee56e8a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -732,9 +732,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"}, @@ -2804,9 +2805,10 @@ windows-terminal = ["colorama (>=0.4.6)"] name = "pymongo" version = "4.15.5" description = "PyMongo - the Official MongoDB Python driver" -optional = false +optional = true python-versions = ">=3.9" groups = ["main"] +markers = "extra == \"mongo\"" files = [ {file = "pymongo-4.15.5-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:a01a2054d50b50c121c720739a2216d855c48726b0002894de9b991cdd68a2a5"}, {file = "pymongo-4.15.5-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:5e57968139d81367117ed7b75d921445a575d4d7e61536f5e860475df92ac0a9"}, @@ -3897,7 +3899,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/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 415e02b..06c6edd 100644 --- a/templates/faq.css +++ b/templates/faq.css @@ -15,13 +15,13 @@ --bg: #2a2a2a; --border: #3a3a3a; --border-hover: #4a4a4a; - --summary-color: #e1e4e8; + --summary-color: #4b72a6; --text-color: #764ba2; } } .faq-container { - font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; max-width: 900px; margin: 20px auto; padding: 20px; @@ -88,4 +88,4 @@ font-size: 0.9375rem; } } -} \ No newline at end of file +} From e1bd11c23aac54da8e0ef814da69ed53c408a29c Mon Sep 17 00:00:00 2001 From: Heisenberg208 Date: Wed, 18 Feb 2026 22:57:07 +0530 Subject: [PATCH 2/2] [RZP-260009]: refactor: enhance CLI command group help text and improve command descriptions --- src/sample/cli.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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()