Skip to content

Build _bjdata against NumPy 2.x (drop oldest-supported-numpy); ship wheels #7

Description

@oberstet

Problem

bjdata 0.6.6 ships an sdist only (no binary wheels on PyPI), so the
_bjdata C extension is compiled from source on every install. Its build pins:

# pyproject.toml
[build-system]
requires = ["setuptools>=40", "wheel", "oldest-supported-numpy"]
build-backend = "setuptools.build_meta"

oldest-supported-numpy is deprecated and forces building against
NumPy 1.x. NumPy 2.0 changed the C-ABI: an extension compiled against
NumPy 1.x, when imported under NumPy 2.x, makes NumPy print a multi-line
diagnostic to stderr and disables the extension's NumPy integration:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.4.x as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
...
  from _bjdata import dump, dumpb, load, loadb
AttributeError: _ARRAY_API not found

import bjdata still succeeds and the plain (non-NumPy) UBJSON encode/decode
paths work; only bjdata's NumPy-NDArray (de)serialization is broken. But the
stderr diagnostic is alarming and pollutes the output of any application that
imports bjdata under NumPy 2.x (which is now the default NumPy).

Reproduction

python -m venv /tmp/v && /tmp/v/bin/pip install -U pip "numpy>=2" bjdata==0.6.6
/tmp/v/bin/python -c "import bjdata"   # prints the NumPy 1.x/2.x notice to stderr

Suggested fix

  1. Build against NumPy 2.x: replace oldest-supported-numpy with
    numpy>=2.0 in [build-system].requires. A C extension built against
    NumPy 2.0 is compatible with both NumPy 1.x and 2.x at runtime, which is
    the documented migration path
    (https://numpy.org/devdocs/dev/depending_on_numpy.html#numpy-2-abi-handling).
  2. Publish binary wheels (manylinux / macOS / Windows, per supported
    CPython) so users don't recompile from sdist on every install (and so the
    correct NumPy-2-built binary is what they get).
  3. (Optional) If the NumPy dependency is only needed for the optional NDArray
    feature, consider making numpy an optional/extra dependency so pure-UBJSON
    users don't pull NumPy at all.

Context

This surfaced via the WAMP/Autobahn ecosystem: autobahn 26.6.x uses bjdata
as the backend for its optional "ubjson" WAMP serializer (replacing the
unmaintained py-ubjson), and downstream crossbar users see the notice on
startup under NumPy 2.x.

(Note: distinct from #6.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions