Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,36 @@ jobs:
env:
UV_PYTHON: ${{matrix.python-version}}
run: just test-no-optional

bson2:
name: bson2
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
- name: Install Deps
run: |
python -m pip install rust-just uv
- name: Set up env
run: |
echo "LIBBSON_INSTALL_DIR=$PWD/libbson" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$PWD/libbson/lib" >> $GITHUB_ENV
echo "LIBBSON_VERSION=2.0.1" >> $GITHUB_ENV
- name: Install libbson
run: just build-libbson
- name: Ensure imports with no test deps
run: just import-check
- name: Start MongoDB
if: ${{ startsWith(runner.os, 'Linux') }}
uses: supercharge/mongodb-github-action@90004df786821b6308fb02299e5835d0dae05d0d # 1.12.0
with:
mongodb-version: 4.4
mongodb-replica-set: test-rs
- name: Run the tests
run: just test
docs:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions bindings/python/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ $ conda install --channel conda-forge libbson pkg-config
The minimum required version is listed in `pymongoarrow/version.py`. If
you try to build with a lower version a `ValueError` will be raised.

Our minimum supported major version is 1.x, and that is what we include in our wheels.
In order to build with `bson2`, you can `export LIBBSON_VERSION=2.<minor>.<patch>` before
running `just build-libbson` or building the library.

## Build

Typically we will use the provided `just` scripts and will not build
Expand Down
19 changes: 12 additions & 7 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# Whether to create libarrow symlinks on posix systems.
CREATE_LIBARROW_SYMLINKS = os.environ.get("MONGO_CREATE_LIBARROW_SYMLINKS", "1")

LIBBSON_VERSION = os.environ.get("LIBBSON_VERSION", "1.0.0")

# Set a default value for MACOSX_DEPLOYMENT_TARGET.
os.environ.setdefault("MACOSX_DEPLOYMENT_TARGET", "10.15")

Expand All @@ -40,19 +42,20 @@ def get_min_libbson_version():


def append_libbson_flags(module):
pc_path = "libbson-1.0"
BSON_MAJOR_VERSION = int(LIBBSON_VERSION[0])
pc_path = "libbson-1.0" if BSON_MAJOR_VERSION == 1 else "bson2"
install_dir = os.environ.get("LIBBSON_INSTALL_DIR")
if install_dir:
install_dir = os.path.abspath(install_dir)

# Handle the copy-able library file if applicable.
if COPY_LIBBSON:
if platform == "darwin":
lib_file = "libbson-1.0.0.dylib"
lib_file = "libbson-1.0.0.dylib" if BSON_MAJOR_VERSION == 1 else "bson2.dylib"
elif platform == "linux":
lib_file = "libbson-1.0.so.0"
lib_file = "libbson-1.0.so.0" if BSON_MAJOR_VERSION == 1 else "bson2.so.0"
else: # windows
lib_file = "bson-1.0.dll"
lib_file = "bson-1.0.dll" if BSON_MAJOR_VERSION == 1 else "bson2.dll"
lib_dir = "bin" if IS_WIN else "lib*"
lib_dir = glob.glob(os.path.join(install_dir, lib_dir))
if lib_dir:
Expand Down Expand Up @@ -81,16 +84,18 @@ def append_libbson_flags(module):
if IS_WIN:
# Note: we replace any forward slashes with backslashes so the path
# can be parsed by bash.
lib_path = os.path.join(lib_dir, "bson-1.0.lib").replace(os.sep, "/")
bson_lib = "bson-1.0.lib" if BSON_MAJOR_VERSION == 1 else "bson2.lib"
lib_path = os.path.join(lib_dir, bson_lib).replace(os.sep, "/")
if os.path.exists(lib_path):
module.extra_link_args = [lib_path]
include_dir = os.path.join(install_dir, "include", "libbson-1.0").replace(
include_path = "libbson-1.0" if BSON_MAJOR_VERSION == 1 else "bson2"
include_dir = os.path.join(install_dir, "include", include_path).replace(
os.sep, "/"
)
module.include_dirs.append(include_dir)
else:
raise ValueError(f"Could not find the compiled libbson in {install_dir}")
pc_path = os.path.join(install_dir, lib_dir, "pkgconfig", "libbson-1.0.pc")
pc_path = os.path.join(install_dir, lib_dir, "pkgconfig", f"{pc_path}.pc")

elif IS_WIN:
raise ValueError("We require a LIBBSON_INSTALL_DIR with a compiled library on Windows")
Expand Down
Loading