Skip to content

Commit 10ccbbc

Browse files
committed
feat: comprehensive framework update with enhanced testing, dev tools, and configuration management
- Update README to structured docs approach with focused overview - Remove consolidated DOCUMENTATION_CONSOLIDATION.md file - Add comprehensive development dependencies (pytest plugins, security tools) - Implement enhanced configuration management in main.py - Add monitoring improvements with request tracking and performance stats - Update pyproject.toml with extensive pytest configuration and coverage settings - Add security tools (bandit, safety) and testing infrastructure (tox, pytest-xdist) - Enhanced requirements with development, testing, and security packages - Update uv lockfile with new comprehensive dependency tree - Configure device type enum with string conversion support
1 parent ef6c414 commit 10ccbbc

Some content is hidden

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

52 files changed

+19445
-775
lines changed

.github/workflows/test.yml

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, dev ]
6+
pull_request:
7+
branches: [ main, dev ]
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: [ubuntu-latest, windows-latest, macos-latest]
16+
python-version: ["3.10", "3.11", "3.12"]
17+
include:
18+
# Test with GPU on Ubuntu
19+
- os: ubuntu-latest
20+
python-version: "3.10"
21+
gpu: true
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Install uv
27+
uses: astral-sh/setup-uv@v3
28+
with:
29+
version: "latest"
30+
31+
- name: Set up Python ${{ matrix.python-version }}
32+
run: uv python install ${{ matrix.python-version }}
33+
34+
- name: Install dependencies
35+
run: |
36+
uv sync --extra dev
37+
38+
- name: Download test models
39+
run: |
40+
uv run python tests/models/create_test_models.py
41+
continue-on-error: true
42+
43+
- name: Lint with ruff
44+
run: |
45+
uv run ruff check .
46+
47+
- name: Check formatting with black
48+
run: |
49+
uv run black --check .
50+
51+
- name: Check import sorting with isort
52+
run: |
53+
uv run isort --check-only .
54+
55+
- name: Type check with mypy
56+
run: |
57+
uv run mypy framework
58+
continue-on-error: true
59+
60+
- name: Run unit tests
61+
run: |
62+
uv run pytest tests/unit/ --cov=framework --cov-report=xml --junitxml=junit.xml -v
63+
64+
- name: Run integration tests
65+
run: |
66+
uv run pytest tests/integration/ --cov=framework --cov-append --cov-report=xml --junitxml=junit-integration.xml -v
67+
68+
- name: Run GPU tests
69+
if: matrix.gpu == true
70+
run: |
71+
# Only run if CUDA is available
72+
uv run python -c "import torch; exit(0 if torch.cuda.is_available() else 1)" && \
73+
uv run pytest -m gpu tests/ --cov=framework --cov-append --cov-report=xml -v || \
74+
echo "CUDA not available, skipping GPU tests"
75+
76+
- name: Security scan with bandit
77+
run: |
78+
uv run bandit -r framework -f json -o bandit-report.json
79+
uv run bandit -r framework
80+
continue-on-error: true
81+
82+
- name: Safety check
83+
run: |
84+
uv run safety check --json --output safety-report.json
85+
uv run safety check
86+
continue-on-error: true
87+
88+
- name: Upload coverage to Codecov
89+
uses: codecov/codecov-action@v3
90+
with:
91+
file: ./coverage.xml
92+
flags: unittests
93+
name: codecov-umbrella
94+
fail_ci_if_error: false
95+
96+
benchmark:
97+
runs-on: ubuntu-latest
98+
steps:
99+
- uses: actions/checkout@v4
100+
101+
- name: Install uv
102+
uses: astral-sh/setup-uv@v3
103+
with:
104+
version: "latest"
105+
106+
- name: Set up Python
107+
run: uv python install 3.10
108+
109+
- name: Install dependencies
110+
run: |
111+
uv sync --extra dev
112+
113+
- name: Download test models
114+
run: |
115+
uv run python tests/models/create_test_models.py
116+
continue-on-error: true
117+
118+
- name: Run benchmarks
119+
run: |
120+
uv run pytest -m benchmark --benchmark-only --benchmark-json=benchmark.json tests/
121+
continue-on-error: true
122+
123+
- name: Store benchmark results
124+
uses: benchmark-action/github-action-benchmark@v1
125+
if: github.ref == 'refs/heads/main'
126+
with:
127+
tool: 'pytest'
128+
output-file-path: benchmark.json
129+
github-token: ${{ secrets.GITHUB_TOKEN }}
130+
auto-push: true
131+
132+
docs:
133+
runs-on: ubuntu-latest
134+
steps:
135+
- uses: actions/checkout@v4
136+
137+
- name: Install uv
138+
uses: astral-sh/setup-uv@v3
139+
with:
140+
version: "latest"
141+
142+
- name: Set up Python
143+
run: uv python install 3.10
144+
145+
- name: Install dependencies
146+
run: |
147+
uv sync --extra docs
148+
149+
- name: Build docs
150+
run: |
151+
uv run mkdocs build --strict
152+
153+
- name: Deploy docs to GitHub Pages
154+
if: github.ref == 'refs/heads/main'
155+
run: |
156+
uv run mkdocs gh-deploy --force
157+
158+
docker:
159+
runs-on: ubuntu-latest
160+
steps:
161+
- uses: actions/checkout@v4
162+
163+
- name: Set up Docker Buildx
164+
uses: docker/setup-buildx-action@v3
165+
166+
- name: Build Docker image
167+
uses: docker/build-push-action@v5
168+
with:
169+
context: .
170+
load: true
171+
tags: torch-inference:test
172+
173+
- name: Test in Docker
174+
run: |
175+
docker run --rm torch-inference:test python -m pytest tests/unit/ -v
176+
177+
release:
178+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
179+
needs: [test, benchmark, docs, docker]
180+
runs-on: ubuntu-latest
181+
steps:
182+
- uses: actions/checkout@v4
183+
with:
184+
fetch-depth: 0
185+
186+
- name: Install uv
187+
uses: astral-sh/setup-uv@v3
188+
with:
189+
version: "latest"
190+
191+
- name: Set up Python
192+
run: uv python install 3.10
193+
194+
- name: Install dependencies
195+
run: |
196+
uv sync --extra dev
197+
198+
- name: Build package
199+
run: |
200+
uv build
201+
202+
- name: Check package
203+
run: |
204+
uv run python -m twine check dist/*
205+
206+
- name: Upload to Test PyPI
207+
if: success()
208+
uses: pypa/gh-action-pypi-publish@release/v1
209+
with:
210+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
211+
repository_url: https://test.pypi.org/legacy/
212+
skip_existing: true

.pre-commit-config.yaml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Pre-commit configuration for torch-inference framework
2+
# Runs automated checks before each commit
3+
4+
repos:
5+
# Code formatting
6+
- repo: https://github.com/psf/black
7+
rev: 23.12.1
8+
hooks:
9+
- id: black
10+
language_version: python3
11+
args: [--line-length=88]
12+
13+
# Import sorting
14+
- repo: https://github.com/PyCQA/isort
15+
rev: 5.13.2
16+
hooks:
17+
- id: isort
18+
args: [--profile, black, --line-length=88]
19+
20+
# Linting and code quality
21+
- repo: https://github.com/astral-sh/ruff-pre-commit
22+
rev: v0.1.9
23+
hooks:
24+
- id: ruff
25+
args: [--fix, --exit-non-zero-on-fix]
26+
27+
# Type checking
28+
- repo: https://github.com/pre-commit/mirrors-mypy
29+
rev: v1.8.0
30+
hooks:
31+
- id: mypy
32+
additional_dependencies: [types-requests, types-PyYAML, types-Pillow]
33+
args: [--ignore-missing-imports, --install-types, --non-interactive]
34+
35+
# Security scanning
36+
- repo: https://github.com/PyCQA/bandit
37+
rev: 1.7.5
38+
hooks:
39+
- id: bandit
40+
args: [-r, framework, -f, json, -o, bandit-report.json]
41+
pass_filenames: false
42+
43+
# General pre-commit hooks
44+
- repo: https://github.com/pre-commit/pre-commit-hooks
45+
rev: v4.5.0
46+
hooks:
47+
# Basic file checks
48+
- id: check-added-large-files
49+
args: [--maxkb=1000]
50+
- id: check-case-conflict
51+
- id: check-executables-have-shebangs
52+
- id: check-merge-conflict
53+
- id: check-symlinks
54+
- id: check-toml
55+
- id: check-yaml
56+
args: [--unsafe]
57+
- id: check-json
58+
- id: check-xml
59+
60+
# Python-specific checks
61+
- id: check-ast
62+
- id: check-builtin-literals
63+
- id: check-docstring-first
64+
- id: debug-statements
65+
- id: name-tests-test
66+
args: [--pytest-test-first]
67+
68+
# File cleanup
69+
- id: end-of-file-fixer
70+
- id: trailing-whitespace
71+
args: [--markdown-linebreak-ext=md]
72+
- id: mixed-line-ending
73+
args: [--fix=lf]
74+
75+
# Requirements files
76+
- id: requirements-txt-fixer
77+
78+
# Documentation
79+
- repo: https://github.com/pycqa/pydocstyle
80+
rev: 6.3.0
81+
hooks:
82+
- id: pydocstyle
83+
args: [--convention=google, --add-ignore=D100,D104,D105,D107]
84+
exclude: ^(tests/|examples/)
85+
86+
# Jupyter notebooks (if any)
87+
- repo: https://github.com/nbQA-dev/nbQA
88+
rev: 1.7.1
89+
hooks:
90+
- id: nbqa-black
91+
- id: nbqa-isort
92+
- id: nbqa-ruff
93+
94+
# YAML formatting
95+
- repo: https://github.com/pre-commit/mirrors-prettier
96+
rev: v4.0.0-alpha.8
97+
hooks:
98+
- id: prettier
99+
types_or: [yaml, markdown]
100+
exclude: ^(.*\.md|CHANGELOG\.md)$
101+
102+
# Spell checking (optional, can be disabled)
103+
- repo: https://github.com/crate-ci/typos
104+
rev: v1.16.26
105+
hooks:
106+
- id: typos
107+
exclude: ^(tests/fixtures/|\.git/)
108+
args: [--format, brief]
109+
110+
# Docker
111+
- repo: https://github.com/hadolint/hadolint
112+
rev: v2.12.0
113+
hooks:
114+
- id: hadolint-docker
115+
args: [--ignore, DL3008, --ignore, DL3009]
116+
117+
# Local hooks
118+
- repo: local
119+
hooks:
120+
# Custom pytest hook for fast tests
121+
- id: pytest-fast
122+
name: Run fast tests
123+
entry: uv run pytest
124+
args: [-m, "not slow and not gpu", --tb=short, -q]
125+
language: system
126+
types: [python]
127+
require_serial: true
128+
pass_filenames: false
129+
stages: [pre-push]
130+
131+
# Custom safety check
132+
- id: safety-check
133+
name: Safety dependency scan
134+
entry: uv run safety
135+
args: [check, --short-report]
136+
language: system
137+
pass_filenames: false
138+
stages: [pre-push]
139+
140+
# Custom model validation
141+
- id: validate-test-models
142+
name: Validate test models
143+
entry: uv run python
144+
args: [-c, "from tests.models.model_loader import TestModelLoader; TestModelLoader().validate_models()"]
145+
language: system
146+
pass_filenames: false
147+
stages: [pre-push]
148+
always_run: true
149+
150+
# Configuration
151+
default_stages: [commit]
152+
fail_fast: false
153+
minimum_pre_commit_version: 3.0.0
154+
155+
# CI configuration
156+
ci:
157+
autoupdate_schedule: monthly
158+
autofix_commit_msg: 'style: auto-fix pre-commit hooks'
159+
autoupdate_commit_msg: 'chore: update pre-commit hooks'
160+
skip: [pytest-fast, safety-check, validate-test-models]

0 commit comments

Comments
 (0)