diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 303f1bc..5e2f0b1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,10 +40,15 @@ jobs: run: pip install pytest pydantic numpy - name: Run Python tests - run: pytest tests/ -v --tb=short + run: | + # Clear PYTHONPATH to ensure we test the installed wheel, not the local source + export PYTHONPATH= + pytest tests/ -v --tb=short - name: Run benchmarks (smoke test) - run: python benchmarks/test_10k.py + run: | + export PYTHONPATH= + python benchmarks/test_10k.py test-typescript: name: TypeScript Tests diff --git a/pyproject.toml b/pyproject.toml index 398679b..534b367 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,4 +76,4 @@ known-first-party = ["b_fast"] [tool.maturin] python-source = "python" -module-name = "b_fast.b_fast" +module-name = "b_fast._b_fast" diff --git a/python/b_fast/__init__.py b/python/b_fast/__init__.py index db323c6..a61c2bc 100644 --- a/python/b_fast/__init__.py +++ b/python/b_fast/__init__.py @@ -4,7 +4,7 @@ Ultra-fast binary serialization library with Rust backend. """ -from .b_fast import BFast +from ._b_fast import BFast from .integration import BFastResponse __version__ = "1.2.0" diff --git a/python/b_fast/_b_fast.abi3.so b/python/b_fast/_b_fast.abi3.so new file mode 100755 index 0000000..91b8a1b Binary files /dev/null and b/python/b_fast/_b_fast.abi3.so differ diff --git a/python/b_fast/b_fast.abi3.so b/python/b_fast/b_fast.abi3.so new file mode 100755 index 0000000..998977d Binary files /dev/null and b/python/b_fast/b_fast.abi3.so differ diff --git a/python/b_fast/integration.py b/python/b_fast/integration.py index 567a4ab..5d19cfb 100644 --- a/python/b_fast/integration.py +++ b/python/b_fast/integration.py @@ -1,16 +1,28 @@ from typing import Any -from fastapi import Response - -import b_fast +try: + from fastapi import Response + FASTAPI_AVAILABLE = True +except ImportError: + # Fallback class to prevent crash on import + class Response: + def __init__(self, *args, **kwargs): + pass + FASTAPI_AVAILABLE = False class BFastResponse(Response): media_type = "application/x-bfast" def __init__(self, content: Any, **kwargs): + if not FASTAPI_AVAILABLE: + raise ImportError("FastAPI is required to use BFastResponse. Install it with 'pip install fastapi'.") + + # Delayed import to avoid circular dependency + from ._b_fast import BFast + super().__init__(content=content, **kwargs) - self.encoder = b_fast.BFast() + self.encoder = BFast() def render(self, content: Any) -> bytes: return self.encoder.encode_packed(content, compress=True) diff --git a/src/lib.rs b/src/lib.rs index 364448c..53d35ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,6 @@ const TAG_UUID: u8 = 0xD4; const TAG_DECIMAL: u8 = 0xD5; #[allow(non_local_definitions)] -#[repr(align(64))] #[pyclass] pub struct BFast { string_table: AHashMap, @@ -796,7 +795,7 @@ impl BFast { } #[pymodule] -fn b_fast(_py: Python, m: &PyModule) -> PyResult<()> { +fn _b_fast(_py: Python, m: &PyModule) -> PyResult<()> { m.add_class::()?; m.add( "BFastError",