Merge pull request #842 from akaihola/better-missing-black-error #2918
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | --- | |
| name: Build and test | |
| on: # yamllint disable-line rule:truthy | |
| push: | |
| branches: | |
| - master | |
| pull_request: | |
| branches: | |
| - master | |
| env: | |
| PY_IGNORE_IMPORTMISMATCH: 1 | |
| jobs: | |
| build-wheel: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| wheel-path: ${{ steps.get-darker-version.outputs.wheel-path }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| with: | |
| enable-cache: true | |
| cache-dependency-glob: | | |
| **/setup.cfg | |
| **/pyproject.toml | |
| - name: Build wheel distribution | |
| run: | | |
| uv build --wheel | |
| - name: Upload wheel for other jobs | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| if-no-files-found: error | |
| - name: Find out Darker version and output it for test jobs | |
| id: get-darker-version | |
| shell: python | |
| run: | | |
| from os import environ | |
| from pathlib import Path | |
| from runpy import run_path | |
| version = run_path("src/darker/version.py")["__version__"] | |
| Path(environ["GITHUB_OUTPUT"]).open("a").write( | |
| f"wheel-path=dist/darker-{version}-py3-none-any.whl\n" | |
| ) | |
| test-nixos: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: | |
| - ubuntu-latest | |
| - macos-latest | |
| needs: | |
| - build-wheel | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: cachix/install-nix-action@v31 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| - name: Download wheel uploaded by the build-wheel job | |
| uses: actions/download-artifact@v4 | |
| - name: Run tests in nix-shell | |
| run: | | |
| nix-shell \ | |
| --pure \ | |
| --run ' | |
| cert_file=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt | |
| export NIX_SSL_CERT_FILE=$cert_file | |
| uv venv | |
| uv pip install --group=dev "${{needs.build-wheel.outputs.wheel-path}}" | |
| uv export --only-group=dev | uv pip install --requirements=- | |
| # Run tests in installed package to avoid plugin import issue: | |
| PY_IGNORE_IMPORTMISMATCH=1 uv run pytest $(python -c " | |
| import os, darker | |
| print(os.path.dirname(darker.__file__)) | |
| ") | |
| ' \ | |
| ./default.nix | |
| test: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: | |
| - ubuntu-latest | |
| - windows-latest | |
| - macos-latest | |
| python-version: | |
| - '3.9' | |
| - '3.10' | |
| - '3.11' | |
| - '3.12' | |
| - '3.13' | |
| post_install: [''] | |
| include: | |
| - os: ubuntu-latest | |
| python-version: '3.9' | |
| post_install: uv sync --resolution lowest-direct | |
| - os: ubuntu-latest | |
| python-version: '3.13' | |
| post_install: uv pip install | |
| --upgrade | |
| --requirements constraints-future.txt | |
| needs: | |
| - build-wheel | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # need full history since Pytest runs Darker itself below | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| activate-environment: true | |
| - name: Download wheel uploaded by the build-wheel job | |
| uses: actions/download-artifact@v4 | |
| - name: Install Darker and its dependencies from the wheel built earlier | |
| run: uv pip install --group=dev "${{needs.build-wheel.outputs.wheel-path}}" | |
| - name: Downgrade target-version when running oldest supported Black | |
| if: matrix.post_install == 'uv sync --resolution lowest-direct' | |
| run: | | |
| sed -i 's/, "py311", "py312"//' pyproject.toml | |
| - name: Upgrade/downgrade packages for future/oldest test | |
| # Upgrade Black, Flynt and Isort from GitHub if future constraints are used. | |
| # This can't be done in the same Pip invocation as installing Darker | |
| # since Darker might place an upper limit on Black, Flynt and/or Isort during | |
| # compatibility fixing periods. | |
| if: matrix.post_install | |
| run: ${{ matrix.post_install }} | |
| - run: pytest | |
| build-sdist-validate-dists: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-wheel | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.x | |
| - name: Download wheel uploaded by the build-wheel job | |
| uses: actions/download-artifact@v4 | |
| - name: Build source distribution | |
| run: uv build --sdist | |
| - name: Validate distributions | |
| run: uvx --from "twine!=6.1.0" twine check dist/* | |
| validate-extras: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-wheel | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.x | |
| - uses: astral-sh/setup-uv@v6 | |
| with: | |
| activate-environment: true | |
| - uses: actions/download-artifact@v4 | |
| - run: > | |
| uv pip install ${{needs.build-wheel.outputs.wheel-path}}[color] | |
| | ( ! grep -E '^(error|warning): ' ) | |
| - name: Ensure Pygments was installed | |
| run: uv pip show pygments | |
| validate-no-extras: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-wheel | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.x | |
| - uses: astral-sh/setup-uv@v6 | |
| with: | |
| activate-environment: true | |
| - uses: actions/download-artifact@v4 | |
| - run: > | |
| uv pip install ${{needs.build-wheel.outputs.wheel-path}} | |
| | ( ! grep -E "^(error|warning): " ) | |
| - name: Ensure Pygments was not installed | |
| run: "! uv pip show pygments" |