diff --git a/pyproject.toml b/pyproject.toml index 1e04340..c3d3e12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "rz-sample" -version = "1.5.0" +version = "1.5.1" description = "A python boilerplate for fastapi and streamlit projects." authors = ["recursivezero "] license = "MIT" diff --git a/src/sample/cli.py b/src/sample/cli.py index ccf83be..e5492a1 100644 --- a/src/sample/cli.py +++ b/src/sample/cli.py @@ -1,4 +1,5 @@ import click +from sample.utils.constants import PORT, PORT_API from . import __version__ @@ -23,7 +24,10 @@ def cli(ctx, version): @cli.command(help="Run the Sample Streamlit app.") @click.option( - "--port", default=8501, show_default=True, help="Port to run the Streamlit app on." + "--port", + default=int(PORT), + show_default=True, + help="Port to run the Streamlit app on.", ) def dev(port: int): from sample.__main__ import main @@ -34,7 +38,7 @@ def dev(port: int): @cli.command(help="Run the Sample FastAPI backend.") @click.option( "--port", - default=5000, + default=int(PORT_API), show_default=True, help="Port to run the FastAPI backend on.", ) diff --git a/src/sample/utils/constants.py b/src/sample/utils/constants.py index 74d2bd2..60a7813 100644 --- a/src/sample/utils/constants.py +++ b/src/sample/utils/constants.py @@ -7,6 +7,7 @@ load_env() APP_TITLE = ":blue[Greeting Feature]" DEFAULT_GREETING = "Hello" +DEFAULT_PORT = 8501 FAQ_TITLE = "FAQs" logging.basicConfig( @@ -22,7 +23,7 @@ COMPANY_LOGO = ASSETS_DIR / "logo.png" -def safe_get(secret_path: str, env_key: str = "", default: str = "") -> str: +def safe_get(env_key: str = "", default: str = "") -> str: """ Safely retrieve a configuration value from: 1. Streamlit secrets (if secrets.toml exists) @@ -42,7 +43,7 @@ def safe_get(secret_path: str, env_key: str = "", default: str = "") -> str: source = "env" logging.info( - f"Loaded config for '{env_key or secret_path}' from [{source}]", + f"Loaded config for '{env_key}' from [{source}]", extra={"color": "yellow"}, ) return value @@ -50,13 +51,17 @@ def safe_get(secret_path: str, env_key: str = "", default: str = "") -> str: def get_mongo_config(): return { - "MONGODB_URI": safe_get("mongodb.MONGODB_URI", "MONGODB_URI"), - "DATABASE_NAME": safe_get("mongodb.DATABASE_NAME", "DATABASE_NAME"), + "MONGODB_URI": safe_get("MONGODB_URI"), + "DATABASE_NAME": safe_get("DATABASE_NAME"), } +PORT = safe_get("PORT", DEFAULT_PORT) +PORT_API = safe_get("API_PORT", int(PORT) + 1) + + MONGO_CONFIG = get_mongo_config() # === Environment Selection === -ENVIRONMENT = safe_get("env.ENVIRONMENT", "ENVIRONMENT", "development").lower() +ENVIRONMENT = safe_get("ENVIRONMENT", "development").lower() logging.info(f"Environment: {ENVIRONMENT}", extra={"color": "yellow"}) logging.info(f"Project root: {PROJECT_ROOT}", extra={"color": "yellow"})