Feature flagsmock, and checking for it

mock is a Cargo feature on the medius-capi crate. On import, Python sets medius.HAS_MOCK from what the loaded library exposes.

FeatureCargo flagPython surfacemedius.HAS_MOCKAdds
mock--features mockMockBox().open() / .with_device()HAS_MOCKA scriptable in-process fake box. See Mock box.

The pip install medius wheel is built without mock, and MockBox() raises RuntimeError there. Gate on if medius.HAS_MOCK: first.

FEATURE CHECK
python -c "import medius; print('mock', medius.HAS_MOCK)"
# mock False   <- the published wheel
ENABLE A FEATURE

Build the library with the feature, then point Python at it with MEDIUS_LIB (below). No reinstall.

# from the repo root
cargo build --release -p medius-capi --features mock

export MEDIUS_LIB=$PWD/target/release/libmedius_capi.so
python -c "import medius; print(medius.HAS_MOCK)"
# True

To include mock in an installed wheel, build the library first; pip reuses that build:

cargo build --release -p medius-capi --features mock
MEDIUS_SKIP_CARGO=1 pip install ./bindings/python

Finding the libraryMEDIUS_LIB and the load order

import medius loads the library from the first of these that exists; MEDIUS_LIB overrides the rest.

import medius
   │
   ├─ 1. $MEDIUS_LIB set?                   ──▶  CDLL(that exact path)   (dev / test builds)
   ├─ 2. bundled beside the package?        ──▶  CDLL(medius/<libname>)  (what the wheel ships)
   ├─ 3. on the system loader path?         ──▶  CDLL(<libname>)         (LD_LIBRARY_PATH / PATH)
   ├─ 4. ctypes.util.find_library(...)?     ──▶  CDLL(found)             (ldconfig / system paths)
   └─ none                                  ──▶  OSError                 (cannot locate the library)
MEDIUS_LIB
MEDIUS_LIB=/path/to/target/release/libmedius_capi.so python myscript.py

An OSError on import means every step failed: a bad MEDIUS_LIB path, or an unsupported platform where the install built from source without a Rust toolchain.

An ImportError naming two ABI numbers means the library it found comes from another release: the package checks medius_abi_version() before any call.

PackagingPrebuilt wheels, and building from source

Linux (glibc), macOS, and 64-bit Windows get a prebuilt wheel from pip install medius. On musl Linux (Alpine) or 32-bit Windows, pip builds the library from source.

# build from source even where a wheel exists
pip install medius --no-binary medius

# from a checkout
pip install ./bindings/python

A source build runs cargo build --release -p medius-capi, so it needs a Rust toolchain on PATH. On Linux the library links libudev through serialport; install systemd-devel (or your distro's libudev-dev) first.