Skip to content

Commit ac9ef3b

Browse files
committed
feat: Add legacy-states-v0 Cargo feature for backward compatibility
1 parent 5a550dc commit ac9ef3b

File tree

4 files changed

+84
-70
lines changed

4 files changed

+84
-70
lines changed

.github/workflows/_test.yml

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Run Tests (INTERNAL)
22

33
on:
4-
workflow_call:
4+
workflow_call:
55

66
permissions:
77
contents: read
@@ -10,75 +10,78 @@ env:
1010
CARGO_TERM_COLOR: always
1111

1212
jobs:
13-
build-test:
14-
strategy:
15-
matrix:
16-
python-version: [3.11]
17-
platform:
18-
- { runner: ubuntu-latest, python_exec: ".venv/bin/python" }
19-
- { runner: ubuntu-24.04-arm, python_exec: ".venv/bin/python" }
20-
- { runner: macos-latest, python_exec: ".venv/bin/python" }
21-
- { runner: macos-13, python_exec: ".venv/bin/python" }
22-
- { runner: windows-latest, python_exec: ".venv\\Scripts\\python" }
23-
runs-on: ${{ matrix.platform.runner }}
24-
steps:
25-
- uses: actions/checkout@v4
13+
build-test:
14+
strategy:
15+
matrix:
16+
python-version: [3.11]
17+
platform:
18+
- { runner: ubuntu-latest, python_exec: ".venv/bin/python" }
19+
- { runner: ubuntu-24.04-arm, python_exec: ".venv/bin/python" }
20+
- { runner: macos-latest, python_exec: ".venv/bin/python" }
21+
- { runner: macos-13, python_exec: ".venv/bin/python" }
22+
- { runner: windows-latest, python_exec: ".venv\\Scripts\\python" }
23+
runs-on: ${{ matrix.platform.runner }}
24+
steps:
25+
- uses: actions/checkout@v4
2626

27-
- uses: actions/setup-python@v5
28-
id: setup_python
29-
with:
30-
python-version: ${{ matrix.python-version }}
31-
cache: 'pip'
27+
- uses: actions/setup-python@v5
28+
id: setup_python
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
cache: "pip"
3232

33-
- run: rustup toolchain install stable --profile minimal
34-
- name: Rust Cache
35-
uses: Swatinem/rust-cache@v2
36-
with:
37-
key: rust-${{ matrix.platform.runner }}-${{ matrix.python-version }}
38-
- name: Rust tests
39-
run: cargo test --verbose
33+
- run: rustup toolchain install stable --profile minimal
34+
- name: Rust Cache
35+
uses: Swatinem/rust-cache@v2
36+
with:
37+
key: rust-${{ matrix.platform.runner }}-${{ matrix.python-version }}
38+
- name: Rust tests
39+
run: cargo test --verbose
4040

41-
- uses: actions/cache@v4
42-
with:
43-
path: .venv
44-
key: pyenv-${{ matrix.platform.runner }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('pyproject.toml') }}
45-
restore-keys: |
46-
pyenv-${{ matrix.platform.runner }}-${{ steps.setup_python.outputs.python-version }}-
41+
- name: Rust tests (no default features)
42+
run: cargo test --no-default-features --verbose
4743

48-
- name: Setup venv
49-
run: |
50-
python -m venv .venv
51-
- name: Install Python toolchains
52-
run: |
53-
${{ matrix.platform.python_exec }} -m pip install maturin mypy pytest pytest-asyncio
54-
- name: Python build
55-
run: |
56-
${{ matrix.platform.python_exec }} -m maturin develop -E all
57-
- name: Python type check (mypy)
58-
run: |
59-
${{ matrix.platform.python_exec }} -m mypy python
60-
- name: Python tests
61-
run: |
62-
${{ matrix.platform.python_exec }} -m pytest --capture=no python/cocoindex/tests
44+
- uses: actions/cache@v4
45+
with:
46+
path: .venv
47+
key: pyenv-${{ matrix.platform.runner }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('pyproject.toml') }}
48+
restore-keys: |
49+
pyenv-${{ matrix.platform.runner }}-${{ steps.setup_python.outputs.python-version }}-
6350
64-
validate-3p-notices:
65-
runs-on: ubuntu-latest
66-
steps:
67-
- uses: actions/checkout@v4
68-
- name: Install Rust toolchain
69-
uses: dtolnay/rust-toolchain@stable
70-
- uses: taiki-e/install-action@v2
71-
with:
72-
tool: cargo-binstall
73-
- name: Install cargo-about
74-
run: cargo binstall -y cargo-about
75-
- name: Validate third-party notices (dry-run)
76-
shell: bash
77-
run: |
78-
set +e
79-
cargo about generate about.hbs > /dev/null
80-
status=$?
81-
if [ $status -ne 0 ]; then
82-
echo "::error::Third-party notices validation failed. Please update /about.toml and rerun."
83-
exit $status
84-
fi
51+
- name: Setup venv
52+
run: |
53+
python -m venv .venv
54+
- name: Install Python toolchains
55+
run: |
56+
${{ matrix.platform.python_exec }} -m pip install maturin mypy pytest pytest-asyncio
57+
- name: Python build
58+
run: |
59+
${{ matrix.platform.python_exec }} -m maturin develop -E all
60+
- name: Python type check (mypy)
61+
run: |
62+
${{ matrix.platform.python_exec }} -m mypy python
63+
- name: Python tests
64+
run: |
65+
${{ matrix.platform.python_exec }} -m pytest --capture=no python/cocoindex/tests
66+
67+
validate-3p-notices:
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v4
71+
- name: Install Rust toolchain
72+
uses: dtolnay/rust-toolchain@stable
73+
- uses: taiki-e/install-action@v2
74+
with:
75+
tool: cargo-binstall
76+
- name: Install cargo-about
77+
run: cargo binstall -y cargo-about
78+
- name: Validate third-party notices (dry-run)
79+
shell: bash
80+
run: |
81+
set +e
82+
cargo about generate about.hbs > /dev/null
83+
status=$?
84+
if [ $status -ne 0 ]; then
85+
echo "::error::Third-party notices validation failed. Please update /about.toml and rerun."
86+
exit $status
87+
fi

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ lto = true
1515
name = "cocoindex_engine"
1616
crate-type = ["cdylib"]
1717

18+
[features]
19+
default = ["legacy-states-v0"]
20+
legacy-states-v0 = []
21+
1822
[dependencies]
1923
pyo3 = { version = "0.25.1", features = [
2024
"abi3-py311",

src/builder/exec_ctx.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ fn build_import_op_exec_ctx(
5353
let existing_keys_schema: &[schema::ValueType] =
5454
if let Some(keys_schema) = &state.keys_schema {
5555
keys_schema
56-
} else if let Some(key_schema) = &state.key_schema {
57-
std::slice::from_ref(key_schema)
5856
} else {
57+
#[cfg(feature = "legacy-states-v0")]
58+
if let Some(key_schema) = &state.key_schema {
59+
std::slice::from_ref(key_schema)
60+
} else {
61+
&[]
62+
}
63+
#[cfg(not(feature = "legacy-states-v0"))]
5964
&[]
6065
};
6166
if existing_keys_schema == keys_schema_no_attrs.as_ref() {
@@ -81,6 +86,7 @@ fn build_import_op_exec_ctx(
8186

8287
// Keep this field for backward compatibility,
8388
// so users can still swap back to older version if needed.
89+
#[cfg(feature = "legacy-states-v0")]
8490
key_schema: Some(if keys_schema_no_attrs.len() == 1 {
8591
keys_schema_no_attrs[0].clone()
8692
} else {

src/setup/states.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ pub struct SourceSetupState {
152152
pub keys_schema: Option<Box<[schema::ValueType]>>,
153153

154154
/// DEPRECATED. For backward compatibility.
155+
#[cfg(feature = "legacy-states-v0")]
155156
#[serde(default, skip_serializing_if = "Option::is_none")]
156157
pub key_schema: Option<schema::ValueType>,
157158

0 commit comments

Comments
 (0)