version: 2.1 jobs: local_testing: docker: - image: circleci/python:3.9 working_directory: ~/project steps: - checkout - run: name: Check if litellm dir was updated or if pyproject.toml was modified command: | if [ -n "$(git diff --name-only $CIRCLE_SHA1^..$CIRCLE_SHA1 | grep -E 'pyproject\.toml|litellm/')" ]; then echo "litellm updated" else echo "No changes to litellm or pyproject.toml. Skipping tests." circleci step halt fi - restore_cache: keys: - v1-dependencies-{{ checksum ".circleci/requirements.txt" }} - run: name: Install Dependencies command: | python -m pip install --upgrade pip python -m pip install -r .circleci/requirements.txt pip install pytest pip install pytest-asyncio pip install mypy pip install "google-generativeai>=0.3.2" pip install "google-cloud-aiplatform>=1.38.0" pip install "boto3>=1.28.57" pip install langchain pip install "langfuse>=2.0.0" pip install numpydoc pip install traceloop-sdk==0.0.69 pip install openai pip install prisma - save_cache: paths: - ./venv key: v1-dependencies-{{ checksum ".circleci/requirements.txt" }} - run: name: Black Formatting command: | cd litellm python -m pip install black python -m black . cd .. - run: name: Linting Testing command: | cd litellm python -m pip install types-requests types-setuptools types-redis if ! python -m mypy . --ignore-missing-imports; then echo "mypy detected errors" exit 1 fi cd .. # Run pytest and generate JUnit XML report - run: name: Run tests command: | pwd ls python -m pytest -vv litellm/tests/ -x --junitxml=test-results/junit.xml --durations=5 no_output_timeout: 120m # Store test results - store_test_results: path: test-results publish_to_pypi: docker: - image: cimg/python:3.8 working_directory: ~/project environment: TWINE_USERNAME: __token__ steps: - checkout - run: name: Copy model_prices_and_context_window File to model_prices_and_context_window_backup command: | cp model_prices_and_context_window.json litellm/model_prices_and_context_window_backup.json - run: name: Check if litellm dir was updated or if pyproject.toml was modified command: | if [ -n "$(git diff --name-only $CIRCLE_SHA1^..$CIRCLE_SHA1 | grep -E 'pyproject\.toml|litellm/')" ]; then echo "litellm updated" else echo "No changes to litellm or pyproject.toml. Skipping PyPI publish." circleci step halt fi - run: name: Checkout code command: git checkout $CIRCLE_SHA1 # Check if setup.py is modified and publish to PyPI - run: name: PyPI publish command: | echo "Install TOML package." python -m pip install toml VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])") PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['name'])") if ! pip show -v $PACKAGE_NAME | grep -q "Version: ${VERSION}"; then echo "pyproject.toml modified" echo -e "[pypi]\nusername = $PYPI_PUBLISH_USERNAME\npassword = $PYPI_PUBLISH_PASSWORD" > ~/.pypirc python -m pip install --upgrade pip pip install build pip install wheel pip install --upgrade twine setuptools rm -rf build dist echo "Building package" python -m build echo "Twine upload to dist" echo "Contents of dist directory:" ls dist/ twine upload --verbose dist/* else echo "Version ${VERSION} of package is already published on PyPI. Skipping PyPI publish." circleci step halt fi - run: name: Trigger Github Action for new Docker Container command: | curl -X POST \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ "https://api.github.com/repos/BerriAI/litellm/actions/workflows/ghcr_deploy.yml/dispatches" \ -d '{"ref":"main"}' workflows: version: 2 build_and_test: jobs: - local_testing - publish_to_pypi: requires: - local_testing