From 1c328b0899449ccfb4e33486c2cbf1c6b82e86a3 Mon Sep 17 00:00:00 2001 From: Mathew Payne <2772944+GeekMasher@users.noreply.github.com> Date: Wed, 9 Apr 2025 10:58:17 +0000 Subject: [PATCH] feat: Update Python build, testing, and linting --- .github/workflows/python-build.yml | 9 ++++ .github/workflows/python-linting.yml | 4 +- .github/workflows/python-testing.yml | 78 +++++++++++++++++++++++----- .github/workflows/python.yml | 8 --- 4 files changed, 76 insertions(+), 23 deletions(-) diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index 7e9af6a..6e59ce4 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -48,6 +48,8 @@ jobs: - name: Install dependencies if: ${{ github.event.inputs.install == 'true' }} + env: + PYTHON_VERSION: ${{ matrix.python-version }} run: | set -e if [[ -f Pipfile ]]; then @@ -56,6 +58,11 @@ jobs: elif [[ -f requirements.txt ]]; then python -m pip install --upgrade pip pip install -r requirements.txt + elif [[ -f uv.lock ]]; then + python -m pip install --upgrade uv + uv python install "$PYTHON_VERSION" + uv sync -d + elif [[ -f Makefile ]]; then make install else @@ -71,6 +78,8 @@ jobs: pipenv run build elif [[ -f setup.py ]]; then python setup.py build + elif [[ -f uv.lock ]]; then + uv build elif [[ -f Makefile ]]; then make build else diff --git a/.github/workflows/python-linting.yml b/.github/workflows/python-linting.yml index 1e8c157..8fee567 100644 --- a/.github/workflows/python-linting.yml +++ b/.github/workflows/python-linting.yml @@ -71,9 +71,11 @@ jobs: fi - name: Run linting + env: + TOOL: ${{ inputs.tool }} run: | set -e - TOOL="${{ inputs.tool }}" + if [[ "$TOOL" == "ruff" ]]; then pip install ruff ruff check diff --git a/.github/workflows/python-testing.yml b/.github/workflows/python-testing.yml index 1bc64d8..6875d54 100644 --- a/.github/workflows/python-testing.yml +++ b/.github/workflows/python-testing.yml @@ -10,10 +10,14 @@ on: description: 'Python versions to test against' type: string # All Major versions of Python that are currently supported - default: '3.9,3.10,3.11,3.12' + default: '3.9,3.10,3.11,3.12,3.13' + tool: + description: 'The tool to lint with' + type: string + default: 'ruff' jobs: - python-versions: + versions: runs-on: ubuntu-latest outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} @@ -27,40 +31,56 @@ jobs: echo "matrix :: [$matrix]" echo "matrix=[$matrix]" >> "$GITHUB_OUTPUT" - python-testing: + testing: # This workflow runs on the latest version of Ubuntu runs-on: ubuntu-latest if: ${{ needs.python-versions.outputs.matrix != '[]' }} - needs: [ python-versions ] + needs: [ versions ] strategy: fail-fast: false matrix: - python-version: ${{ fromJSON(needs.python-versions.outputs.matrix) }} + python-version: ${{ fromJSON(needs.versions.outputs.matrix) }} steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0 with: python-version: ${{ matrix.python-version }} - name: Install dependencies + env: + PYTHON_VERSION: ${{ matrix.python-version }} run: | set -e echo "Installing dependencies..." - if [[ -f pyproject.toml ]]; then - python -m pip install --upgrade pip poetry - poetry install - elif [[ -f Pipfile ]]; then + + if [[ -f Pipfile ]]; then + echo "Pipfile found, installing with pipenv" python -m pip install --upgrade pip pipenv pipenv sync -d + + elif [[ -f uv.lock ]]; then + echo "uv.lock found, installing with uv" + python -m pip install --upgrade uv + uv python install "$PYTHON_VERSION" + uv sync -d + + elif [[ -f pyproject.toml ]]; then + echo "pyproject.toml found, installing with poetry" + python -m pip install --upgrade pip poetry + poetry install + elif [[ -f requirements.txt ]]; then + echo "requirements.txt found, installing with pip" python -m pip install --upgrade pip pip install -r requirements.txt + elif [[ -f Makefile ]]; then make install + else echo "No manifest files found to install dependencies" fi @@ -69,16 +89,46 @@ jobs: run: | set -e echo "Running Python tests..." - if [[ -f pyproject.toml ]]; then - echo "Running poetry run test" - poetry run test - elif [[ -f Pipfile ]]; then + + if [[ -f Pipfile ]]; then echo "Running pipenv run test" pipenv run test + + elif [[ -f uv.lock ]]; then + echo "Running uv test" + uv run test + + elif [[ -f pyproject.toml ]]; then + echo "Running poetry run test" + poetry run test + elif [[ -f Makefile ]]; then echo "Running make test" make test + else echo "Unknown test runner..." echo "Please contact the oss-maintainers team for help." fi + + - name: Run linting + env: + TOOL: ${{ inputs.tool }} + run: | + set -e + + if [[ "$TOOL" == "ruff" ]]; then + pip install ruff + ruff check + + elif [[ "$TOOL" == "flake8" ]]; then + pip install flake8 + flake8 . + + elif [[ "$TOOL" == "black" ]]; then + pip install black + black --check . + else + echo "Unknown linting tool..." + echo "Please contact the oss-maintainers team for help." + fi diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index b8cca63..ce29e90 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -30,14 +30,6 @@ jobs: with: versions: ${{ inputs.versions }} - # Run linters on the codebase - linting: - uses: advanced-security/reusable-workflows/.github/workflows/python-linting.yml@v0.3.0 - needs: [ testing ] - secrets: inherit - with: - versions: ${{ inputs.versions }} - # Vendor the dependencies into the repository if needed vendoring: uses: advanced-security/reusable-workflows/.github/workflows/python-vendor.yml@v0.3.0