Skip to content

Commit d2a7bd9

Browse files
committed
[SAM-260013]: feat: enhance Streamlit app command with port option and update main function to accept port parameter
1 parent f4b75ee commit d2a7bd9

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.PHONY: install lint format type test run api clean
22

3+
PORT ?= 8501
34
install:
45
poetry install
56

@@ -20,7 +21,7 @@ type:
2021

2122

2223
dev:
23-
poetry run sample dev
24+
poetry run sample dev --port $(PORT)
2425

2526
api:
2627
poetry run sample api

src/sample/__main__.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,33 @@
88
from . import __version__
99

1010

11-
def main():
11+
def main(port: int = 8501):
1212
"""
1313
Entrypoint for the Streamlit 'dev' app.
1414
"""
1515
print("🏷️ Sample version:", __version__)
1616
logging.info("Starting sample dev script...")
1717

18-
# Paths
1918
Sample_dir = Path(__file__).resolve().parent
20-
dev_root = Sample_dir.parent # src/
21-
wheel_root = Sample_dir.parent # same in wheel
19+
dev_root = Sample_dir.parent
20+
wheel_root = Sample_dir.parent
2221

23-
# Add correct root to sys.path
24-
if "site-packages" in str(Sample_dir): # running from wheel
22+
if "site-packages" in str(Sample_dir):
2523
if str(wheel_root) not in sys.path:
2624
sys.path.append(str(wheel_root))
2725
logging.info(f"Added wheel root to sys.path: {wheel_root}")
28-
else: # dev mode
26+
else:
2927
if str(dev_root) not in sys.path:
3028
sys.path.append(str(dev_root))
3129
logging.info(f"Added dev src root to sys.path: {dev_root}")
3230

33-
# Locate streamlit_app.py
3431
streamlit_app_path = Sample_dir / "streamlit_app.py"
3532
logging.info(f"Streamlit app path: {streamlit_app_path}")
3633

3734
if not streamlit_app_path.exists():
3835
logging.error(f"Streamlit app not found at: {streamlit_app_path}")
3936
return
4037

41-
# Run Streamlit app
4238
python_path = sys.executable
4339
logging.info(f"Using Python executable: {python_path}")
4440

@@ -50,11 +46,11 @@ def main():
5046
"run",
5147
str(streamlit_app_path.resolve()),
5248
"--server.port",
53-
"8501",
49+
str(port),
5450
],
5551
check=True,
5652
)
5753

5854

5955
if __name__ == "__main__":
60-
main()
56+
main(port=8501)

src/sample/cli.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ def cli(ctx, version):
2222

2323

2424
@cli.command(help="Run the Sample Streamlit app.")
25-
def dev():
25+
@click.option(
26+
"--port", default=8501, show_default=True, help="Port to run the Streamlit app on."
27+
)
28+
def dev(port: int):
2629
from sample.__main__ import main
2730

28-
main()
31+
main(port)
2932

3033

3134
@cli.command(help="Run the Sample FastAPI backend.")

0 commit comments

Comments
 (0)