From 926bcdd82beb93e83f55f10fd03439a951425693 Mon Sep 17 00:00:00 2001 From: Jiangzhou He Date: Mon, 24 Nov 2025 08:58:48 -0800 Subject: [PATCH 1/2] feat: add sanity check to make sure Python and engine version conssitent --- .github/scripts/update_version.sh | 1 + .github/workflows/release.yml | 32 +++++-------------- python/cocoindex/__init__.py | 5 +++ python/cocoindex/_version.py | 3 ++ python/cocoindex/_version_check.py | 49 ++++++++++++++++++++++++++++++ rust/cocoindex/src/py/mod.rs | 2 ++ 6 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 python/cocoindex/_version.py create mode 100644 python/cocoindex/_version_check.py diff --git a/.github/scripts/update_version.sh b/.github/scripts/update_version.sh index b2e60857d..e8941655f 100755 --- a/.github/scripts/update_version.sh +++ b/.github/scripts/update_version.sh @@ -20,3 +20,4 @@ fi # Update Cargo.toml sed "${SED_INLINE[@]}" "s/^version = .*/version = \"$VERSION\"/" Cargo.toml +echo "__version__ = \"$VERSION\"" > python/cocoindex/_version.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f91d9d1e7..27629ba87 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,25 +15,13 @@ permissions: pages: write jobs: - create-versioned-toml: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - run: ./.github/scripts/update_version.sh - - uses: actions/upload-artifact@v4 - with: - name: Cargo.toml - path: Cargo.toml - generate-3p-notices: runs-on: ubuntu-latest - needs: [create-versioned-toml] steps: - uses: actions/checkout@v4 with: fetch-depth: 1 + - run: ./.github/scripts/update_version.sh - uses: actions/download-artifact@v4 with: name: Cargo.toml @@ -54,7 +42,7 @@ jobs: build: runs-on: ${{ matrix.platform.runner }} - needs: [create-versioned-toml, generate-3p-notices] + needs: [generate-3p-notices] strategy: matrix: platform: @@ -67,9 +55,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/download-artifact@v4 - with: - name: Cargo.toml + - run: ./.github/scripts/update_version.sh - uses: actions/download-artifact@v4 with: name: THIRD_PARTY_NOTICES.html @@ -110,14 +96,12 @@ jobs: sdist: runs-on: ubuntu-latest - needs: [create-versioned-toml, generate-3p-notices] + needs: [generate-3p-notices] steps: - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/download-artifact@v4 - with: - name: Cargo.toml + - run: ./.github/scripts/update_version.sh - uses: actions/download-artifact@v4 with: name: THIRD_PARTY_NOTICES.html @@ -135,7 +119,7 @@ jobs: release: name: Release runs-on: ubuntu-latest - needs: [create-versioned-toml, build, test-abi3, sdist, generate-3p-notices] + needs: [build, test-abi3, sdist, generate-3p-notices] permissions: # Use to sign the release artifacts id-token: write @@ -148,9 +132,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/download-artifact@v4 - with: - name: Cargo.toml + - run: ./.github/scripts/update_version.sh - uses: actions/download-artifact@v4 with: name: THIRD_PARTY_NOTICES.html diff --git a/python/cocoindex/__init__.py b/python/cocoindex/__init__.py index 024595b1a..a76520f7d 100644 --- a/python/cocoindex/__init__.py +++ b/python/cocoindex/__init__.py @@ -2,6 +2,10 @@ Cocoindex is a framework for building and running indexing pipelines. """ +from ._version import __version__ + +from . import _version_check + from . import _engine # type: ignore from . import functions, sources, targets, cli, utils @@ -46,6 +50,7 @@ _engine.init_pyo3_runtime() __all__ = [ + "__version__", # Submodules "_engine", "functions", diff --git a/python/cocoindex/_version.py b/python/cocoindex/_version.py new file mode 100644 index 000000000..7fa6f60c0 --- /dev/null +++ b/python/cocoindex/_version.py @@ -0,0 +1,3 @@ +# This file will be rewritten by the release workflow. +# DO NOT ADD ANYTHING ELSE TO THIS FILE. +__version__ = "999.0.0" diff --git a/python/cocoindex/_version_check.py b/python/cocoindex/_version_check.py new file mode 100644 index 000000000..e61c64942 --- /dev/null +++ b/python/cocoindex/_version_check.py @@ -0,0 +1,49 @@ +from __future__ import annotations + +import sys +from . import _engine +from . import __version__ + + +def _sanity_check_engine() -> None: + engine_file = getattr(_engine, "__file__", "") + engine_version = getattr(_engine, "__version__", None) + + problems: list[str] = [] + + # Version mismatch (if the engine exposes its own version) + if engine_version is not None and engine_version != __version__: + problems.append( + f"Version mismatch: Python package is {__version__!r}, " + f"but cocoindex._engine reports {engine_version!r}." + ) + + if problems: + # Helpful diagnostic message for users + msg_lines = [ + "Inconsistent cocoindex installation detected:", + *[f" - {p}" for p in problems], + "", + f"Python executable: {sys.executable}", + f"cocoindex package file: {__file__}", + f"cocoindex._engine file: {engine_file}", + "", + "This usually happens when:", + " * An old 'cocoindex._engine' .pyd is still present in the", + " package directory, or", + " * Multiple 'cocoindex' copies exist on sys.path", + " (e.g. a local checkout + an installed wheel).", + "", + "Suggested fix:", + " 1. Uninstall cocoindex completely:", + " pip uninstall cocoindex", + " 2. Reinstall it cleanly:", + " pip install --no-cache-dir cocoindex", + " 3. Ensure there is no local 'cocoindex' directory or old", + " .pyd shadowing the installed package.", + ] + raise RuntimeError("\n".join(msg_lines)) + + +_sanity_check_engine() +del _sanity_check_engine diff --git a/rust/cocoindex/src/py/mod.rs b/rust/cocoindex/src/py/mod.rs index 50f0b16fe..18f793891 100644 --- a/rust/cocoindex/src/py/mod.rs +++ b/rust/cocoindex/src/py/mod.rs @@ -606,6 +606,8 @@ fn seder_roundtrip<'py>( #[pymodule] #[pyo3(name = "_engine")] fn cocoindex_engine(m: &Bound<'_, PyModule>) -> PyResult<()> { + m.add("__version__", env!("CARGO_PKG_VERSION"))?; + m.add_function(wrap_pyfunction!(init_pyo3_runtime, m)?)?; m.add_function(wrap_pyfunction!(init, m)?)?; m.add_function(wrap_pyfunction!(set_settings_fn, m)?)?; From c9de039d064d608772771c566066972d3e8faa20 Mon Sep 17 00:00:00 2001 From: Jiangzhou He Date: Mon, 24 Nov 2025 09:02:46 -0800 Subject: [PATCH 2/2] fix: remove unnecessary download --- .github/workflows/release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 27629ba87..fdefe85ff 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,9 +22,6 @@ jobs: with: fetch-depth: 1 - run: ./.github/scripts/update_version.sh - - uses: actions/download-artifact@v4 - with: - name: Cargo.toml - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable - uses: taiki-e/install-action@v2