Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite OpenEXR python bindings using pybind11 and numpy #1756

Merged
merged 13 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 3 additions & 0 deletions .github/workflows/python-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ on:
branches-ignore:
- RB-*
paths:
- 'src/lib/**'
- 'src/wrappers/python/**'
- 'pyproject.toml'
- '.github/workflows/python-wheels.yml'
pull_request:
branches-ignore:
- RB-*
paths:
- 'src/lib/**'
- 'src/wrappers/python/**'
- 'pyproject.toml'
- '.github/workflows/python-wheels.yml'
Expand Down Expand Up @@ -63,6 +65,7 @@ jobs:
# Also skip the PyPy builds, since they fail the unit tests
CIBW_SKIP: cp36-* *-win32 *_i686 pp*
CIBW_TEST_SKIP: "*-macosx*arm64"
OPENEXR_TEST_IMAGE_REPO: "https://github.com/raw/AcademySoftwareFoundation/openexr-images/main"

- name: Upload artifact
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) Contributors to the OpenEXR Project.

[build-system]
requires = ["scikit-build-core==0.8.1"]
requires = ["scikit-build-core==0.8.1", "pybind11"]
build-backend = "scikit_build_core.build"

[project]
Expand Down Expand Up @@ -67,6 +67,7 @@ CMAKE_POSITION_INDEPENDENT_CODE = 'ON'

[tool.cibuildwheel]
test-command = "pytest -s {project}/src/wrappers/python/tests"
test-requires = ["numpy"]
test-extras = ["test"]
test-skip = ["*universal2:arm64"]
build-verbosity = 1
Expand Down
37 changes: 37 additions & 0 deletions share/ci/scripts/install_pybind11.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenColorIO Project.

set -ex

PYBIND11_VERSION="$1"

if [[ $OSTYPE == "msys" ]]; then
SUDO=""
else
SUDO="sudo"
fi

git clone https://github.com/pybind/pybind11.git
cd pybind11

if [ "$PYBIND11_VERSION" == "latest" ]; then
LATEST_TAG=$(git describe --abbrev=0 --tags)
git checkout tags/${LATEST_TAG} -b ${LATEST_TAG}
else
git checkout tags/v${PYBIND11_VERSION} -b v${PYBIND11_VERSION}
fi

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release \
-DPYBIND11_INSTALL=ON \
-DPYBIND11_TEST=OFF \
../.
$SUDO cmake --build . \
--target install \
--config Release \
--parallel 2

cd ../..
rm -rf pybind11
12 changes: 12 additions & 0 deletions src/lib/OpenEXR/ImfKeyCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ KeyCode::operator= (const KeyCode& other)
return *this;
}

bool
KeyCode::operator== (const KeyCode& other) const
{
return (_filmMfcCode == other._filmMfcCode &&
_filmType == other._filmType &&
_prefix == other._prefix &&
_count == other._count &&
_perfOffset == other._perfOffset &&
_perfsPerFrame == other._perfsPerFrame &&
_perfsPerCount == other._perfsPerCount);
}

int
KeyCode::filmMfcCode () const
{
Expand Down
2 changes: 2 additions & 0 deletions src/lib/OpenEXR/ImfKeyCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class IMF_EXPORT_TYPE KeyCode
IMF_EXPORT
KeyCode& operator= (const KeyCode& other);

bool operator== (const KeyCode& other) const;

//----------------------------
// Access to individual fields
//----------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/lib/OpenEXR/ImfPreviewImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ struct IMF_EXPORT_TYPE PreviewRgba
unsigned char a = 255)
: r (r), g (g), b (b), a (a)
{}

bool operator==(const PreviewRgba& other) const
{
return r == other.r && g == other.g && b == other.b && a == other.a;
}
};

class IMF_EXPORT_TYPE PreviewImage
Expand Down
5 changes: 3 additions & 2 deletions src/wrappers/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ if(NOT "${CMAKE_PROJECT_NAME}" STREQUAL "OpenEXR")
endif()

find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
find_package(pybind11 CONFIG REQUIRED)

python_add_library (PyOpenEXR MODULE OpenEXR.cpp)
python_add_library (PyOpenEXR MODULE PyOpenEXR.cpp PyOpenEXR_old.cpp)

target_link_libraries (PyOpenEXR PRIVATE "${Python_LIBRARIES}" OpenEXR::OpenEXR)
target_link_libraries (PyOpenEXR PRIVATE "${Python_LIBRARIES}" OpenEXR::OpenEXR pybind11::headers)

# The python module should be called "OpenEXR.so", not "PyOpenEXR.so",
# but "OpenEXR" is taken as a library name by the main lib, so specify
Expand Down
Loading
Loading