mirror of
https://github.com/tiennm99/litellm.git
synced 2026-06-28 05:08:21 +00:00
18f4b7219b
* feat: add faster linting targets for development workflow - Add lint-dev target that only checks changed files vs origin/main - Add lint-format-changed to format only modified Python lines - Add lint-ruff-dev using diff-quality for incremental lint checks - Upgrade ruff from 0.1.x to 0.2.x for --range formatting support - Add pylint and diff-cover as dev dependencies - Use portable PIP variable for cross-platform compatibility - Suppress poetry warnings in install-dev target * fix(mypy): fix type: ignore placement for OTEL LogRecord import The type: ignore[attr-defined] comment was on the import alias line inside parentheses, but mypy reports the error on the `from` line. Collapse to single-line imports so the suppression is on the correct line. Also add no-redef to the fallback branch. * fix: address review issues in faster linting PR - Remove poetry lock/check from install-dev (slow, can mutate lockfile) - Remove misplaced [virtualenvs] and [installer] from pyproject.toml (these belong in poetry.toml, not project metadata) - Remove unused pylint dev dependency (diff-quality uses pylint output format, not the pylint package itself) - Fix trailing whitespace in .PHONY declaration - Use mktemp instead of hardcoded /tmp/ruff.txt in lint-ruff-dev - Guard lint-ruff-FULL-dev against empty file list from git diff - Fix incorrect comment on lint-dev target - Regenerate poetry.lock Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: address review issues in faster linting PR - Remove poetry lock/check from install-dev (slow, can mutate lockfile) - Remove misplaced [virtualenvs] and [installer] from pyproject.toml (these belong in poetry.toml, not project metadata) - Remove unused pylint dev dependency (diff-quality uses pylint output format, not the pylint package itself) - Fix trailing whitespace in .PHONY declaration - Use mktemp instead of hardcoded /tmp/ruff.txt in lint-ruff-dev - Guard lint-ruff-FULL-dev against empty file list from git diff - Fix incorrect comment on lint-dev target - Regenerate poetry.lock --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
150 lines
5.5 KiB
Makefile
150 lines
5.5 KiB
Makefile
# LiteLLM Makefile
|
|
# Simple Makefile for running tests and basic development tasks
|
|
|
|
.PHONY: help test test-unit test-integration test-unit-helm \
|
|
info lint lint-dev format \
|
|
install-dev install-proxy-dev install-test-deps \
|
|
install-helm-unittest check-circular-imports check-import-safety
|
|
|
|
# Default target
|
|
help:
|
|
@echo "Available commands:"
|
|
@echo " make install-dev - Install development dependencies"
|
|
@echo " make install-proxy-dev - Install proxy development dependencies"
|
|
@echo " make install-dev-ci - Install dev dependencies (CI-compatible, pins OpenAI)"
|
|
@echo " make install-proxy-dev-ci - Install proxy dev dependencies (CI-compatible)"
|
|
@echo " make install-test-deps - Install test dependencies"
|
|
@echo " make install-helm-unittest - Install helm unittest plugin"
|
|
@echo " make format - Apply Black code formatting"
|
|
@echo " make format-check - Check Black code formatting (matches CI)"
|
|
@echo " make lint - Run all linting (Ruff, MyPy, Black check, circular imports, import safety)"
|
|
@echo " make lint-ruff - Run Ruff linting only"
|
|
@echo " make lint-mypy - Run MyPy type checking only"
|
|
@echo " make lint-black - Check Black formatting (matches CI)"
|
|
@echo " make check-circular-imports - Check for circular imports"
|
|
@echo " make check-import-safety - Check import safety"
|
|
@echo " make test - Run all tests"
|
|
@echo " make test-unit - Run unit tests (tests/test_litellm)"
|
|
@echo " make test-integration - Run integration tests"
|
|
@echo " make test-unit-helm - Run helm unit tests"
|
|
|
|
# Keep PIP simple for edge cases:
|
|
PIP := $(shell command -v pip > /dev/null 2>&1 && echo "pip" || echo "python3 -m pip")
|
|
|
|
# Show info
|
|
info:
|
|
@echo "PIP: $(PIP)"
|
|
|
|
# Installation targets
|
|
install-dev:
|
|
poetry install --with dev
|
|
|
|
install-proxy-dev:
|
|
poetry install --with dev,proxy-dev --extras proxy
|
|
|
|
# CI-compatible installations (matches GitHub workflows exactly)
|
|
install-dev-ci:
|
|
$(PIP) install openai==2.8.0
|
|
poetry install --with dev
|
|
$(PIP) install openai==2.8.0
|
|
|
|
install-proxy-dev-ci:
|
|
poetry install --with dev,proxy-dev --extras proxy
|
|
$(PIP) install openai==2.8.0
|
|
|
|
install-test-deps: install-proxy-dev
|
|
poetry run $(PIP) install "pytest-retry==1.6.3"
|
|
poetry run $(PIP) install pytest-xdist
|
|
poetry run $(PIP) install openapi-core
|
|
cd enterprise && poetry run $(PIP) install -e . && cd ..
|
|
|
|
install-helm-unittest:
|
|
helm plugin install https://github.com/helm-unittest/helm-unittest --version v0.4.4 || echo "ignore error if plugin exists"
|
|
|
|
# Formatting
|
|
format: install-dev
|
|
cd litellm && poetry run black . && cd ..
|
|
|
|
format-check: install-dev
|
|
cd litellm && poetry run black --check . && cd ..
|
|
|
|
# Linting targets
|
|
lint-ruff: install-dev
|
|
cd litellm && poetry run ruff check . && cd ..
|
|
|
|
# faster linter for developing ...
|
|
# inspiration from:
|
|
# https://github.com/astral-sh/ruff/discussions/10977
|
|
# https://github.com/astral-sh/ruff/discussions/4049
|
|
lint-format-changed: install-dev
|
|
@git diff origin/main --unified=0 --no-color -- '*.py' | \
|
|
perl -ne '\
|
|
if (/^diff --git a\/(.*) b\//) { $$file = $$1; } \
|
|
if (/^@@ .* \+(\d+)(?:,(\d+))? @@/) { \
|
|
$$start = $$1; $$count = $$2 || 1; $$end = $$start + $$count - 1; \
|
|
print "$$file:$$start:1-$$end:999\n"; \
|
|
}' | \
|
|
while read range; do \
|
|
file="$${range%%:*}"; \
|
|
lines="$${range#*:}"; \
|
|
echo "Formatting $$file (lines $$lines)"; \
|
|
poetry run ruff format --range "$$lines" "$$file"; \
|
|
done
|
|
|
|
lint-ruff-dev: install-dev
|
|
@tmpfile=$$(mktemp /tmp/ruff-dev.XXXXXX) && \
|
|
cd litellm && \
|
|
(poetry run ruff check . --output-format=pylint || true) > "$$tmpfile" && \
|
|
poetry run diff-quality --violations=pylint "$$tmpfile" --compare-branch=origin/main && \
|
|
cd .. ; \
|
|
rm -f "$$tmpfile"
|
|
|
|
lint-ruff-FULL-dev: install-dev
|
|
@files=$$(git diff --name-only origin/main -- '*.py'); \
|
|
if [ -n "$$files" ]; then echo "$$files" | xargs poetry run ruff check; \
|
|
else echo "No changed .py files to check."; fi
|
|
|
|
lint-mypy: install-dev
|
|
poetry run $(PIP) install types-requests types-setuptools types-redis types-PyYAML
|
|
cd litellm && poetry run mypy . --ignore-missing-imports && cd ..
|
|
|
|
lint-black: format-check
|
|
|
|
check-circular-imports: install-dev
|
|
cd litellm && poetry run python ../tests/documentation_tests/test_circular_imports.py && cd ..
|
|
|
|
check-import-safety: install-dev
|
|
@poetry run python -c "from litellm import *; print('[from litellm import *] OK! no issues!');" || (echo '🚨 import failed, this means you introduced unprotected imports! 🚨'; exit 1)
|
|
|
|
# Combined linting (matches test-linting.yml workflow)
|
|
lint: format-check lint-ruff lint-mypy check-circular-imports check-import-safety
|
|
|
|
# Faster linting for local development (only checks changed code)
|
|
lint-dev: lint-format-changed lint-mypy check-circular-imports check-import-safety
|
|
|
|
# Testing targets
|
|
test:
|
|
poetry run pytest tests/
|
|
|
|
test-unit: install-test-deps
|
|
poetry run pytest tests/test_litellm -x -vv -n 4
|
|
|
|
test-integration:
|
|
poetry run pytest tests/ -k "not test_litellm"
|
|
|
|
test-unit-helm: install-helm-unittest
|
|
helm unittest -f 'tests/*.yaml' deploy/charts/litellm-helm
|
|
|
|
# LLM Translation testing targets
|
|
test-llm-translation: install-test-deps
|
|
@echo "Running LLM translation tests..."
|
|
@python .github/workflows/run_llm_translation_tests.py
|
|
|
|
test-llm-translation-single: install-test-deps
|
|
@echo "Running single LLM translation test file..."
|
|
@if [ -z "$(FILE)" ]; then echo "Usage: make test-llm-translation-single FILE=test_filename.py"; exit 1; fi
|
|
@mkdir -p test-results
|
|
poetry run pytest tests/llm_translation/$(FILE) \
|
|
--junitxml=test-results/junit.xml \
|
|
-v --tb=short --maxfail=100 --timeout=300
|