Skip to content

Commit d848ad0

Browse files
committed
[SAM-260015]: feat: add port option for FastAPI and Streamlit commands in Makefile and CLI
1 parent d2a7bd9 commit d848ad0

4 files changed

Lines changed: 19 additions & 12 deletions

File tree

Makefile

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

33
PORT ?= 8501
4+
PORT_API ?= 5000
45
install:
56
poetry install
67

@@ -24,7 +25,7 @@ dev:
2425
poetry run sample dev --port $(PORT)
2526

2627
api:
27-
poetry run sample api
28+
poetry run sample api --port $(PORT_API)
2829

2930
clean:
3031
find . -type d -name "__pycache__" -exec rm -rf {} +

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ setup `.env.development` and `.env.production` in project root
6565

6666
```bash
6767
make dev
68-
#or
69-
poetry run sample dev
68+
#or with custom port
69+
poetry run sample dev --port 8051
7070

7171
```
7272

@@ -76,8 +76,8 @@ Access: <http://localhost:8501>
7676

7777
```bash
7878
make api
79-
#OR
80-
poetry run sample api
79+
#OR with custom port
80+
poetry run sample api --port 5000
8181
```
8282

8383
Access: <http://127.0.0.1:5000>
@@ -134,9 +134,9 @@ pip install sample
134134

135135
## CLI Shortcuts
136136

137-
`sample dev` → Launch Streamlit UI
137+
`make dev` → Launch Streamlit UI
138138

139-
`sample api` → Launch FastAPI
139+
`make api` → Launch FastAPI
140140

141141
current version will be printed on start of above commands.
142142

src/sample/api/fast_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def greet_user(payload: GreetRequest):
102102
app.include_router(greet_router)
103103

104104

105-
def start():
105+
def start(port: int = 5000):
106106
import uvicorn
107107

108108
print(f"🧵 {__version__}\n")
@@ -112,8 +112,8 @@ def start():
112112
print(
113113
"⚠️ Could not connect to the database.Please check database configuration."
114114
)
115-
uvicorn.run("sample.api.fast_api:app", host="127.0.0.1", port=5000, reload=True)
115+
uvicorn.run("sample.api.fast_api:app", host="127.0.0.1", port=port, reload=True)
116116

117117

118118
if __name__ == "__main__":
119-
start()
119+
start(port=5000)

src/sample/cli.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ def dev(port: int):
3232

3333

3434
@cli.command(help="Run the Sample FastAPI backend.")
35-
def api():
35+
@click.option(
36+
"--port",
37+
default=5000,
38+
show_default=True,
39+
help="Port to run the FastAPI backend on.",
40+
)
41+
def api(port: int):
3642
from sample.api.fast_api import start
3743

38-
start()
44+
start(port)

0 commit comments

Comments
 (0)