Skip to content

Commit 75f8c84

Browse files
Merge pull request #14 from recursivezero/feature/SAM-260013
Feature/sam 260013: Publishing package PYPi
2 parents 59028c9 + d2a7bd9 commit 75f8c84

6 files changed

Lines changed: 158 additions & 42 deletions

File tree

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.PHONY: install lint format type test run api clean
2+
3+
PORT ?= 8501
4+
install:
5+
poetry install
6+
7+
lint:
8+
poetry run ruff check .
9+
poetry run black --check .
10+
poetry run mypy .
11+
12+
hooks:
13+
poetry run scripts/setup-hooks.sh
14+
15+
format:
16+
poetry run black .
17+
poetry run ruff check --fix .
18+
19+
type:
20+
poetry run mypy .
21+
22+
23+
dev:
24+
poetry run sample dev --port $(PORT)
25+
26+
api:
27+
poetry run sample api
28+
29+
clean:
30+
find . -type d -name "__pycache__" -exec rm -rf {} +
31+
rm -rf .pytest_cache .mypy_cache dist build

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ poetry install --all-extras --with dev
4545
Or manually
4646

4747
```bash
48-
poetry install
48+
make install
4949
```
5050

5151
## How to Run
@@ -64,17 +64,20 @@ setup `.env.development` and `.env.production` in project root
6464
## Run Streamlit App
6565

6666
```bash
67+
make dev
68+
#or
6769
poetry run sample dev
70+
6871
```
6972

7073
Access: <http://localhost:8501>
7174

7275
## Run FastAPI Server
7376

7477
```bash
78+
make api
79+
#OR
7580
poetry run sample api
76-
# OR
77-
python src/api/fast_api.py
7881
```
7982

8083
Access: <http://127.0.0.1:5000>
@@ -84,7 +87,7 @@ Access: <http://127.0.0.1:5000>
8487
Pre-commit hooks are enabled. If commits fail, run:
8588

8689
```bash
87-
poetry run lint
90+
make lint
8891
```
8992

9093
or run individual
@@ -101,6 +104,7 @@ poetry run ruff check .
101104
## Build Package
102105

103106
```bash
107+
104108
poetry clean
105109
poetry build
106110
```
@@ -146,7 +150,7 @@ these hooks will
146150

147151
```bash
148152
# Install git hooks
149-
poetry run ./scripts/setup-hooks.sh
153+
make hooks
150154
```
151155

152156
there is `.vscode/Python.code-profile` file; import this as a profile in vscode which include necessary extension for python development.

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.")

src/sample/utils/lint.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

templates/faq.html

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,109 @@ <h1>Frequently Asked Questions</h1>
3030
<p>This is a useful to start the development with pre-defined template and best practices and define folder
3131
structure.</p>
3232
</details>
33-
</div>
33+
</div>
34+
<div id="technical-faq" class="faq-container">
35+
<h1>Technical FAQ</h1>
36+
37+
<details>
38+
<summary>Which Python version is supported?</summary>
39+
<p>
40+
Python ≥ 3.11 is required. Verify using:
41+
</p>
42+
<pre><code>python --version</code></pre>
43+
</details>
44+
45+
<details>
46+
<summary>How do I install dependencies?</summary>
47+
<p>
48+
Use the Makefile command:
49+
</p>
50+
<pre><code>make install</code></pre>
51+
<p>
52+
This runs <code>poetry install</code> internally.
53+
</p>
54+
</details>
55+
56+
<details>
57+
<summary>How do I run the Streamlit app?</summary>
58+
<pre><code>make dev</code></pre>
59+
<p>
60+
This executes <code>poetry run sample dev</code>.
61+
</p>
62+
</details>
63+
64+
<details>
65+
<summary>How do I run the FastAPI server?</summary>
66+
<pre><code>make api</code></pre>
67+
<p>
68+
This executes <code>poetry run sample api</code>.
69+
</p>
70+
</details>
71+
72+
<details>
73+
<summary>How do I run linting and type checks?</summary>
74+
<pre><code>make lint</code></pre>
75+
<p>
76+
This runs ruff, black (check mode), and mypy.
77+
</p>
78+
</details>
79+
80+
<details>
81+
<summary>How do I auto-format the code?</summary>
82+
<pre><code>make format</code></pre>
83+
<p>
84+
This runs black and ruff with auto-fix enabled.
85+
</p>
86+
</details>
87+
88+
89+
<details>
90+
<summary>How do I clean cache and build artifacts?</summary>
91+
<pre><code>make clean</code></pre>
92+
<p>
93+
This removes __pycache__, mypy cache, pytest cache, and build artifacts.
94+
</p>
95+
</details>
96+
97+
<details>
98+
<summary>Where is the virtual environment created?</summary>
99+
<p>
100+
Poetry manages the virtual environment automatically.
101+
To inspect:
102+
</p>
103+
<pre><code>poetry env info</code></pre>
104+
</details>
105+
106+
<details>
107+
<summary>When should I regenerate poetry.lock?</summary>
108+
<p>
109+
Only when adding or upgrading dependencies.
110+
</p>
111+
<pre><code>poetry lock --no-cache --regenerate</code></pre>
112+
<p>
113+
Avoid unnecessary lock file changes in pull requests.
114+
</p>
115+
</details>
116+
117+
<details>
118+
<summary>What if pymongo is not found?</summary>
119+
<p>
120+
MongoDB support is an optional extra dependency.
121+
Install using:
122+
</p>
123+
<pre><code>pip install sample[mongo]</code></pre>
124+
<p>
125+
If using Poetry:
126+
</p>
127+
<pre><code>poetry install --extras "mongo"</code></pre>
128+
</details>
129+
130+
<details>
131+
<summary>Are secrets allowed inside the repository?</summary>
132+
<p>
133+
No. Never commit secrets. Use environment variables or external secret managers.
134+
Maintain a <code>.env.example</code> file for documentation purposes.
135+
</p>
136+
</details>
137+
138+
</div>

0 commit comments

Comments
 (0)