evlib 0.8.7

Event Camera Data Processing Library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
name: Publish

on:
  push:
    branches:
      - main
      - master
  workflow_dispatch:
    inputs:
      publish_to:
        description: "Where to publish"
        required: true
        default: "both"
        type: choice
        options: [both, pypi, crates]
      test_mode:
        description: "Use test repositories"
        required: false
        default: false
        type: boolean

jobs:
  check-version:
    runs-on: ubuntu-latest
    if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' || github.event_name == 'push'
    outputs:
      version: ${{ steps.version.outputs.version }}
      should_publish: ${{ steps.check.outputs.should_publish }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 2

      - name: Get version and check if changed
        id: version
        run: |
          version=$(grep '^version[[:space:]]*=' Cargo.toml | head -1 | sed 's/.*"\([^"]*\)".*/\1/')
          echo "version=$version" >> $GITHUB_OUTPUT
          echo "Current version: $version"

      - name: Check if should publish
        id: check
        run: |
          if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
            echo "should_publish=true" >> $GITHUB_OUTPUT
          elif git diff HEAD~1 HEAD --name-only | grep -q "Cargo.toml"; then
            prev_version=$(git show HEAD~1:Cargo.toml | grep '^version[[:space:]]*=' | head -1 | sed 's/.*"\([^"]*\)".*/\1/')
            if [ "${{ steps.version.outputs.version }}" != "$prev_version" ]; then
              echo "should_publish=true" >> $GITHUB_OUTPUT
            else
              echo "should_publish=false" >> $GITHUB_OUTPUT
            fi
          else
            echo "should_publish=false" >> $GITHUB_OUTPUT
          fi

  build-wheels:
    runs-on: ${{ matrix.os }}
    needs: [check-version]
    timeout-minutes: 30
    if: |
      needs.check-version.outputs.should_publish == 'true' &&
      (github.event_name == 'push' || github.event.inputs.publish_to == 'both' || github.event.inputs.publish_to == 'pypi' || github.event.inputs.publish_to == '')
    strategy:
      fail-fast: false
      matrix:
        include:
          # macOS builds (Apple Silicon only - Intel users can use Rosetta 2)
          - os: macos-latest  # ARM64 macOS (Apple Silicon)
            platform: macos
            arch: arm64
            python-version: "3.10"
          - os: macos-latest
            platform: macos
            arch: arm64
            python-version: "3.11"
          - os: macos-latest
            platform: macos
            arch: arm64
            python-version: "3.12"

          # Windows builds (no HDF5 support)
          - os: windows-latest
            platform: windows
            arch: x64
            python-version: "3.10"
          - os: windows-latest
            platform: windows
            arch: x64
            python-version: "3.11"
          - os: windows-latest
            platform: windows
            arch: x64
            python-version: "3.12"

    steps:
      - uses: actions/checkout@v4

      - name: Setup dependencies (Unix)
        if: matrix.platform != 'windows'
        uses: ./.github/actions/setup-dependencies
        with:
          python-version: ${{ matrix.python-version }}
          os: ${{ matrix.os }}

      - name: Setup Python (Windows)
        if: matrix.platform == 'windows'
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install UV (Windows)
        if: matrix.platform == 'windows'
        run: pip install uv

      - name: Create venv (Windows)
        if: matrix.platform == 'windows'
        run: uv venv --python ${{ matrix.python-version }}

      - name: Set up Rust
        uses: dtolnay/rust-toolchain@nightly
        with:
          targets: ${{ matrix.platform == 'linux' && 'x86_64-unknown-linux-gnu' || matrix.platform == 'macos' && matrix.arch == 'arm64' && 'aarch64-apple-darwin' || matrix.platform == 'windows' && 'x86_64-pc-windows-msvc' || 'x86_64-apple-darwin' }}

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          key: build-wheels-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.arch }}

      - name: Install maturin (Unix)
        if: matrix.platform != 'windows'
        run: |
          source .venv/bin/activate
          uv pip install maturin>=1.7.4

      - name: Install maturin (Windows)
        if: matrix.platform == 'windows'
        run: |
          .venv\Scripts\activate
          uv pip install maturin>=1.7.4

      - name: Build wheels (Unix)
        if: matrix.platform != 'windows'
        run: |
          source .venv/bin/activate

          # Set target architecture for cross-compilation
          if [ "${{ matrix.platform }}" = "macos" ] && [ "${{ matrix.arch }}" = "arm64" ]; then
            export CARGO_BUILD_TARGET="aarch64-apple-darwin"
          elif [ "${{ matrix.platform }}" = "macos" ] && [ "${{ matrix.arch }}" = "x86_64" ]; then
            export CARGO_BUILD_TARGET="x86_64-apple-darwin"
          fi

          # Build wheel with all features on Unix (HDF5 included via platform dependencies)
          maturin build --release --features python,polars,arrow --interpreter python${{ matrix.python-version }} --out dist

      - name: Build wheels (Windows)
        if: matrix.platform == 'windows'
        run: |
          .venv\Scripts\activate
          # Windows builds exclude HDF5 due to build complexity
          maturin build --release --features python,polars --interpreter python --out dist
        env:
          CARGO_BUILD_TARGET: x86_64-pc-windows-msvc

      - name: Upload wheels as artifacts
        uses: actions/upload-artifact@v4
        with:
          name: wheels-${{ matrix.platform }}-${{ matrix.arch }}-py${{ matrix.python-version }}
          path: dist/*.whl

  # Build manylinux wheels with proper HDF5 environment setup
  build-wheels-linux:
    runs-on: ubuntu-latest
    needs: [check-version]
    timeout-minutes: 45
    if: |
      needs.check-version.outputs.should_publish == 'true' &&
      (github.event_name == 'push' || github.event.inputs.publish_to == 'both' || github.event.inputs.publish_to == 'pypi' || github.event.inputs.publish_to == '')

    strategy:
      matrix:
        python-version: ['3.10', '3.11', '3.12']

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}

      - name: Set up Rust
        uses: dtolnay/rust-toolchain@nightly

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          key: build-wheels-linux-${{ matrix.python-version }}

      - name: Create HDF5 setup script
        run: |
          cat > setup-hdf5.sh << 'EOF'
          #!/bin/bash
          set -e
          echo "=== Installing system dependencies ==="
          yum install -y openssl-devel pkgconfig cmake3 wget tar make gcc-c++ zlib-devel

          echo "=== Building HDF5 ==="
          cd /tmp
          wget -q https://github.com/HDFGroup/hdf5/archive/refs/tags/hdf5_1.14.4.3.tar.gz
          tar -xzf hdf5_1.14.4.3.tar.gz
          cd hdf5-hdf5_1.14.4.3

          ./configure \
            --prefix=/usr/local/hdf5 \
            --enable-build-mode=production \
            --with-szlib \
            --enable-shared \
            --disable-static \
            --disable-fortran \
            --disable-cxx \
            CFLAGS="-O2 -fPIC"

          make -j $(nproc) && make install

          echo "/usr/local/hdf5/lib" > /etc/ld.so.conf.d/hdf5.conf
          ldconfig

          # Make pkg-config file available
          mkdir -p /usr/local/lib/pkgconfig
          if [ -f "/usr/local/hdf5/lib/pkgconfig/hdf5.pc" ]; then
            cp /usr/local/hdf5/lib/pkgconfig/hdf5.pc /usr/local/lib/pkgconfig/
          fi

          echo "=== HDF5 setup complete ==="
          EOF
          chmod +x setup-hdf5.sh

      - name: Build wheels with maturin-action
        uses: PyO3/maturin-action@v1
        with:
          command: build
          args: --release --features python,polars,arrow --interpreter python${{ matrix.python-version }}
          rust-toolchain: nightly
          manylinux: 2014
          before-script-linux: |
            # Save current directory
            ORIGINAL_DIR=$(pwd)

            # Install system dependencies
            yum install -y openssl-devel pkgconfig cmake3 wget tar make gcc-c++ zlib-devel

            # Build HDF5 in temporary directory
            cd /tmp
            wget -q https://github.com/HDFGroup/hdf5/archive/refs/tags/hdf5_1.14.4.3.tar.gz
            tar -xzf hdf5_1.14.4.3.tar.gz
            cd hdf5-hdf5_1.14.4.3
            ./configure --prefix=/usr/local/hdf5 --enable-build-mode=production --with-szlib --enable-shared --disable-static --disable-fortran --disable-cxx CFLAGS="-O2 -fPIC"
            make -j $(nproc) && make install

            # Configure system for HDF5
            echo "/usr/local/hdf5/lib" > /etc/ld.so.conf.d/hdf5.conf
            ldconfig
            mkdir -p /usr/local/lib/pkgconfig
            [ -f "/usr/local/hdf5/lib/pkgconfig/hdf5.pc" ] && cp /usr/local/hdf5/lib/pkgconfig/hdf5.pc /usr/local/lib/pkgconfig/

            # Return to project directory
            cd "$ORIGINAL_DIR"

            # Set environment variables for the build
            export PKG_CONFIG_PATH="/usr/local/hdf5/lib/pkgconfig:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
            export LD_LIBRARY_PATH="/usr/local/hdf5/lib:$LD_LIBRARY_PATH"
            export HDF5_ROOT="/usr/local/hdf5"
            export HDF5_DIR="/usr/local/hdf5"
        env:
          PKG_CONFIG_PATH: "/usr/local/hdf5/lib/pkgconfig:/usr/local/lib/pkgconfig"
          LD_LIBRARY_PATH: "/usr/local/hdf5/lib"
          HDF5_ROOT: "/usr/local/hdf5"
          HDF5_DIR: "/usr/local/hdf5"

      - name: Upload Linux wheels as artifacts
        uses: actions/upload-artifact@v4
        with:
          name: wheels-linux-py${{ matrix.python-version }}
          path: target/wheels/*.whl

  publish-pypi:
    runs-on: ubuntu-latest
    needs: [check-version, build-wheels, build-wheels-linux]
    if: |
      needs.check-version.outputs.should_publish == 'true' &&
      (github.event_name == 'push' || github.event.inputs.publish_to == 'both' || github.event.inputs.publish_to == 'pypi' || github.event.inputs.publish_to == '')

    steps:
      - uses: actions/checkout@v4

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"

      - name: Download all wheel artifacts
        uses: actions/download-artifact@v4
        with:
          path: dist/
          pattern: wheels-*
          merge-multiple: true

      - name: List built wheels
        run: |
          echo "Built wheels:"
          ls -la dist/
          echo
          echo "Wheel details:"
          for wheel in dist/*.whl; do
            echo "$(basename "$wheel"): $(python -m zipfile -l "$wheel" | grep -E '\.(so|pyd)$' || echo 'No native extensions found')"
          done

      - name: Install twine
        run: pip install twine

      - name: Publish to PyPI
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
          TEST_TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
        run: |
          if [ "${{ github.event.inputs.test_mode }}" = "true" ]; then
            echo "TEST MODE: Uploading to TestPyPI"
            twine upload --repository testpypi --username __token__ --password "$TEST_TWINE_PASSWORD" dist/*.whl --skip-existing --verbose
          else
            echo "Uploading to PyPI"
            twine upload --username __token__ --password "$TWINE_PASSWORD" dist/*.whl --skip-existing --verbose
          fi

  publish-crates:
    runs-on: ubuntu-latest
    needs: [check-version]
    if: |
      needs.check-version.outputs.should_publish == 'true' &&
      (github.event_name == 'push' || github.event.inputs.publish_to == 'both' || github.event.inputs.publish_to == 'crates' || github.event.inputs.publish_to == '')
    steps:
      - uses: actions/checkout@v4

      - name: Setup dependencies
        uses: ./.github/actions/setup-dependencies
        with:
          python-version: "3.11"
          os: ubuntu-latest

      - name: Set up Rust
        uses: dtolnay/rust-toolchain@nightly

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2

      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}
        run: |
          if [ "${{ github.event.inputs.test_mode }}" = "true" ]; then
            echo "TEST MODE: Dry-run publish"
            cargo publish --dry-run
          else
            echo "Publishing version ${{ needs.check-version.outputs.version }}"
            cargo publish --token $CARGO_REGISTRY_TOKEN
          fi

  create-release:
    runs-on: ubuntu-latest
    needs: [check-version, publish-crates, publish-pypi]
    if: |
      always() &&
      needs.check-version.outputs.should_publish == 'true' &&
      github.event.inputs.test_mode != 'true' &&
      (needs.publish-crates.result == 'success' || needs.publish-crates.result == 'skipped') &&
      (needs.publish-pypi.result == 'success' || needs.publish-pypi.result == 'skipped')
    steps:
      - uses: actions/checkout@v4

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: v${{ needs.check-version.outputs.version }}
          name: Release v${{ needs.check-version.outputs.version }}
          body: |
            ## evlib v${{ needs.check-version.outputs.version }}

            ### Installation
            ```bash
            pip install evlib==${{ needs.check-version.outputs.version }}
            cargo add evlib@${{ needs.check-version.outputs.version }}
            ```

            ### Links
            - [PyPI Package](https://pypi.org/project/evlib/${{ needs.check-version.outputs.version }}/)
            - [crates.io Package](https://crates.io/crates/evlib/${{ needs.check-version.outputs.version }})
            - [Documentation](https://tallamjr.github.io/evlib/)

  deploy-docs:
    runs-on: ubuntu-latest
    needs: [check-version, publish-crates, publish-pypi]
    if: |
      always() &&
      needs.check-version.outputs.should_publish == 'true' &&
      github.event.inputs.test_mode != 'true' &&
      (needs.publish-crates.result == 'success' || needs.publish-crates.result == 'skipped') &&
      (needs.publish-pypi.result == 'success' || needs.publish-pypi.result == 'skipped')
    permissions:
      contents: write
      pages: write
      id-token: write
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup dependencies
        uses: ./.github/actions/setup-dependencies
        with:
          python-version: "3.11"
          os: ubuntu-latest

      - name: Set up Rust
        uses: dtolnay/rust-toolchain@nightly

      - name: Install documentation dependencies
        run: |
          source .venv/bin/activate
          uv pip install -e ".[dev]"

      - name: Build evlib for documentation
        run: |
          source .venv/bin/activate
          maturin develop --release --features python

      - name: Configure Git user
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"

      - name: Deploy documentation
        env:
          VERSION: ${{ needs.check-version.outputs.version }}
        run: |
          source .venv/bin/activate
          # Set version in mkdocs config
          export EVLIB_VERSION="v$VERSION"

          # Deploy using mike for versioning
          mkdocs build

          # Deploy to GitHub Pages using mike
          mike deploy --push --update-aliases "$VERSION" latest
          mike set-default --push latest