Skip to content

Commit bec4538

Browse files
committed
[SAM-260015]: feat: update version to 1.5.1 and refactor port handling in CLI and constants
1 parent 8de0500 commit bec4538

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "rz-sample"
3-
version = "1.5.0"
3+
version = "1.5.1"
44
description = "A python boilerplate for fastapi and streamlit projects."
55
authors = ["recursivezero <recursivezero@outlook.com>"]
66
license = "MIT"

src/sample/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import click
2+
from sample.utils.constants import PORT, PORT_API
23

34
from . import __version__
45

@@ -23,7 +24,10 @@ def cli(ctx, version):
2324

2425
@cli.command(help="Run the Sample Streamlit app.")
2526
@click.option(
26-
"--port", default=8501, show_default=True, help="Port to run the Streamlit app on."
27+
"--port",
28+
default=int(PORT),
29+
show_default=True,
30+
help="Port to run the Streamlit app on.",
2731
)
2832
def dev(port: int):
2933
from sample.__main__ import main
@@ -34,7 +38,7 @@ def dev(port: int):
3438
@cli.command(help="Run the Sample FastAPI backend.")
3539
@click.option(
3640
"--port",
37-
default=5000,
41+
default=int(PORT_API),
3842
show_default=True,
3943
help="Port to run the FastAPI backend on.",
4044
)

src/sample/utils/constants.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
load_env()
88
APP_TITLE = ":blue[Greeting Feature]"
99
DEFAULT_GREETING = "Hello"
10+
DEFAULT_PORT = 8501
1011
FAQ_TITLE = "FAQs"
1112

1213
logging.basicConfig(
@@ -22,7 +23,7 @@
2223
COMPANY_LOGO = ASSETS_DIR / "logo.png"
2324

2425

25-
def safe_get(secret_path: str, env_key: str = "", default: str = "") -> str:
26+
def safe_get(env_key: str = "", default: str = "") -> str:
2627
"""
2728
Safely retrieve a configuration value from:
2829
1. Streamlit secrets (if secrets.toml exists)
@@ -42,21 +43,25 @@ def safe_get(secret_path: str, env_key: str = "", default: str = "") -> str:
4243
source = "env"
4344

4445
logging.info(
45-
f"Loaded config for '{env_key or secret_path}' from [{source}]",
46+
f"Loaded config for '{env_key}' from [{source}]",
4647
extra={"color": "yellow"},
4748
)
4849
return value
4950

5051

5152
def get_mongo_config():
5253
return {
53-
"MONGODB_URI": safe_get("mongodb.MONGODB_URI", "MONGODB_URI"),
54-
"DATABASE_NAME": safe_get("mongodb.DATABASE_NAME", "DATABASE_NAME"),
54+
"MONGODB_URI": safe_get("MONGODB_URI"),
55+
"DATABASE_NAME": safe_get("DATABASE_NAME"),
5556
}
5657

5758

59+
PORT = safe_get("PORT", DEFAULT_PORT)
60+
PORT_API = safe_get("API_PORT", int(PORT) + 1)
61+
62+
5863
MONGO_CONFIG = get_mongo_config()
5964
# === Environment Selection ===
60-
ENVIRONMENT = safe_get("env.ENVIRONMENT", "ENVIRONMENT", "development").lower()
65+
ENVIRONMENT = safe_get("ENVIRONMENT", "development").lower()
6166
logging.info(f"Environment: {ENVIRONMENT}", extra={"color": "yellow"})
6267
logging.info(f"Project root: {PROJECT_ROOT}", extra={"color": "yellow"})

0 commit comments

Comments
 (0)