satkit 0.21.0

Satellite Toolkit
Documentation
name: Build

on:
  push:
    branches:
      - "**"
    paths-ignore:
      - "docs/**"
      - "README.md"
      - "CHANGELOG.md"
      - "CONTRIBUTING.md"
      - "LICENSE"
  pull_request:
    branches:
      - "**"
      - "!wheel**"
    types:
      - opened
      - synchronize
      - reopened
      - closed
    paths-ignore:
      - "docs/**"
      - "README.md"
      - "CHANGELOG.md"
      - "CONTRIBUTING.md"
      - "LICENSE"

jobs:
  lint:
    name: rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - name: Check formatting
        run: cargo fmt --all -- --check

  clippy:
    name: clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - name: Cargo Cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo-clippy-
      - name: Clippy (deny warnings)
        run: cargo clippy --workspace --all-targets -- -D warnings

  audit:
    name: cargo audit
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
      - name: Install cargo-audit
        uses: taiki-e/install-action@cargo-audit
      - name: Audit dependencies (RustSec advisories)
        run: cargo audit

  sdist:
    # Guard against source-unbuildable sdists: a broken 0.20.0 sdist (missing
    # benches/ while Cargo.toml declared a bench target) shipped to PyPI
    # undetected because wheels and `cargo publish --dry-run` exercise
    # different artifacts. Build the sdist, then pip-install *from it* and
    # import the result.
    name: sdist installs from source
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.13"
      - name: Cargo Cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
          key: ${{ runner.os }}-cargo-sdist-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo-sdist-
      - name: Build sdist
        run: |
          pip install build
          python -m build --sdist -o dist
      - name: Install from sdist and import
        run: |
          pip install numpy
          pip install --no-deps dist/satkit-*.tar.gz
          cd /tmp
          python -c "import satkit as sk; t = sk.time(2024, 1, 1, 12, 0, 0); q = sk.quaternion.rotz(0.5); assert abs(q.angle - 0.5) < 1e-12; print('sdist install OK:', sk.__version__, t)"

  rust:
    name: rust build and test (${{ matrix.os }})
    strategy:
      fail-fast: false
      matrix:
        os: [macos, ubuntu, windows]

    runs-on: ${{ format('{0}-latest', matrix.os) }}

    env:
      SATKIT_DATA: astro-data
      SATKIT_TESTVEC_ROOT: satkit-testvecs

    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable

      - name: Cache Satkit Data
        id: cache-satkit-data
        uses: actions/cache@v4
        with:
          path: astro-data
          enableCrossOsArchive: true
          key: satkit-data-${{ hashFiles('data/manifest.json') }}

      - name: Download Satkit Data
        if: steps.cache-satkit-data.outputs.cache-hit != 'true'
        run: |
          python -m pip install requests
          python python/test/download_data.py astro-data

      - name: Cache Satkit Test Vectors
        id: cache-satkit-testvecs
        uses: actions/cache@v4
        with:
          path: satkit-testvecs
          enableCrossOsArchive: true
          key: satkit-testvecs-cache

      - name: Download Satkit Test Vectors
        if: steps.cache-satkit-testvecs.outputs.cache-hit != 'true'
        run: |
          python -m pip install requests
          python python/test/download_testvecs.py satkit-testvecs

      - name: Cargo Cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo-

      - name: Build
        run: cargo build --release

      - name: Test
        run: cargo test --features chrono

      # Network-dependent test, #[ignore]d so an offline `cargo test` passes;
      # still exercised here where the runner has internet access.
      - name: Test (network, solar cycle forecast download)
        run: cargo test --features chrono --lib solar_cycle_forecast -- --ignored

      # What works with NO data directory and NO network: the compiled-in
      # IERS tables and gravity models, SGP4, time, Kepler, Lambert — and a
      # missing ephemeris must be a typed error, not a hang or a download.
      - name: Test (offline, empty data directory)
        shell: bash
        env:
          SATKIT_DATA: ${{ runner.temp }}/satkit-empty-data
          SATKIT_OFFLINE: "1"
        run: |
          mkdir -p "$SATKIT_DATA"
          cargo test --features chrono --lib offline_
          cargo test --features chrono --test offline_smoke
          cargo build --no-default-features

      # Already covered by `cargo test` above; re-run with --nocapture so the
      # per-case max residual vs GMAT (tests/gmat/README.md) is visible in the log.
      - name: GMAT regression residuals
        run: cargo test --test gmat_regression -- --nocapture

      - name: Doc
        run: cargo doc --no-deps

  python:
    name: python bindings test
    runs-on: ubuntu-latest

    env:
      SATKIT_DATA: astro-data
      SATKIT_TESTVEC_ROOT: satkit-testvecs

    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable

      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.13"

      - name: Cache Satkit Data
        id: cache-satkit-data
        uses: actions/cache@v4
        with:
          path: astro-data
          enableCrossOsArchive: true
          key: satkit-data-${{ hashFiles('data/manifest.json') }}

      - name: Download Satkit Data
        if: steps.cache-satkit-data.outputs.cache-hit != 'true'
        run: |
          pip install requests
          python python/test/download_data.py astro-data

      - name: Cache Satkit Test Vectors
        id: cache-satkit-testvecs
        uses: actions/cache@v4
        with:
          path: satkit-testvecs
          enableCrossOsArchive: true
          key: satkit-testvecs-cache

      - name: Download Satkit Test Vectors
        if: steps.cache-satkit-testvecs.outputs.cache-hit != 'true'
        run: |
          pip install requests
          python python/test/download_testvecs.py satkit-testvecs

      - name: Cargo Cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-python-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo-python-

      - name: Install satkit
        run: pip install -e ".[test]"

      - name: Run Python tests
        run: pytest python/test/

      # Same offline guarantee from Python: empty data dir, downloads forbidden.
      - name: Python offline smoke test (empty data directory)
        env:
          SATKIT_DATA: ${{ runner.temp }}/satkit-empty-data
          SATKIT_OFFLINE: "1"
        run: |
          mkdir -p "$SATKIT_DATA"
          pytest python/test/test_offline.py -v

      # Already covered above; listed per case for visibility (see tests/gmat/README.md).
      - name: GMAT regression (Python)
        run: pytest python/test/test_gmat.py -v

      # Verify the hand-written .pyi stubs still match the compiled bindings.
      # --ignore-positional-only / --ignore-disjoint-bases switch off two whole
      # PyO3-idiom categories; the rest is handled by the allowlist.
      - name: Check type stubs match bindings (stubtest)
        run: |
          python -m mypy.stubtest satkit \
            --allowlist python/stubtest_allowlist.txt \
            --ignore-positional-only \
            --ignore-disjoint-bases