From ba85175a830601ba622f0cf3615e2297c70b9e96 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Tue, 23 Apr 2024 17:52:15 +0200 Subject: [PATCH] ci(python): Use `uv` for installing Python dependencies in CI (#15848) --- .github/workflows/benchmark.yml | 6 ++++-- .github/workflows/docs-global.yml | 10 ++++++---- .github/workflows/docs-python.yml | 12 ++++++++---- .github/workflows/lint-python.yml | 18 ++++++++++++------ .../{codecov.yml => test-coverage.yml} | 11 +++++++---- .github/workflows/test-python.yml | 7 +++++-- Makefile | 2 +- py-polars/requirements-dev.txt | 1 + 8 files changed, 44 insertions(+), 23 deletions(-) rename .github/workflows/{codecov.yml => test-coverage.yml} (92%) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 1f8d27ee4735..dbf48aba13ca 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -41,12 +41,14 @@ jobs: - name: Create virtual environment run: | - python -m venv .venv + curl -LsSf https://astral.sh/uv/install.sh | sh + uv venv echo "$GITHUB_WORKSPACE/.venv/bin" >> $GITHUB_PATH + echo "VIRTUAL_ENV=$GITHUB_WORKSPACE/.venv" >> $GITHUB_ENV - name: Install Python dependencies working-directory: py-polars - run: pip install -r requirements-dev.txt + run: uv pip install --compile-bytecode -r requirements-dev.txt - name: Set up Rust run: rustup show diff --git a/.github/workflows/docs-global.yml b/.github/workflows/docs-global.yml index cddd3fcbced3..58be103f9ac5 100644 --- a/.github/workflows/docs-global.yml +++ b/.github/workflows/docs-global.yml @@ -63,13 +63,15 @@ jobs: - name: Create virtual environment run: | - python -m venv .venv + curl -LsSf https://astral.sh/uv/install.sh | sh + uv venv echo "$GITHUB_WORKSPACE/.venv/bin" >> $GITHUB_PATH + echo "VIRTUAL_ENV=$GITHUB_WORKSPACE/.venv" >> $GITHUB_ENV - - name: Install dependencies + - name: Install Python dependencies run: | - pip install -r py-polars/requirements-dev.txt - pip install -r docs/requirements.txt + uv pip install -r py-polars/requirements-dev.txt + uv pip install -r docs/requirements.txt - name: Set up Rust run: rustup show diff --git a/.github/workflows/docs-python.yml b/.github/workflows/docs-python.yml index 7cd2801c43e0..0e9505293f65 100644 --- a/.github/workflows/docs-python.yml +++ b/.github/workflows/docs-python.yml @@ -32,17 +32,21 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.12' - cache: pip - cache-dependency-path: py-polars/docs/requirements-docs.txt + + - name: Create virtual environment + run: | + curl -LsSf https://astral.sh/uv/install.sh | sh + uv venv + echo "$GITHUB_WORKSPACE/.venv/bin" >> $GITHUB_PATH + echo "VIRTUAL_ENV=$GITHUB_WORKSPACE/.venv" >> $GITHUB_ENV - name: Install Python dependencies working-directory: py-polars/docs - run: pip install -r requirements-docs.txt + run: uv pip install -r requirements-docs.txt - name: Build Python documentation working-directory: py-polars/docs env: - SPHINXOPTS: -W --jobs=auto POLARS_VERSION: ${{ github.event.client_payload.tag || 'main' }} run: make html diff --git a/.github/workflows/lint-python.yml b/.github/workflows/lint-python.yml index 308afdbef089..53e487479414 100644 --- a/.github/workflows/lint-python.yml +++ b/.github/workflows/lint-python.yml @@ -40,9 +40,6 @@ jobs: fail-fast: false matrix: python-version: ['3.8', '3.12'] - defaults: - run: - working-directory: py-polars steps: - uses: actions/checkout@v4 @@ -52,11 +49,20 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install dependencies + - name: Create virtual environment run: | - pip install -r requirements-dev.txt - pip install -r requirements-lint.txt + curl -LsSf https://astral.sh/uv/install.sh | sh + uv venv + echo "$GITHUB_WORKSPACE/.venv/bin" >> $GITHUB_PATH + echo "VIRTUAL_ENV=$GITHUB_WORKSPACE/.venv" >> $GITHUB_ENV + + - name: Install Python dependencies + working-directory: py-polars + run: | + uv pip install -r requirements-dev.txt + uv pip install -r requirements-lint.txt # Allow untyped calls for older Python versions - name: Run mypy + working-directory: py-polars run: mypy ${{ (matrix.python-version == '3.8') && '--allow-untyped-calls' || '' }} diff --git a/.github/workflows/codecov.yml b/.github/workflows/test-coverage.yml similarity index 92% rename from .github/workflows/codecov.yml rename to .github/workflows/test-coverage.yml index 65cf0cba5e8e..1c75dc5ee021 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/test-coverage.yml @@ -84,15 +84,18 @@ jobs: - uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: '3.11' - name: Create virtual environment run: | - python -m venv .venv + curl -LsSf https://astral.sh/uv/install.sh | sh + uv venv echo "$GITHUB_WORKSPACE/.venv/bin" >> $GITHUB_PATH + echo "VIRTUAL_ENV=$GITHUB_WORKSPACE/.venv" >> $GITHUB_ENV - - name: Install dependencies - run: pip install -r py-polars/requirements-dev.txt + - name: Install Python dependencies + working-directory: py-polars + run: uv pip install --compile-bytecode -r requirements-dev.txt - name: Set up Rust run: rustup component add llvm-tools-preview diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 1646e5bc5032..ae27d473b6cc 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -60,9 +60,12 @@ jobs: run: | python -m venv .venv echo "$GITHUB_WORKSPACE/py-polars/.venv/$BIN" >> $GITHUB_PATH + echo "VIRTUAL_ENV=$GITHUB_WORKSPACE/py-polars/.venv" >> $GITHUB_ENV - - name: Install dependencies - run: pip install -r requirements-dev.txt + - name: Install Python dependencies + run: | + pip install uv + uv pip install --compile-bytecode -r requirements-dev.txt - name: Set up Rust run: rustup show diff --git a/Makefile b/Makefile index 85b791b6f97e..b8db8a8e66c7 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ FILTER_PIP_WARNINGS=| grep -v "don't match your environment"; test $${PIPESTATUS requirements: .venv ## Install/refresh Python project requirements @unset CONDA_PREFIX \ && $(VENV_BIN)/python -m pip install --upgrade uv \ - && $(VENV_BIN)/uv pip install --upgrade -r py-polars/requirements-dev.txt \ + && $(VENV_BIN)/uv pip install --upgrade --compile-bytecode -r py-polars/requirements-dev.txt \ && $(VENV_BIN)/uv pip install --upgrade -r py-polars/requirements-lint.txt \ && $(VENV_BIN)/uv pip install --upgrade -r py-polars/docs/requirements-docs.txt \ && $(VENV_BIN)/uv pip install --upgrade -r docs/requirements.txt diff --git a/py-polars/requirements-dev.txt b/py-polars/requirements-dev.txt index 22eb31b567fb..21151cc31c42 100644 --- a/py-polars/requirements-dev.txt +++ b/py-polars/requirements-dev.txt @@ -9,6 +9,7 @@ maturin # extra dependency for maturin (linux-only) patchelf; platform_system == 'Linux' +pip # ------------ # DEPENDENCIES