Skip to content

Support installation through PyPI #13

@joshua-laughner

Description

@joshua-laughner

Since we've added support for plain Python virtual environments in GGG2020.1, it would be useful to keep that option in 2020.2. Since uv is installable from PyPI, it must be possible. I suspect that compiling in the netCDF library will be the most annoying part, though that should be doable with a wheel. Gemini has provided an initial recommendation for a Github Action workflow that would handle this, including building for ARM64 just in case. Some notes from the discussion:

  • The maturin-action step is supposed to include patching a wheel to ensure that all dynamic libraries are included and pointed to by the RPATH entries
  • PyPI distributions can include source for non-Python code, and so if anyone does need to build from source, this should recognize that maturin is the correct build system to use
  • Since we are bundling static libraries, we will need to verify that their licenses allow that.

Also note that I will want to modify this to pin specific commits for the actions as a protection against supply chain attacks.

name: CI/CD - Multi-Arch Release
on:
  release:
    types: [published]

permissions:
  contents: read

jobs:
  build_wheels:
    name: Build wheels on ${{ matrix.os }} (${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux x86_64
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          # Linux ARM64 (Native Runner)
          - os: ubuntu-24.04-arm
            target: aarch64-unknown-linux-gnu
          # macOS (Maturin handles Universal binaries by default on macos-latest)
          - os: macos-latest
            target: aarch64-apple-darwin
          # Windows x86_64
          - os: windows-latest
            target: x86_64-pc-windows-msvc

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      # Crucial for 'netcdf' static build: needs cmake to compile C dependencies
      - name: Install Build Dependencies (Linux)
        if: runner.os == 'Linux'
        run: sudo apt-get update && sudo apt-get install -y cmake libclang-dev

      - name: Install Build Dependencies (macOS)
        if: runner.os == 'macOS'
        run: brew install cmake

      - name: Build wheels
        uses: messense/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --sdist
          # 'auto' ensures manylinux compatibility for Linux wheels
          manylinux: auto

      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-${{ matrix.os }}-${{ strategy.job-index }}
          path: dist

  publish:
    name: Publish to PyPI
    runs-on: ubuntu-latest
    needs: [build_wheels]
    permissions:
      id-token: write # Required for Trusted Publishing
    steps:
      - uses: actions/download-artifact@v4
        with:
          pattern: wheels-*
          merge-multiple: true
          path: dist

      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions