Skip to content

Commit a77cdaf

Browse files
authored
Merge pull request #2 from MehrazRumman/wip
Updateing folder structure
2 parents 2dc924d + daa5810 commit a77cdaf

59 files changed

Lines changed: 2970 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

8 KB
Binary file not shown.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python3
2+
from __future__ import annotations
3+
4+
import sys
5+
import xml.etree.ElementTree as ET
6+
from pathlib import Path
7+
8+
9+
def pick_color(percent: int) -> str:
10+
if percent >= 90:
11+
return "#4c1" # brightgreen
12+
if percent >= 80:
13+
return "#97CA00" # green
14+
if percent >= 70:
15+
return "#a4a61d" # yellowgreen
16+
if percent >= 60:
17+
return "#dfb317" # yellow
18+
if percent >= 50:
19+
return "#fe7d37" # orange
20+
return "#e05d44" # red
21+
22+
23+
def text_width(text: str) -> int:
24+
# Approximate width for 11px sans-serif shields-style text.
25+
return max(20, len(text) * 7 + 10)
26+
27+
28+
def make_badge(label: str, value: str, color: str) -> str:
29+
left = text_width(label)
30+
right = text_width(value)
31+
total = left + right
32+
left_center = left / 2
33+
right_center = left + right / 2
34+
35+
return f"""<svg xmlns="http://www.w3.org/2000/svg" width="{total}" height="20" role="img" aria-label="{label}: {value}">
36+
<title>{label}: {value}</title>
37+
<linearGradient id="s" x2="0" y2="100%">
38+
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
39+
<stop offset="1" stop-opacity=".1"/>
40+
</linearGradient>
41+
<mask id="m">
42+
<rect width="{total}" height="20" rx="3" fill="#fff"/>
43+
</mask>
44+
<g mask="url(#m)">
45+
<rect width="{left}" height="20" fill="#555"/>
46+
<rect x="{left}" width="{right}" height="20" fill="{color}"/>
47+
<rect width="{total}" height="20" fill="url(#s)"/>
48+
</g>
49+
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" text-rendering="geometricPrecision" font-size="11">
50+
<text x="{left_center}" y="15" fill="#010101" fill-opacity=".3">{label}</text>
51+
<text x="{left_center}" y="14">{label}</text>
52+
<text x="{right_center}" y="15" fill="#010101" fill-opacity=".3">{value}</text>
53+
<text x="{right_center}" y="14">{value}</text>
54+
</g>
55+
</svg>
56+
"""
57+
58+
59+
def main() -> int:
60+
if len(sys.argv) != 3:
61+
print("Usage: generate_coverage_badge.py <coverage.xml> <output.svg>")
62+
return 2
63+
64+
coverage_xml = Path(sys.argv[1])
65+
output_svg = Path(sys.argv[2])
66+
67+
tree = ET.parse(coverage_xml)
68+
root = tree.getroot()
69+
line_rate = root.attrib.get("line-rate")
70+
if line_rate is None:
71+
raise ValueError("coverage.xml missing line-rate attribute")
72+
73+
percent = round(float(line_rate) * 100)
74+
badge = make_badge("coverage", f"{percent}%", pick_color(percent))
75+
output_svg.write_text(badge, encoding="utf-8")
76+
print(f"Wrote badge: {output_svg} ({percent}%)")
77+
return 0
78+
79+
80+
if __name__ == "__main__":
81+
raise SystemExit(main())
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Coverage Badge
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
paths-ignore:
7+
- "assets/coverage.svg"
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
badge:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.12"
24+
cache: "pip"
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install -e ".[test]"
30+
31+
- name: Run tests with coverage
32+
run: |
33+
pytest -q --cov=fastapi_observer --cov-report=term-missing --cov-report=xml
34+
35+
- name: Generate coverage badge
36+
run: |
37+
mkdir -p assets
38+
python .github/scripts/generate_coverage_badge.py coverage.xml assets/coverage.svg
39+
40+
- name: Commit updated badge
41+
uses: stefanzweifel/git-auto-commit-action@v5
42+
with:
43+
commit_message: "chore(ci): update coverage badge [skip ci]"
44+
file_pattern: assets/coverage.svg

.github/workflows/docs.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
paths:
6+
- "docs/**"
7+
- "mkdocs.yml"
8+
- "README.md"
9+
- "pyproject.toml"
10+
- ".github/workflows/docs.yml"
11+
pull_request:
12+
paths:
13+
- "docs/**"
14+
- "mkdocs.yml"
15+
- "README.md"
16+
- "pyproject.toml"
17+
- ".github/workflows/docs.yml"
18+
19+
jobs:
20+
docs-check:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.12"
30+
cache: "pip"
31+
32+
- name: Install docs dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
python -m pip install -e ".[docs]"
36+
37+
- name: Build docs
38+
run: |
39+
mkdocs build --strict

.github/workflows/publish.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.12"
23+
24+
- name: Build package
25+
run: |
26+
python -m pip install --upgrade pip build twine
27+
python -m build
28+
python -m twine check dist/*
29+
30+
- name: Upload dist artifacts
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: dist
34+
path: dist/*
35+
36+
publish:
37+
needs: build
38+
if: startsWith(github.ref, 'refs/tags/v')
39+
runs-on: ubuntu-latest
40+
permissions:
41+
id-token: write
42+
contents: read
43+
environment:
44+
name: pypi
45+
steps:
46+
- name: Download dist artifacts
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: dist
50+
path: dist
51+
52+
- name: Publish to PyPI
53+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/tests.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
tox:
12+
name: Python ${{ matrix.python-version }} / ${{ matrix.toxenv }}
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- python-version: "3.10"
19+
toxenv: py310
20+
- python-version: "3.11"
21+
toxenv: py311
22+
- python-version: "3.12"
23+
toxenv: py312
24+
- python-version: "3.13"
25+
toxenv: py313
26+
- python-version: "3.14"
27+
toxenv: py314
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
cache: "pip"
38+
39+
- name: Install tox
40+
run: python -m pip install --upgrade pip tox
41+
42+
- name: Run tests via tox
43+
run: tox -e ${{ matrix.toxenv }}
44+
45+
- name: Upload coverage artifact
46+
if: always()
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: coverage-${{ matrix.python-version }}
50+
path: coverage.xml
51+
if-no-files-found: ignore

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ cython_debug/
182182
.abstra/
183183

184184
# Visual Studio Code
185-
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
185+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186186
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187-
# and can be added to the global gitignore or merged into this file. However, if you prefer,
187+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
188188
# you could uncomment the following to ignore the entire vscode folder
189189
# .vscode/
190190

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-toml
9+
- id: check-merge-conflict
10+
11+
- repo: https://github.com/psf/black
12+
rev: 24.10.0
13+
hooks:
14+
- id: black

CONTRIBUTING.md

Whitespace-only changes.

README.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
11
# fastapi-observer
2-
FastApi Logs visualization
2+
3+
FastAPI Observer provides structured logging and observability helpers for FastAPI applications.
4+
5+
[![Test](https://github.com/MehrazRumman/fastapi-observer/actions/workflows/tests.yml/badge.svg)](https://github.com/MehrazRumman/fastapi-observer/actions/workflows/tests.yml)
6+
[![coverage](assets/coverage.svg)](https://github.com/MehrazRumman/fastapi-observer/actions/workflows/coverage-badge.yml)
7+
[![pypi package](https://img.shields.io/pypi/v/fastapi-observer?logo=pypi&label=pypi%20package)](https://pypi.org/project/fastapi-observer/)
8+
[![python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-brightgreen?logo=python&logoColor=white)](#python-compatibility)
9+
10+
## Python compatibility
11+
12+
- Supported Python versions: `3.10`, `3.11`, `3.12`, `3.13`, `3.14`
13+
- Enforced in CI with tox matrix: `py310`, `py311`, `py312`, `py313`, `py314`
14+
15+
## Package versions
16+
17+
### Runtime
18+
19+
- `pydantic>=2.0,<3.0`
20+
21+
### Testing
22+
23+
- `pytest>=8.0`
24+
- `pytest-cov>=5.0`
25+
26+
### Documentation
27+
28+
- `mkdocs>=1.6`
29+
- `mkdocs-material>=9.5`
30+
31+
### Development
32+
33+
- `pre-commit>=3.7`
34+
- `black>=24.10`
35+
36+
## Install
37+
38+
```bash
39+
pip install fastapi-observer
40+
```
41+
42+
For development:
43+
44+
```bash
45+
pip install -e ".[test,docs,dev]"
46+
```
47+
48+
## Tests and coverage
49+
50+
Run tests:
51+
52+
```bash
53+
pytest -q
54+
```
55+
56+
Run tests with coverage:
57+
58+
```bash
59+
pytest -q --cov=fastapi_observer --cov-report=term-missing --cov-report=xml
60+
```
61+
62+
Run full Python version matrix locally:
63+
64+
```bash
65+
tox
66+
```
67+
68+
## Docs
69+
70+
Build docs:
71+
72+
```bash
73+
mkdocs build --strict
74+
```
75+
76+
Serve docs locally:
77+
78+
```bash
79+
mkdocs serve
80+
```

0 commit comments

Comments
 (0)