diff --git a/.github/actions/pip-list/action.yml b/.github/actions/pip-list/action.yml index 156fde4f..e567b3d7 100644 --- a/.github/actions/pip-list/action.yml +++ b/.github/actions/pip-list/action.yml @@ -20,9 +20,9 @@ runs: echo 'pip list' >> $GITHUB_STEP_SUMMARY echo '' >> $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY - pip list >> $GITHUB_STEP_SUMMARY + uv pip list >> $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY echo '' >> $GITHUB_STEP_SUMMARY echo '' >> $GITHUB_STEP_SUMMARY - pip list # also print to stdout + uv pip list # also print to stdout shell: bash diff --git a/.github/actions/pkg-install/action.yml b/.github/actions/pkg-install/action.yml index c1bbf361..b34c9c8d 100644 --- a/.github/actions/pkg-install/action.yml +++ b/.github/actions/pkg-install/action.yml @@ -40,7 +40,7 @@ runs: - name: Install package (archive) if: ${{ inputs.install-from == 'archive' }} - working-directory: pypi/ + working-directory: ${{ inputs.pkg-folder }} run: | set -ex pip install '${{ env.PKG_SOURCE }}${{ inputs.pkg-extras }}' \ diff --git a/.github/workflows/check-docs.yml b/.github/workflows/check-docs.yml index 91e18da6..ab9c7bf7 100644 --- a/.github/workflows/check-docs.yml +++ b/.github/workflows/check-docs.yml @@ -55,6 +55,7 @@ defaults: env: # just use CPU version since running on CPU machine TORCH_URL: "https://download.pytorch.org/whl/cpu/torch_stable.html" + UV_TORCH_BACKEND: cpu # default 0 means to keep for the maximum time KEEP_DAYS: 0 @@ -72,11 +73,12 @@ jobs: with: submodules: recursive - - name: Set up Python 🐍 ${{ inputs.python-version }} - uses: actions/setup-python@v6 + - name: Set up uv and Python 🐍 ${{ inputs.python-version }} + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: ${{ inputs.python-version }} - cache: "pip" + enable-cache: true - name: Install pandoc & texlive if: ${{ inputs.install-tex == 'true' }} @@ -92,9 +94,9 @@ jobs: - name: Install dependencies timeout-minutes: 20 run: | - pip --version - pip install -e . -U -r ${{ inputs.requirements-file }} -f ${TORCH_URL} - pip list + uv --version + uv pip install -e . -U -r ${{ inputs.requirements-file }} -f ${TORCH_URL} + uv pip list - name: Pull reusable πŸ€– actions️ if: ${{ inputs.actions-ref != '' }} @@ -123,3 +125,6 @@ jobs: path: ${{ inputs.docs-dir }}/build/ retention-days: ${{ env.KEEP_DAYS }} include-hidden-files: true + + - name: Minimize uv cache + run: uv cache prune --ci diff --git a/.github/workflows/check-package.yml b/.github/workflows/check-package.yml index 4b910138..907b2d06 100644 --- a/.github/workflows/check-package.yml +++ b/.github/workflows/check-package.yml @@ -80,10 +80,12 @@ jobs: with: fetch-depth: 0 # checkout entire history for all branches (required when using scm-based versioning) submodules: recursive - - name: Set up Python 🐍 - uses: actions/setup-python@v6 + - name: Set up uv and Python 🐍 + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: ${{ matrix.python-version || '3.x' }} + enable-cache: true - name: Pull reusable πŸ€– actions️ uses: actions/checkout@v5 @@ -93,8 +95,8 @@ jobs: repository: Lightning-AI/utilities - name: Prepare build env. run: | - pip install -q -r ./.cicd/requirements/gha-package.txt - pip list + uv pip install -q -r ./.cicd/requirements/gha-package.txt + uv pip list - name: Create package πŸ“¦ uses: ./.cicd/.github/actions/pkg-create - name: Upload πŸ“€ packages @@ -104,6 +106,9 @@ jobs: name: ${{ inputs.artifact-name }}-build-${{ strategy.job-index }} path: dist + - name: Minimize uv cache + run: uv cache prune --ci + merge-artifacts: needs: pkg-build runs-on: ubuntu-latest @@ -114,10 +119,16 @@ jobs: ref: ${{ inputs.actions-ref }} path: .cicd repository: Lightning-AI/utilities + - name: Set up uv and Python + uses: astral-sh/setup-uv@v7 + with: + activate-environment: true + python-version: "3.10" + enable-cache: true - name: Prepare build env. run: | - pip install -q -r ./.cicd/requirements/gha-package.txt - pip list + uv pip install -q -r ./.cicd/requirements/gha-package.txt + uv pip list - name: Download πŸ“₯ uses: actions/download-artifact@v6 @@ -136,6 +147,9 @@ jobs: name: ${{ inputs.artifact-name }} path: dist + - name: Minimize uv cache + run: uv cache prune --ci + pkg-check: needs: merge-artifacts runs-on: ${{ matrix.os }} @@ -148,6 +162,7 @@ jobs: uses: actions/checkout@v5 with: submodules: recursive + # NOTE: use pip as gold standard for package validation - name: Set up Python 🐍 ${{ matrix.python-version }} uses: actions/setup-python@v6 with: diff --git a/.github/workflows/check-precommit.yml b/.github/workflows/check-precommit.yml index c4115f21..a9bb02d2 100644 --- a/.github/workflows/check-precommit.yml +++ b/.github/workflows/check-precommit.yml @@ -38,10 +38,12 @@ jobs: submodules: recursive token: ${{ secrets.github-token || github.token }} - - name: Set up Python 🐍 - uses: actions/setup-python@v6 + - name: Set up uv and Python 🐍 + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: ${{ inputs.python-version }} + enable-cache: true - name: Cache πŸ’½ pre-commit if: ${{ inputs.use-cache == true }} @@ -53,9 +55,12 @@ jobs: - name: Run pre-commit πŸ€– id: precommit run: | - pip install -q pre-commit + uv pip install -q pre-commit pre-commit run --all-files + - name: Minimize uv cache + run: uv cache prune --ci + - name: Fixing Pull Request ↩️ if: always() && inputs.push-fixes == true && steps.precommit.outcome == 'failure' uses: actions-js/push@v1.5 diff --git a/.github/workflows/check-schema.yml b/.github/workflows/check-schema.yml index d950468b..b9408878 100644 --- a/.github/workflows/check-schema.yml +++ b/.github/workflows/check-schema.yml @@ -31,10 +31,12 @@ jobs: uses: actions/checkout@v5 with: submodules: recursive - - name: Set up Python - uses: actions/setup-python@v6 + - name: Set up uv and Python + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: "3.10" + enable-cache: true # if actions version is given install defined versions - name: "[optional] Pull reusable πŸ€– actions" @@ -48,15 +50,16 @@ jobs: if: inputs.actions-ref != '' timeout-minutes: 5 run: | - pip install -r ./.cicd/requirements/gha-schema.txt - pip list | grep "check-jsonschema" + uv pip install -r ./.cicd/requirements/gha-schema.txt + uv pip list | grep "check-jsonschema" + # otherwise fall back to using the latest - name: "[default] Install recommended dependencies" if: inputs.actions-ref == '' timeout-minutes: 5 run: | - pip install -q check-jsonschema - pip list | grep "check-jsonschema" + uv pip install -q check-jsonschema + uv pip list | grep "check-jsonschema" - name: Scan repo id: folders @@ -92,3 +95,6 @@ jobs: echo $f; check-jsonschema -v $f --schemafile "$SCHEMA_FILE" --regex-variant="nonunicode"; done + + - name: Minimize uv cache + run: uv cache prune --ci diff --git a/.github/workflows/check-typing.yml b/.github/workflows/check-typing.yml index ecd4d211..7334e3d1 100644 --- a/.github/workflows/check-typing.yml +++ b/.github/workflows/check-typing.yml @@ -31,24 +31,28 @@ defaults: jobs: mypy: runs-on: ubuntu-24.04 + env: + UV_TORCH_BACKEND: cpu steps: - name: Checkout πŸ›ŽοΈ uses: actions/checkout@v5 with: submodules: recursive - - name: Set up Python 🐍 ${{ inputs.python-version }} - uses: actions/setup-python@v6 + - name: Set up uv and Python 🐍 ${{ inputs.python-version }} + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: ${{ inputs.python-version }} + enable-cache: true - name: Install dependencies timeout-minutes: 20 run: | # don't use --upgrade to respect the version installed via setup.py - pip install -e '.[${{ inputs.extra-typing }}]' mypy \ + uv pip install -e '.[${{ inputs.extra-typing }}]' mypy types-requests \ --extra-index-url https://download.pytorch.org/whl/cpu/torch_stable.html - pip list + uv pip list - name: Pull reusable πŸ€– actions️ if: ${{ inputs.actions-ref != '' }} @@ -94,3 +98,6 @@ jobs: | sed 's/\.py//g; s|${SOURCE_DIR}||g; s|\/__init__||g; s|\/|\.|g' \ | xargs -I {} echo '"{}",' \ || true + + - name: Minimize uv cache + run: uv cache prune --ci diff --git a/.github/workflows/ci-cli.yml b/.github/workflows/ci-cli.yml index 538bec54..a66ddccc 100644 --- a/.github/workflows/ci-cli.yml +++ b/.github/workflows/ci-cli.yml @@ -22,15 +22,17 @@ jobs: steps: - name: Checkout πŸ›Ž uses: actions/checkout@v5 - - name: Set up Python 🐍 ${{ matrix.python-version }} - uses: actions/setup-python@v6 + - name: Set up uv and Python 🐍 ${{ matrix.python-version }} + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: ${{ matrix.python-version }} + enable-cache: true - name: install package run: | - pip install -e '.[cli]' - pip list + uv pip install -e '.[cli]' + uv pip list - name: run CLI working-directory: ./requirements @@ -40,6 +42,9 @@ jobs: python -m lightning_utilities.cli requirements set-oldest --req_files="cli.txt" python -m lightning_utilities.cli requirements set-oldest --req_files='["cli.txt", "docs.txt"]' + - name: Minimize uv cache + run: uv cache prune --ci + cli-guardian: runs-on: ubuntu-latest needs: test-cli diff --git a/.github/workflows/ci-scripts.yml b/.github/workflows/ci-scripts.yml index 2966b322..1f90e1b9 100644 --- a/.github/workflows/ci-scripts.yml +++ b/.github/workflows/ci-scripts.yml @@ -22,49 +22,58 @@ jobs: steps: - name: Checkout πŸ›Ž uses: actions/checkout@v5 - - name: Set up Python 🐍 ${{ matrix.python-version }} - uses: actions/setup-python@v6 + - name: Set up uv and Python 🐍 ${{ matrix.python-version }} + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: ${{ matrix.python-version }} - cache: "pip" + enable-cache: true - name: Install dependencies timeout-minutes: 5 run: | - pip install -r requirements/_tests.txt - pip --version - pip list + uv pip install -r requirements/_tests.txt + uv --version + uv pip list - name: test Scripts working-directory: ./scripts - run: pytest . -v + run: uv run pytest . -v + + - name: Minimize uv cache + run: uv cache prune --ci standalone-run: runs-on: "ubuntu-22.04" timeout-minutes: 20 env: TORCH_URL: "https://download.pytorch.org/whl/cpu/torch_stable.html" + UV_TORCH_BACKEND: cpu steps: - name: Checkout πŸ›Ž uses: actions/checkout@v5 - - name: Set up Python 🐍 ${{ matrix.python-version }} - uses: actions/setup-python@v6 + - name: Set up uv and Python 🐍 ${{ matrix.python-version }} + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: "3.10" - cache: "pip" + enable-cache: true - name: Install dependencies timeout-minutes: 20 run: | set -e - pip install -e ".[cli]" -U -r requirements/_tests.txt -f $TORCH_URL - pip --version - pip list + uv pip install -e ".[cli]" -U -r requirements/_tests.txt -f $TORCH_URL + uv --version + uv pip list - name: Run standalone script run: bash ./scripts/run_standalone_tests.sh "tests" env: COVERAGE_SOURCE: "lightning_utilities" + - name: Minimize uv cache + run: uv cache prune --ci + scripts-guardian: runs-on: ubuntu-latest needs: [test-scripts, standalone-run] diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index 46b139a2..354cc2f6 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -24,42 +24,40 @@ jobs: timeout-minutes: 35 env: TORCH_URL: "https://download.pytorch.org/whl/cpu/torch_stable.html" + UV_TORCH_BACKEND: cpu steps: - name: Checkout πŸ›Ž uses: actions/checkout@v5 with: submodules: recursive - - name: Set up Python 🐍 ${{ matrix.python-version }} - uses: actions/setup-python@v6 + - name: Set up uv and Python 🐍 ${{ matrix.python-version }} + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: ${{ matrix.python-version }} + enable-cache: true - name: Set oldest dependencies if: matrix.requires == 'oldest' timeout-minutes: 20 run: | - pip install -e '.[cli]' + uv pip install -e '.[cli]' python -m lightning_utilities.cli requirements set-oldest - - name: Complex πŸ’½ caching - uses: ./.github/actions/cache - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies timeout-minutes: 20 run: | set -e - pip install -e ".[cli]" -U -r requirements/_tests.txt -f $TORCH_URL - pip --version - pip list + uv pip install -e ".[cli]" -U -r requirements/_tests.txt -f $TORCH_URL + uv --version + uv pip list - name: Print πŸ–¨οΈ dependencies uses: ./.github/actions/pip-list - name: Unittests working-directory: ./tests - run: python -m pytest unittests --cov=lightning_utilities --durations=50 --timeout=120 + run: uv run python -m pytest unittests --cov=lightning_utilities --durations=50 --timeout=120 - name: Statistics working-directory: ./tests @@ -80,7 +78,10 @@ jobs: - name: test CI scripts working-directory: ./tests - run: python -m pytest scripts --durations=50 --timeout=120 + run: uv run python -m pytest scripts --durations=50 --timeout=120 + + - name: Minimize uv cache + run: uv cache prune --ci testing-guardian: runs-on: ubuntu-latest diff --git a/.github/workflows/cleanup-caches.yml b/.github/workflows/cleanup-caches.yml index b7be9101..de419340 100644 --- a/.github/workflows/cleanup-caches.yml +++ b/.github/workflows/cleanup-caches.yml @@ -41,6 +41,13 @@ jobs: - name: Checkout Code uses: actions/checkout@v5 + - name: Set up uv and Python + uses: astral-sh/setup-uv@v7 + with: + activate-environment: true + python-version: "3.10" + enable-cache: true + - name: Pull reusable πŸ€– actions️ uses: actions/checkout@v5 with: @@ -49,7 +56,7 @@ jobs: repository: Lightning-AI/utilities - name: install requirements timeout-minutes: 20 - run: pip install -U -r ./.cicd/.github/scripts/find-unused-caches.txt + run: uv pip install -U -r ./.cicd/.github/scripts/find-unused-caches.txt - name: List and Filer πŸ” caches run: | @@ -66,3 +73,6 @@ jobs: # delete each cache based on file... gh api --method DELETE -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/actions/caches/ $line; done < "unused-cashes.txt" + + - name: Minimize uv cache + run: uv cache prune --ci diff --git a/.github/workflows/cron-clear-cache.yml b/.github/workflows/cron-clear-cache.yml index 61f1af82..41891440 100644 --- a/.github/workflows/cron-clear-cache.yml +++ b/.github/workflows/cron-clear-cache.yml @@ -29,6 +29,6 @@ jobs: with: scripts-ref: ${{ github.sha }} # use local version dry-run: ${{ github.event_name == 'pull_request' }} - # ise input if set of default... + # use input if set, otherwise default... pattern: ${{ inputs.pattern || 'pip|conda' }} - age-days: ${{ fromJSON(inputs.age-days) || 2 }} + age-days: ${{ inputs.age-days || 7 }} diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 25ce1210..dadf8ed1 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -15,6 +15,7 @@ jobs: runs-on: ubuntu-latest env: TORCH_URL: "https://download.pytorch.org/whl/cpu/torch_stable.html" + UV_TORCH_BACKEND: cpu steps: - name: Checkout πŸ›ŽοΈ uses: actions/checkout@v5 @@ -22,20 +23,12 @@ jobs: with: persist-credentials: false submodules: recursive - - name: Set up Python 🐍 - uses: actions/setup-python@v6 + - name: Set up uv and Python 🐍 + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: "3.10" - cache: "pip" - - # Note: This uses an internal pip API and may not always work - # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow - - name: Cache πŸ’½ pip - uses: actions/cache@v4 - with: - path: ~/.cache/pip - key: pip-${{ hashFiles('requirements/*.txt') }} - restore-keys: pip- + enable-cache: true #- name: Install texlive # timeout-minutes: 20 @@ -48,9 +41,9 @@ jobs: - name: Install dependencies timeout-minutes: 20 run: | - pip --version - pip install -e . -U -q -r requirements/_docs.txt -f ${TORCH_URL} - pip list + uv --version + uv pip install -e . -U -q -r requirements/_docs.txt -f ${TORCH_URL} + uv pip list shell: bash - name: Make Documentation @@ -67,3 +60,6 @@ jobs: clean: true # Automatically remove deleted files from the deploy branch target-folder: docs # If you'd like to push the contents of the deployment folder into a specific directory single-commit: true # you'd prefer to have a single commit on the deployment branch instead of full history + + - name: Minimize uv cache + run: uv cache prune --ci diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml index 4d6866d0..307ae0a7 100644 --- a/.github/workflows/release-pypi.yml +++ b/.github/workflows/release-pypi.yml @@ -22,12 +22,14 @@ jobs: steps: - name: Checkout πŸ›ŽοΈ uses: actions/checkout@v5 - - name: Set up Python 🐍 - uses: actions/setup-python@v6 + - name: Set up uv and Python 🐍 + uses: astral-sh/setup-uv@v7 with: + activate-environment: true python-version: "3.10" + enable-cache: true - name: Prepare build env. - run: pip install -r ./requirements/gha-package.txt + run: uv pip install -r ./requirements/gha-package.txt - name: Create πŸ“¦ package uses: ./.github/actions/pkg-create - name: Upload πŸ“€ packages @@ -36,6 +38,9 @@ jobs: name: pypi-packages-${{ github.sha }} path: dist + - name: Minimize uv cache + run: uv cache prune --ci + upload-package: needs: build-package if: github.event_name == 'release' diff --git a/tests/unittests/cli/test_command_line.py b/tests/unittests/cli/test_command_line.py index a379adf5..a4ff42a7 100644 --- a/tests/unittests/cli/test_command_line.py +++ b/tests/unittests/cli/test_command_line.py @@ -1,4 +1,5 @@ import subprocess +import sys from pathlib import Path import pytest @@ -6,7 +7,7 @@ def test_version(): """Prints the help message for the requirements commands.""" - return_code = subprocess.call(["python", "-mlightning_utilities.cli", "version"]) # noqa: S607 + return_code = subprocess.call([sys.executable, "-m", "lightning_utilities.cli", "version"]) # noqa: S603 assert return_code == 0 @@ -14,7 +15,7 @@ def test_version(): class TestRequirements: """Test requirements commands.""" - BASE_CMD = ("python", "-m", "lightning_utilities.cli", "requirements") + BASE_CMD = (sys.executable, "-m", "lightning_utilities.cli", "requirements") REQUIREMENTS_SAMPLE = """ # This is sample requirements file # with multi line comments