Skip to content

Commit

Permalink
Python: switch to uv (microsoft#8320)
Browse files Browse the repository at this point in the history
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Switches from poetry to uv
much faster and easier lock management
easier maintenance of pyproject.toml

fixes: microsoft#6584
fixes: microsoft#8326

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
  • Loading branch information
eavanvalkenburg authored Aug 26, 2024
1 parent 163d512 commit f90538b
Show file tree
Hide file tree
Showing 24 changed files with 5,819 additions and 8,362 deletions.
45 changes: 0 additions & 45 deletions .github/workflows/python-build-wheel.yml

This file was deleted.

92 changes: 64 additions & 28 deletions .github/workflows/python-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,37 @@ jobs:
matrix:
python-version: ["3.11"]
os: [ubuntu-latest]
env:
# Configure a constant location for the uv cache
UV_CACHE_DIR: /tmp/.uv-cache
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up uv
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }}
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up uv
if: ${{ matrix.os == 'windows-latest' }}
run: irm https://astral.sh/uv/install.ps1 | iex
shell: powershell
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Restore uv cache
id: cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/uv.lock') }}
- name: Install dependencies with hnswlib native disabled
if: matrix.os == 'macos-latest' && matrix.python-version == '3.11'
run: |
export HNSWLIB_NO_NATIVE=1
python -m pip install --upgrade pip setuptools wheel
cd python && poetry install --with tests
uv sync --all-extras --dev
- name: Install dependencies with hnswlib native enabled
if: matrix.os != 'macos-latest' || matrix.python-version != '3.11'
run: |
python -m pip install --upgrade pip setuptools wheel
cd python
poetry install --with tests
uv sync --all-extras --dev
- name: Install Ollama
if: matrix.os == 'ubuntu-latest'
run: |
Expand Down Expand Up @@ -98,7 +108,7 @@ jobs:
- name: Run Integration Tests
id: run_tests
shell: bash
env: # Set Azure credentials secret as an input
env:
HNSWLIB_NO_NATIVE: 1
Python_Integration_Tests: Python_Integration_Tests
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME }} # azure-text-embedding-ada-002
Expand Down Expand Up @@ -137,7 +147,7 @@ jobs:
REDIS_CONNECTION_STRING: ${{ vars.REDIS_CONNECTION_STRING }}
run: |
cd python
poetry run pytest -n logical --dist loadfile --dist worksteal ./tests/integration ./tests/samples -v --junitxml=pytest.xml
uv run pytest -n logical --dist loadfile --dist worksteal ./tests/integration ./tests/samples -v --junitxml=pytest.xml
- name: Surface failing tests
if: always()
uses: pmeier/pytest-results-action@main
Expand All @@ -155,6 +165,8 @@ jobs:
fail-on-empty: true
# (Optional) Title of the test results section in the workflow summary
title: Test results
- name: Minimize uv cache
run: uv cache prune --ci

python-integration-tests:
needs: paths-filter
Expand All @@ -168,26 +180,32 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up uv
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }}
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up uv
if: ${{ matrix.os == 'windows-latest' }}
run: irm https://astral.sh/uv/install.ps1 | iex
shell: powershell
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Restore uv cache
id: cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/uv.lock') }}
- name: Install dependencies with hnswlib native disabled
if: matrix.os == 'macos-latest' && matrix.python-version == '3.11'
run: |
export HNSWLIB_NO_NATIVE=1
python -m pip install --upgrade pip setuptools wheel
cd python && poetry install --with tests
uv sync --all-extras --dev
- name: Install dependencies with hnswlib native enabled
if: matrix.os != 'macos-latest' || matrix.python-version != '3.11'
run: |
python -m pip install --upgrade pip setuptools wheel
cd python && poetry install --with tests
uv sync --all-extras --dev
- name: Install Ollama
if: matrix.os == 'ubuntu-latest'
run: |
Expand All @@ -209,11 +227,15 @@ jobs:

- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v2

- name: Setup Redis Stack Server
if: matrix.os == 'ubuntu-latest'
run: docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest

- name: Run Integration Tests
id: run_tests
shell: bash
env: # Set Azure credentials secret as an input
env:
HNSWLIB_NO_NATIVE: 1
Python_Integration_Tests: Python_Integration_Tests
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME }} # azure-text-embedding-ada-002
Expand All @@ -240,6 +262,8 @@ jobs:
MISTRALAI_API_KEY: ${{secrets.MISTRALAI_API_KEY}}
MISTRALAI_CHAT_MODEL_ID: ${{ vars.MISTRALAI_CHAT_MODEL_ID }}
MISTRALAI_EMBEDDING_MODEL_ID: ${{ vars.MISTRALAI_EMBEDDING_MODEL_ID }}
ANTHROPIC_API_KEY: ${{secrets.ANTHROPIC_API_KEY}}
ANTHROPIC_CHAT_MODEL_ID: ${{ vars.ANTHROPIC_CHAT_MODEL_ID }}
OLLAMA_MODEL: "${{ matrix.os == 'ubuntu-latest' && vars.OLLAMA_MODEL || '' }}" # phi3
GOOGLE_AI_GEMINI_MODEL_ID: ${{ vars.GOOGLE_AI_GEMINI_MODEL_ID }}
GOOGLE_AI_EMBEDDING_MODEL_ID: ${{ vars.GOOGLE_AI_EMBEDDING_MODEL_ID }}
Expand All @@ -248,16 +272,28 @@ jobs:
VERTEX_AI_GEMINI_MODEL_ID: ${{ vars.VERTEX_AI_GEMINI_MODEL_ID }}
VERTEX_AI_EMBEDDING_MODEL_ID: ${{ vars.VERTEX_AI_EMBEDDING_MODEL_ID }}
REDIS_CONNECTION_STRING: ${{ vars.REDIS_CONNECTION_STRING }}
ANTHROPIC_API_KEY: ${{secrets.ANTHROPIC_API_KEY}}
ANTHROPIC_CHAT_MODEL_ID: ${{ vars.ANTHROPIC_CHAT_MODEL_ID }}
run: |
if ${{ matrix.os == 'ubuntu-latest' }}; then
docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest
fi
cd python
poetry run pytest -n logical --dist loadfile --dist worksteal ./tests/integration -v
poetry run pytest -n logical --dist loadfile --dist worksteal ./tests/samples -v
uv run pytest -n logical --dist loadfile --dist worksteal ./tests/integration ./tests/samples -v --junitxml=pytest.xml
- name: Surface failing tests
if: always()
uses: pmeier/pytest-results-action@main
with:
# A list of JUnit XML files, directories containing the former, and wildcard
# patterns to process.
# See @actions/glob for supported patterns.
path: python/pytest.xml
# (Optional) Add a summary of the results at the top of the report
summary: true
# (Optional) Select which results should be included in the report.
# Follows the same syntax as `pytest -r`
display-options: fEX
# (Optional) Fail the workflow if no JUnit XML was found.
fail-on-empty: true
# (Optional) Title of the test results section in the workflow summary
title: Test results
- name: Minimize uv cache
run: uv cache prune --ci

# This final job is required to satisfy the merge queue. It must only run (or succeed) if no tests failed
python-integration-tests-check:
Expand Down
27 changes: 21 additions & 6 deletions .github/workflows/python-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,29 @@ jobs:
python-version: ["3.10"]
runs-on: ubuntu-latest
continue-on-error: true
defaults:
run:
working-directory: python
env:
# Configure a constant location for the uv cache
UV_CACHE_DIR: /tmp/.uv-cache
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Install dependencies
run: cd python && poetry install
- name: Restore uv cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/uv.lock') }}
- name: Install the project
run: uv sync --all-extras --dev
- uses: pre-commit/action@v3.0.1
with:
extra_args: --config python/.pre-commit-config.yaml
- name: Minimize uv cache
run: uv cache prune --ci
51 changes: 37 additions & 14 deletions .github/workflows/python-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches: ["main", "feature*"]
paths:
- "python/**"
env:
# Configure a constant location for the uv cache
UV_CACHE_DIR: /tmp/.uv-cache

jobs:
python-unit-tests:
Expand All @@ -28,17 +31,27 @@ jobs:
working-directory: python
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up uv
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }}
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up uv
if: ${{ matrix.os == 'windows-latest' }}
run: irm https://astral.sh/uv/install.ps1 | iex
shell: powershell
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Install dependencies
run: poetry install --with unit-tests
- name: Restore uv cache
id: cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/uv.lock') }}
- name: Install the project
run: uv sync --all-extras --dev
- name: Test with pytest
run: poetry run pytest --junitxml=pytest.xml ./tests/unit
run: uv run pytest --junitxml=pytest.xml ./tests/unit
- name: Surface failing tests
if: always()
uses: pmeier/pytest-results-action@main
Expand All @@ -56,6 +69,8 @@ jobs:
fail-on-empty: true
# (Optional) Title of the test results section in the workflow summary
title: Test results
- name: Minimize uv cache
run: uv cache prune --ci
python-test-coverage:
name: Python Test Coverage
runs-on: [ubuntu-latest]
Expand All @@ -65,21 +80,27 @@ jobs:
defaults:
run:
working-directory: python
env:
PYTHON_VERSION: "3.10"
steps:
- uses: actions/checkout@v4
- name: Setup filename variables
run: echo "FILE_ID=${{ github.event.number }}" >> $GITHUB_ENV
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.10
- name: Set up uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "poetry"
- name: Install dependencies
run: poetry install --with unit-tests
python-version: ${{ env.PYTHON_VERSION }}
- name: Restore uv cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/uv.lock') }}
- name: Install the project
run: uv sync --all-extras --dev
- name: Test with pytest
run: poetry run pytest -q --junitxml=pytest.xml --cov=semantic_kernel --cov-report=term-missing:skip-covered ./tests/unit | tee python-coverage.txt
run: uv run pytest -q --junitxml=pytest.xml --cov=semantic_kernel --cov-report=term-missing:skip-covered ./tests/unit | tee python-coverage.txt
- name: Upload coverage
if: always()
uses: actions/upload-artifact@v4
Expand All @@ -96,3 +117,5 @@ jobs:
path: python/pytest.xml
overwrite: true
retention-days: 1
- name: Minimize uv cache
run: uv cache prune --ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ env/
venv/
myvenv/
ENV/
.venv*/

# Python dist
dist/
Expand Down
Loading

0 comments on commit f90538b

Please sign in to comment.