feat: add pyproject.toml, smoke tests, and Gitea CI workflow
- pyproject.toml: hatchling build, ruff + pytest dev deps, CLI entrypoint - tests/test_smoke.py: import validation for all modules - .gitea/workflows/ci.yaml: lint, test, publish to Gitea PyPI, ntfy notifications - .gitignore: exclude __pycache__
This commit is contained in:
154
.gitea/workflows/ci.yaml
Normal file
154
.gitea/workflows/ci.yaml
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
env:
|
||||||
|
NTFY_URL: http://ntfy.observability.svc.cluster.local:80
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up uv
|
||||||
|
uses: astral-sh/setup-uv@v7
|
||||||
|
with:
|
||||||
|
version: "latest"
|
||||||
|
activate-environment: false
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
run: uv python install 3.13
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: uv sync --frozen --extra dev
|
||||||
|
|
||||||
|
- name: Run ruff check
|
||||||
|
run: uv run ruff check .
|
||||||
|
|
||||||
|
- name: Run ruff format check
|
||||||
|
run: uv run ruff format --check .
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up uv
|
||||||
|
uses: astral-sh/setup-uv@v7
|
||||||
|
with:
|
||||||
|
version: "latest"
|
||||||
|
activate-environment: false
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
run: uv python install 3.13
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: uv sync --frozen --extra dev
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: uv run pytest -v
|
||||||
|
|
||||||
|
publish:
|
||||||
|
name: Publish
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [lint, test]
|
||||||
|
if: gitea.ref == 'refs/heads/main' && gitea.event_name == 'push'
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up uv
|
||||||
|
uses: astral-sh/setup-uv@v7
|
||||||
|
with:
|
||||||
|
version: "latest"
|
||||||
|
activate-environment: false
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
run: uv python install 3.13
|
||||||
|
|
||||||
|
- name: Calculate version
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
LATEST=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
||||||
|
VERSION=${LATEST#v}
|
||||||
|
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
|
||||||
|
|
||||||
|
MSG="${{ gitea.event.head_commit.message }}"
|
||||||
|
if echo "$MSG" | grep -qiE "^major:|BREAKING CHANGE"; then
|
||||||
|
MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0
|
||||||
|
elif echo "$MSG" | grep -qiE "^(minor:|feat:)"; then
|
||||||
|
MINOR=$((MINOR + 1)); PATCH=0
|
||||||
|
else
|
||||||
|
PATCH=$((PATCH + 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
|
||||||
|
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
echo "Bumping $LATEST → v$NEW_VERSION"
|
||||||
|
|
||||||
|
- name: Update version in pyproject.toml
|
||||||
|
run: |
|
||||||
|
sed -i 's/^version = .*/version = "${{ steps.version.outputs.version }}"/' pyproject.toml
|
||||||
|
|
||||||
|
- name: Build package
|
||||||
|
run: uv build
|
||||||
|
|
||||||
|
- name: Publish to Gitea PyPI
|
||||||
|
env:
|
||||||
|
TWINE_USERNAME: ${{ secrets.REGISTRY_USER }}
|
||||||
|
TWINE_PASSWORD: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
TWINE_REPOSITORY_URL: http://gitea-http.gitea.svc.cluster.local:3000/api/packages/daviestechlabs/pypi
|
||||||
|
run: |
|
||||||
|
uv pip install twine --system
|
||||||
|
twine upload --verbose dist/*
|
||||||
|
|
||||||
|
- name: Create and push tag
|
||||||
|
run: |
|
||||||
|
git config user.name "gitea-actions[bot]"
|
||||||
|
git config user.email "actions@git.daviestechlabs.io"
|
||||||
|
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
|
||||||
|
git push origin "v${{ steps.version.outputs.version }}"
|
||||||
|
|
||||||
|
notify:
|
||||||
|
name: Notify
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [lint, test, publish]
|
||||||
|
if: always()
|
||||||
|
steps:
|
||||||
|
- name: Notify on success
|
||||||
|
if: needs.lint.result == 'success' && needs.test.result == 'success'
|
||||||
|
run: |
|
||||||
|
curl -s \
|
||||||
|
-H "Title: ✅ CI Passed: ${{ gitea.repository }}" \
|
||||||
|
-H "Priority: default" \
|
||||||
|
-H "Tags: white_check_mark,package" \
|
||||||
|
-H "Click: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
||||||
|
-d "Branch: ${{ gitea.ref_name }}
|
||||||
|
Commit: ${{ gitea.event.head_commit.message || gitea.sha }}
|
||||||
|
Publish: ${{ needs.publish.result == 'success' && 'published' || 'skipped' }}" \
|
||||||
|
${{ env.NTFY_URL }}/gitea-ci
|
||||||
|
|
||||||
|
- name: Notify on failure
|
||||||
|
if: needs.lint.result == 'failure' || needs.test.result == 'failure'
|
||||||
|
run: |
|
||||||
|
curl -s \
|
||||||
|
-H "Title: ❌ CI Failed: ${{ gitea.repository }}" \
|
||||||
|
-H "Priority: high" \
|
||||||
|
-H "Tags: x,package" \
|
||||||
|
-H "Click: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
||||||
|
-d "Branch: ${{ gitea.ref_name }}
|
||||||
|
Commit: ${{ gitea.event.head_commit.message || gitea.sha }}
|
||||||
|
Lint: ${{ needs.lint.result }}
|
||||||
|
Test: ${{ needs.test.result }}" \
|
||||||
|
${{ env.NTFY_URL }}/gitea-ci
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
39
pyproject.toml
Normal file
39
pyproject.toml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "mlflow-utils"
|
||||||
|
version = "1.0.0"
|
||||||
|
description = "MLflow integration utilities for LLM Workflows"
|
||||||
|
readme = "README.md"
|
||||||
|
license = "MIT"
|
||||||
|
requires-python = ">=3.11"
|
||||||
|
dependencies = [
|
||||||
|
"mlflow>=2.10.0",
|
||||||
|
"psycopg2-binary>=2.9.0",
|
||||||
|
"boto3>=1.34.0",
|
||||||
|
"aiohttp>=3.9.0",
|
||||||
|
"PyYAML>=6.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
dev = [
|
||||||
|
"ruff>=0.9.0",
|
||||||
|
"pytest>=8.0",
|
||||||
|
"pytest-asyncio>=0.24.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
mlflow-utils = "mlflow_utils.cli:main"
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
target-version = "py311"
|
||||||
|
line-length = 120
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = ["E", "F", "I", "W"]
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
testpaths = ["tests"]
|
||||||
|
asyncio_mode = "auto"
|
||||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
59
tests/test_smoke.py
Normal file
59
tests/test_smoke.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
"""Smoke tests for mlflow_utils package."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_imports() -> None:
|
||||||
|
"""All public symbols are importable."""
|
||||||
|
from mlflow_utils import ( # noqa: F401
|
||||||
|
MLflowConfig,
|
||||||
|
MLflowTracker,
|
||||||
|
InferenceMetricsTracker,
|
||||||
|
get_mlflow_client,
|
||||||
|
get_tracking_uri,
|
||||||
|
ensure_experiment,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_version() -> None:
|
||||||
|
import mlflow_utils
|
||||||
|
|
||||||
|
assert mlflow_utils.__version__
|
||||||
|
|
||||||
|
|
||||||
|
def test_mlflow_config_defaults() -> None:
|
||||||
|
from mlflow_utils.client import MLflowConfig
|
||||||
|
|
||||||
|
cfg = MLflowConfig()
|
||||||
|
assert "mlflow" in cfg.tracking_uri
|
||||||
|
assert cfg.tracking_uri.startswith("http")
|
||||||
|
|
||||||
|
|
||||||
|
def test_cli_entrypoint() -> None:
|
||||||
|
"""CLI main function exists and is callable."""
|
||||||
|
from mlflow_utils.cli import main
|
||||||
|
|
||||||
|
assert callable(main)
|
||||||
|
|
||||||
|
|
||||||
|
def test_kfp_components_importable() -> None:
|
||||||
|
kfp = pytest.importorskip("kfp") # noqa: F841
|
||||||
|
from mlflow_utils.kfp_components import ( # noqa: F401
|
||||||
|
create_mlflow_run,
|
||||||
|
log_metrics_component,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_model_registry_importable() -> None:
|
||||||
|
from mlflow_utils.model_registry import ( # noqa: F401
|
||||||
|
register_model_for_kserve,
|
||||||
|
generate_kserve_manifest,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_experiment_comparison_importable() -> None:
|
||||||
|
from mlflow_utils.experiment_comparison import ( # noqa: F401
|
||||||
|
ExperimentAnalyzer,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user