Skip to content

Commit 64fbd52

Browse files
author
Manus AI
committed
feat: Implement quick wins for python-backend documentation and CI
1 parent 80fbbb6 commit 64fbd52

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ jobs:
6161
run: |
6262
python -m pip install --upgrade pip
6363
pip install -r requirements-dev.txt
64+
pip install pytest-cov
6465
6566
- name: Run pytest
66-
run: pytest -v --tb=short
67+
run: pytest -v --tb=short --cov=app --cov-report=xml --cov-report=html --cov-report=term-missing
6768

6869
typecheck:
6970
name: Type check (mypy)
@@ -86,7 +87,7 @@ jobs:
8687
pip install -r requirements-dev.txt
8788
8889
- name: Run mypy
89-
run: mypy app tests || true # non-blocking until types are fully clean
90+
run: mypy app tests
9091

9192
security:
9293
name: Security scan (pip-audit)

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-261230?style=flat-square)](https://docs.astral.sh/ruff/)
88
[![GitHub release](https://img.shields.io/github/v/release/mohit-tanwar-dev/python-backend?style=flat-square)](https://github.com/mohit-tanwar-dev/python-backend/releases)
99

10+
[![Code Coverage](https://img.shields.io/badge/coverage-XX%25-red?style=flat-square)](./htmlcov/index.html)
11+
1012
FastAPI scaffold with health endpoint, structured logging, env-driven config, pytest suite, ruff/mypy, and GitHub Actions CI.
1113

1214
## Stack
@@ -49,6 +51,27 @@ python-backend/
4951
└── SECURITY.md
5052
```
5153

54+
## Development Workflow
55+
56+
For local development, it's recommended to use a virtual environment. The project uses `ruff` for linting and formatting, and `mypy` for type checking. `pre-commit` hooks are configured to ensure code quality before commits.
57+
58+
### Local Setup
59+
60+
```bash
61+
# Install pre-commit hooks
62+
pre-commit install
63+
```
64+
65+
### Running Linters and Type Checks
66+
67+
```bash
68+
ruff check .
69+
ruff format --check .
70+
mypy app tests
71+
```
72+
73+
These checks are also run in the CI pipeline.
74+
5275
## Quick start
5376

5477
```bash
@@ -75,6 +98,26 @@ docker build -t python-backend:latest .
7598
docker run --rm -p 8000:8000 --env-file .env python-backend:latest
7699
```
77100

101+
## Production Deployment
102+
103+
For production deployments, it is recommended to use a production-ready ASGI server like Gunicorn with Uvicorn workers. Below are examples for running the application in a production environment.
104+
105+
### Gunicorn with Uvicorn Workers
106+
107+
```bash
108+
gunicorn -w 4 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:8000
109+
```
110+
111+
This command starts Gunicorn with 4 Uvicorn worker processes, binding to all network interfaces on port 8000.
112+
113+
### Health Check Path
114+
115+
The application provides a health check endpoint at `/health` (or `/api/v1/health` for the versioned API) that can be used by load balancers or container orchestration systems to verify the application's status.
116+
117+
## Logging Configuration
118+
119+
The application uses structured logging, configured via `app/core/logging.py`. The log level can be controlled using the `APP_LOG_LEVEL` environment variable (e.g., `INFO`, `DEBUG`, `WARNING`, `ERROR`). Logs are typically output to `stdout` and `stderr`, making them suitable for containerized environments and centralized logging solutions.
120+
78121
## Configuration
79122

80123
Settings loaded from environment variables or `.env`. All have defaults.
@@ -103,6 +146,10 @@ CI runs all of the above on Python 3.11 and 3.12.
103146

104147
See [CONTRIBUTING.md](CONTRIBUTING.md). Fork, branch from `main`, open a PR.
105148

149+
## Release Process
150+
151+
Releases are managed via GitHub releases. A new release can be cut by creating a new tag (e.g., `v1.0.0`). The CI/CD pipeline is configured to automatically build and publish artifacts upon a new tag. Changelog conventions are maintained in `CHANGELOG.md`.
152+
106153
## Changelog
107154

108155
See [CHANGELOG.md](CHANGELOG.md).

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ python_classes = Test*
55
python_functions = test_*
66
asyncio_mode = auto
77
addopts = -v --tb=short --strict-markers
8+
9+
[pytest-cov]
10+
addopts = --cov=app --cov-report=xml --cov-report=html --cov-report=term-missing

0 commit comments

Comments
 (0)