readcon-core 0.13.1

An oxidized single and multiple CON file reader and writer with FFI bindings for ergonomic C/C++ usage.
Documentation
name: Python wheels

on:
  push:
    tags:
      - 'v*'
  pull_request:
    paths:
      - 'src/**'
      - 'Cargo.toml'
      - 'Cargo.lock'
      - 'pyproject.toml'
      - 'pyproject.chemfiles.toml'
      - '.github/workflows/python_wheels.yml'
  workflow_dispatch:

concurrency:
  group: python-wheels-${{ github.ref }}
  cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}

permissions:
  contents: read

env:
  CARGO_HTTP_MULTIPLEXING: "false"
  CARGO_NET_RETRY: "10"
  CARGO_HTTP_TIMEOUT: "120"

jobs:
  # Lean `readcon` + chemfiles-linked `readcon-chemfiles` (separate PyPI names,
  # same extension module `readcon`). Matrix is the usual dual-distribution pattern.
  sdist:
    name: Build sdist (${{ matrix.variant }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - variant: default
            pyproject: pyproject.toml
          - variant: chemfiles
            pyproject: pyproject.chemfiles.toml
    steps:
      - uses: actions/checkout@v6

      - name: Select pyproject for variant
        shell: bash
        run: |
          if [ "${{ matrix.pyproject }}" != "pyproject.toml" ]; then
            cp "${{ matrix.pyproject }}" pyproject.toml
          fi
          head -15 pyproject.toml

      - name: Build sdist
        uses: PyO3/maturin-action@v1
        with:
          command: sdist
          args: --out dist

      - name: Validate sdist
        run: pipx run twine check --strict dist/*

      - uses: actions/upload-artifact@v4
        with:
          name: sdist-${{ matrix.variant }}
          path: dist/*.tar.gz
          if-no-files-found: error

  wheels:
    name: Wheel ${{ matrix.variant }} (${{ matrix.os }}, ${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      # Explicit rows only (no axis × include cartesian product).
      matrix:
        include:
          # --- default (lean): features from pyproject.toml [tool.maturin]
          - variant: default
            os: ubuntu-latest
            target: x86_64
            pyproject: pyproject.toml
            features: python
          - variant: default
            os: ubuntu-22.04
            target: aarch64
            pyproject: pyproject.toml
            features: python
          - variant: default
            os: macos-15
            target: x86_64
            pyproject: pyproject.toml
            features: python
          - variant: default
            os: macos-14
            target: aarch64
            pyproject: pyproject.toml
            features: python
          - variant: default
            os: windows-latest
            target: x86_64
            pyproject: pyproject.toml
            features: python
          # --- chemfiles-linked distribution (readcon-chemfiles on PyPI)
          - variant: chemfiles
            os: ubuntu-latest
            target: x86_64
            pyproject: pyproject.chemfiles.toml
            features: python,chemfiles
          - variant: chemfiles
            os: ubuntu-22.04
            target: aarch64
            pyproject: pyproject.chemfiles.toml
            features: python,chemfiles
          - variant: chemfiles
            os: macos-15
            target: x86_64
            pyproject: pyproject.chemfiles.toml
            features: python,chemfiles
          - variant: chemfiles
            os: macos-14
            target: aarch64
            pyproject: pyproject.chemfiles.toml
            features: python,chemfiles
          # Windows + chemfiles-sys/CMake is unreliable on GHA; ship lean
          # Windows wheels only. Linux/macOS cover full chemfiles matrices.
          # - variant: chemfiles / windows-latest — omitted on purpose
    steps:
      - uses: actions/checkout@v6

      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Select pyproject for variant
        shell: bash
        run: |
          if [ "${{ matrix.pyproject }}" != "pyproject.toml" ]; then
            cp "${{ matrix.pyproject }}" pyproject.toml
          fi
          echo "Building features=${{ matrix.features }} from:"
          head -20 pyproject.toml

      - name: Build wheels
        id: build1
        continue-on-error: true
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --features ${{ matrix.features }} --find-interpreter
          manylinux: auto
          docker-options: >-
            -e CARGO_HTTP_MULTIPLEXING=false
            -e CARGO_NET_RETRY=10
            -e CARGO_HTTP_TIMEOUT=120
            -e CMAKE_POLICY_VERSION_MINIMUM=3.5

      - name: Build wheels (retry)
        if: steps.build1.outcome == 'failure'
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --features ${{ matrix.features }} --find-interpreter
          manylinux: auto
          docker-options: >-
            -e CARGO_HTTP_MULTIPLEXING=false
            -e CARGO_NET_RETRY=10
            -e CARGO_HTTP_TIMEOUT=120
            -e CMAKE_POLICY_VERSION_MINIMUM=3.5

      - name: Validate wheels
        if: matrix.target != 'aarch64' || runner.os != 'Linux'
        run: pipx run twine check --strict dist/*

      - uses: actions/upload-artifact@v4
        with:
          name: wheels-${{ matrix.variant }}-${{ matrix.os }}-${{ matrix.target }}
          path: dist/*.whl
          if-no-files-found: error

  publish:
    name: Publish to PyPI
    needs: [sdist, wheels]
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v')
    environment:
      name: pypi
      url: https://pypi.org/p/readcon
    permissions:
      id-token: write
    steps:
      - uses: actions/download-artifact@v4
        with:
          pattern: '{sdist-*,wheels-*}'
          merge-multiple: true
          path: dist/

      - name: List artifacts
        run: |
          ls -la dist/
          echo "--- expected packages: readcon (lean) and readcon-chemfiles (full) ---"
          ls dist/*.whl dist/*.tar.gz | sed 's|.*/||' | sort -u

      # Trusted publishers must be configured on PyPI for *both* project names
      # `readcon` and `readcon-chemfiles` (same workflow + environment `pypi`).
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          skip-existing: true