apexbase 1.25.0

High-performance HTAP embedded database with Rust core
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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
name: Build and Release

on:
  push:
    tags:
      - 'v*'
  workflow_dispatch:
    inputs:
      tag:
        description: 'Existing Git tag to build and publish as a release (e.g., v1.0.0)'
        required: true
        type: string

env:
  # The repo's local Cargo config uses target-cpu=native for developer and
  # benchmark builds. CI builds must stay portable because GitHub runners and
  # restored proc-macro artifacts can land on hosts with different CPU features.
  RUSTFLAGS: "-C target-cpu=generic"
  APEXBASE_CI_CPU: "generic"

jobs:
  # Resolve the requested tag before choosing the legacy Python or maturin path.
  resolve-release:
    runs-on: ubuntu-latest
    outputs:
      tag_name: ${{ steps.inspect.outputs.tag_name }}
      package_kind: ${{ steps.inspect.outputs.package_kind }}
      rust_features: ${{ steps.inspect.outputs.rust_features }}
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: Inspect release tag
      id: inspect
      env:
        RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
      shell: bash
      run: |
        if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+(\.[0-9]+)*([-.][0-9A-Za-z]+)*$ ]]; then
          echo "Release tag must look like v0.0.1; got '$RELEASE_TAG'."
          exit 1
        fi
        git rev-parse "refs/tags/$RELEASE_TAG^{commit}" >/dev/null
        git checkout --detach "refs/tags/$RELEASE_TAG"
        python - <<'PY'
        import json
        import os
        import sys
        import tomllib
        from pathlib import Path

        tag = os.environ["RELEASE_TAG"]
        pyproject = Path("pyproject.toml")
        if not pyproject.exists():
            sys.exit("The release tag has no pyproject.toml.")
        project = tomllib.loads(pyproject.read_text(encoding="utf-8"))
        version = project.get("project", {}).get("version")
        backend = project.get("build-system", {}).get("build-backend", "")
        if version != tag.removeprefix("v"):
            sys.exit(f"Package version {version!r} does not match tag {tag!r}.")
        package_kind = "maturin" if "maturin" in backend else "legacy"
        rust_features = [""]
        cargo_file = Path("Cargo.toml")
        if package_kind == "maturin" and cargo_file.exists():
            cargo = tomllib.loads(cargo_file.read_text(encoding="utf-8"))
            available_features = cargo.get("features", {})
            rust_features.extend(
                feature for feature in ("server", "flight")
                if feature in available_features
            )
        with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
            print(f"tag_name={tag}", file=output)
            print(f"package_kind={package_kind}", file=output)
            print(f"rust_features={json.dumps(rust_features)}", file=output)
        PY

  # ── Rust tests (core lib without PyO3, plus server/flight features) ──
  rust-test:
    needs: resolve-release
    if: needs.resolve-release.outputs.package_kind == 'maturin'
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        features: ${{ fromJSON(needs.resolve-release.outputs.rust_features) }}
        rust: [stable]
      fail-fast: false

    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        ref: ${{ github.event.inputs.tag || github.ref }}

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

    - name: Rust cache
      uses: Swatinem/rust-cache@v2
      with:
        key: ${{ matrix.os }}-${{ matrix.features }}-${{ env.APEXBASE_CI_CPU }}

    - name: Install system dependencies (Linux)
      if: runner.os == 'Linux'
      run: |
        sudo apt-get update
        sudo apt-get install -y protobuf-compiler

    - name: Install system dependencies (macOS)
      if: runner.os == 'macOS'
      run: |
        brew install protobuf

    - name: Install system dependencies (Windows)
      if: runner.os == 'Windows'
      run: |
        choco install protoc -y

    - name: Validate Rust (${{ matrix.features && format('{0} feature', matrix.features) || 'core only' }})
      shell: bash
      run: |
        if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
          # Historical release backfills must validate the publishable library,
          # not recompile old test targets with today's Rust/dependency graph.
          cargo check --lib --no-default-features ${{ matrix.features && format('--features {0}', matrix.features) || '' }} --release
        else
          cargo test --no-default-features ${{ matrix.features && format('--features {0}', matrix.features) || '' }} --release
        fi
      env:
        RUST_BACKTRACE: 1

  # ── Python tests (existing) ──
  test:
    needs: resolve-release
    if: needs.resolve-release.outputs.package_kind == 'maturin'
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
      fail-fast: false

    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        ref: ${{ github.event.inputs.tag || github.ref }}

    - name: Install Rust stable
      uses: dtolnay/rust-toolchain@stable

    - name: Rust cache
      uses: Swatinem/rust-cache@v2
      with:
        key: python-${{ matrix.os }}-${{ matrix.python-version }}-${{ env.APEXBASE_CI_CPU }}

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

    - name: Install system dependencies (Linux)
      if: runner.os == 'Linux'
      run: |
        sudo apt-get update
        sudo apt-get install -y protobuf-compiler

    - name: Install system dependencies (macOS)
      if: runner.os == 'macOS'
      run: |
        brew install protobuf

    - name: Install system dependencies (Windows)
      if: runner.os == 'Windows'
      run: |
        choco install protoc -y

    - name: Install dependencies
      shell: bash
      run: |
        python -m venv .venv
        python - <<'PY'
        import os
        import pathlib
        import subprocess
        import sys

        venv = pathlib.Path(".venv").resolve()
        bin_dir = venv / ("Scripts" if os.name == "nt" else "bin")
        python = bin_dir / ("python.exe" if os.name == "nt" else "python")
        env = os.environ.copy()
        env["VIRTUAL_ENV"] = str(venv)
        env["PATH"] = str(bin_dir) + os.pathsep + env.get("PATH", "")

        subprocess.check_call([str(python), "-m", "pip", "install", "--upgrade", "pip"])
        # Keep the native-extension test stack pinned. The pytest suite loads
        # ApexBase, NumPy, PyArrow, pandas, and Polars in the same process; using
        # floating latest wheels has produced macOS native hangs during pytest.
        # Newer NumPy/PyArrow/pandas/Polars releases have dropped older Python
        # versions at different points, so pin by interpreter instead of using
        # one native stack for the whole 3.9-3.13 matrix.
        test_deps = [
            "pytest==8.4.2",
            "pytest-timeout==2.4.0",
            "maturin==1.9.1",
        ]
        if sys.version_info < (3, 10):
            test_deps.extend([
                "numpy==2.0.2",
                "pyarrow==17.0.0",
                "pandas==2.3.2",
                "polars==1.36.1",
            ])
        elif sys.version_info < (3, 11):
            test_deps.extend([
                "numpy==2.1.3",
                "pyarrow==17.0.0",
                "pandas==2.3.2",
                "polars==1.39.3",
            ])
        else:
            test_deps.extend([
                "numpy==2.1.3",
                "pyarrow==23.0.1",
                "pandas==3.0.1",
                "polars==1.39.3",
            ])
        print("Installing test dependencies:")
        for dep in test_deps:
            print(f"  {dep}")
        subprocess.check_call([str(python), "-m", "pip", "install", *test_deps])
        subprocess.check_call([str(python), "-m", "maturin", "develop", "--release", "--skip-install"], env=env)
        smoke = """
        import sys
        import tempfile
        sys.path.insert(0, 'apexbase/python')
        import apexbase
        import apexbase._core as core
        print(apexbase.__file__)
        print(core.__file__)
        with tempfile.TemporaryDirectory() as tmpdir:
            client = apexbase.ApexClient(dirpath=tmpdir)
            client.create_table('smoke')
            client.close()
        """
        subprocess.check_call([
            str(python),
            "-c",
            smoke,
        ], env=env)

        with open(os.environ["GITHUB_PATH"], "a", encoding="utf-8") as path_file:
            path_file.write(str(bin_dir) + os.linesep)
        with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8") as env_file:
            env_file.write(f"VIRTUAL_ENV={venv}{os.linesep}")
        PY

    - name: Run tests
      timeout-minutes: 10
      shell: bash
      run: |
        python - <<'PY'
        import sys
        from pathlib import Path

        sys.path.insert(0, str(Path("apexbase/python").resolve()))

        import apexbase
        import apexbase._core as core
        import numpy
        import pandas
        import polars
        import pyarrow
        import pytest

        print(f"python={sys.version}")
        print(f"apexbase={apexbase.__file__}")
        print(f"apexbase_core={core.__file__}")
        print(f"pytest={pytest.__version__}")
        print(f"numpy={numpy.__version__}")
        print(f"pyarrow={pyarrow.__version__}")
        print(f"pandas={pandas.__version__}")
        print(f"polars={polars.__version__}")
        PY
        python -X faulthandler -m pytest \
          --ignore=test/test_memory_vs_duckdb.py \
          --timeout=30 \
          --durations=40
      env:
        PYTHONFAULTHANDLER: "1"
        RUST_BACKTRACE: "1"

  # ── Build Linux wheels (manylinux) ──
  build-wheels-linux:
    needs: [resolve-release, test, rust-test]
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        ref: ${{ github.event.inputs.tag || github.ref }}

    - name: Build wheels (manylinux)
      uses: PyO3/maturin-action@v1
      env:
        RUSTFLAGS: ${{ env.RUSTFLAGS }}
      with:
        maturin-version: v1.9.1
        command: build
        args: --release --out dist --interpreter /opt/python/cp39-cp39/bin/python /opt/python/cp310-cp310/bin/python /opt/python/cp311-cp311/bin/python /opt/python/cp312-cp312/bin/python /opt/python/cp313-cp313/bin/python
        manylinux: 2014

    - name: Upload wheel artifacts
      uses: actions/upload-artifact@v4
      with:
        name: wheels-manylinux
        path: dist/*.whl

  # ── Build macOS / Windows wheels ──
  build-wheels:
    needs: [resolve-release, test, rust-test]
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [windows-latest, macos-latest]
        python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
      fail-fast: false
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        ref: ${{ github.event.inputs.tag || github.ref }}

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

    - name: Show Python
      run: |
        python -c "import sys; print(sys.executable); print(sys.version)"

    - name: Build wheels
      uses: PyO3/maturin-action@v1
      env:
        RUSTFLAGS: ${{ env.RUSTFLAGS }}
        PYO3_PYTHON: ${{ steps.py.outputs.python-path }}
        PYTHON_SYS_EXECUTABLE: ${{ steps.py.outputs.python-path }}
      with:
        maturin-version: v1.9.1
        command: build
        args: --release --out dist --interpreter ${{ steps.py.outputs.python-path }}

    - name: Smoke test wheel (ApexStorage init)
      if: matrix.os == 'macos-latest' && matrix.python-version == '3.12'
      shell: bash
      run: |
        python -m pip install --upgrade pip
        python -m pip install "$(ls dist/*.whl | head -1)"
        python - <<'PY'
        import sys
        import tempfile
        import os

        # Import path used by repro scripts / minimal integrations.
        from apexbase._core import ApexStorage

        db_dir = tempfile.mkdtemp(prefix="apexbase_wheel_smoke_")
        ApexStorage(os.path.join(db_dir, "apexbase.apex"))
        print("wheel smoke test OK", sys.version.split()[0])
        PY

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

  # ── Build source distribution ──
  build-sdist:
    needs: [resolve-release, test, rust-test]
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        ref: ${{ github.event.inputs.tag || github.ref }}
    - name: Build sdist
      uses: PyO3/maturin-action@v1
      with:
        maturin-version: v1.9.1
        command: sdist
        args: --out dist
    - name: Upload sdist artifact
      uses: actions/upload-artifact@v4
      with:
        name: sdist
        path: dist/*.tar.gz

  # ── Publish to PyPI ──
  publish:
    needs: [build-wheels-linux, build-wheels, build-sdist]
    runs-on: ubuntu-latest
    steps:
    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: "3.11"
    - name: Install twine
      run: |
        python -m pip install --upgrade pip
        pip install twine
    - name: Download artifacts
      uses: actions/download-artifact@v4
      with:
        path: dist
    - name: Publish to PyPI
      env:
        TWINE_USERNAME: __token__
        TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
      run: |
        python -m twine upload --verbose --skip-existing dist/**/*.whl dist/**/*.tar.gz

  # ── Publish to crates.io ──
  publish-crate:
    needs: [resolve-release, rust-test]
    if: needs.resolve-release.outputs.package_kind == 'maturin'
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        ref: ${{ github.event.inputs.tag || github.ref }}

    - name: Install Rust stable
      uses: dtolnay/rust-toolchain@stable

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

    - name: Install system dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y protobuf-compiler

    - name: Verify crate packaging
      run: |
        cargo package --no-default-features --allow-dirty --list

    - name: Publish to crates.io (if version not exists)
      run: |
        VERSION=$(grep "^version" Cargo.toml | head -1 | cut -d'"' -f2)
        echo "Checking if apexbase v${VERSION} exists on crates.io..."
        if cargo search apexbase --limit 1 2>/dev/null | grep -q "apexbase = \"${VERSION}\""; then
          echo "Version ${VERSION} already exists on crates.io, skipping publish."
          exit 0
        fi
        echo "Publishing apexbase v${VERSION}..."
        cargo publish --no-default-features --allow-dirty
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  # ── Build and publish historical pure-Python releases ──
  build-legacy:
    needs: resolve-release
    if: needs.resolve-release.outputs.package_kind == 'legacy'
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        ref: ${{ needs.resolve-release.outputs.tag_name }}
    - uses: actions/setup-python@v5
      with:
        python-version: "3.11"
    - name: Build pure-Python wheel and source distribution
      run: |
        python -m pip install --upgrade pip build
        python -m build --wheel --sdist --outdir dist
    - name: Upload legacy distributions
      uses: actions/upload-artifact@v4
      with:
        name: legacy-distributions
        path: |
          dist/*.whl
          dist/*.tar.gz
        if-no-files-found: error

  publish-legacy:
    needs: [resolve-release, build-legacy]
    if: needs.resolve-release.outputs.package_kind == 'legacy'
    runs-on: ubuntu-latest
    steps:
    - uses: actions/download-artifact@v4
      with:
        name: legacy-distributions
        path: dist
    - name: Publish legacy package to PyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        packages-dir: dist
        password: ${{ secrets.PYPI_API_TOKEN }}
        skip-existing: true

  # ── Create GitHub Release ──
  create-release:
    needs: [resolve-release, publish, publish-crate, publish-legacy]
    if: >-
      always() &&
      needs.resolve-release.result == 'success' &&
      (needs.publish.result == 'success' || needs.publish.result == 'skipped') &&
      (needs.publish-crate.result == 'success' || needs.publish-crate.result == 'skipped') &&
      (needs.publish-legacy.result == 'success' || needs.publish-legacy.result == 'skipped')
    runs-on: ubuntu-latest
    permissions:
      contents: write
    env:
      RELEASE_TAG: ${{ needs.resolve-release.outputs.tag_name }}
    steps:
    - name: Checkout release notes from the default branch
      uses: actions/checkout@v4
      with:
        ref: ${{ github.event.repository.default_branch }}

    - name: Download all artifacts
      uses: actions/download-artifact@v4
      with:
        path: all-artifacts

    - name: Prepare release assets
      run: |
        mkdir -p release-assets
        find all-artifacts -type f \( -name "*.whl" -o -name "*.tar.gz" \) -exec cp {} release-assets/ \;
        echo "Release assets prepared:"
        ls -lh release-assets/

    - name: Extract release notes for tag
      env:
        RELEASE_NOTES_FILE: docs/release-notes.md
      run: |
        python - <<'PY'
        import os
        import re
        import sys
        from pathlib import Path

        tag = os.environ["RELEASE_TAG"]
        source = Path(os.environ["RELEASE_NOTES_FILE"])
        if not source.exists():
            sys.exit(f"Release notes file not found: {source}")

        text = source.read_text(encoding="utf-8")
        heading = re.compile(
            rf"^##\s+(?:\[{re.escape(tag)}\]\([^)]+\)|{re.escape(tag)})\s*$",
            re.MULTILINE,
        )
        match = heading.search(text)
        if not match:
            sys.exit(f"No release notes section found for {tag} in {source}.")

        next_heading = re.search(r"^##\s+", text[match.end():], re.MULTILINE)
        end = match.end() + next_heading.start() if next_heading else len(text)
        body = text[match.end():end].strip()
        body = re.sub(r"\n---\s*$", "", body).strip()
        if not body:
            sys.exit(f"Release notes section for {tag} is empty.")

        Path("release-body.md").write_text(body + "\n", encoding="utf-8")
        print(f"Extracted release notes for {tag} from {source}")
        PY

    - name: Create GitHub Release with assets
      uses: softprops/action-gh-release@v2
      with:
        tag_name: ${{ env.RELEASE_TAG }}
        name: ApexBase ${{ env.RELEASE_TAG }}
        body_path: release-body.md
        files: release-assets/*
        fail_on_unmatched_files: true
        draft: false
        prerelease: ${{ contains(env.RELEASE_TAG, 'alpha') || contains(env.RELEASE_TAG, 'beta') || contains(env.RELEASE_TAG, 'rc') }}
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}