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

Add .pyi generation and specify numpy dependency for Python wrapper build #1933

Closed
wants to merge 7 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .github/workflows/python-wheels-publish-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ jobs:
CIBW_SKIP: "*-win32 *_i686"
CIBW_TEST_SKIP: "*-macosx_universal2:arm64"
CIBW_ENVIRONMENT: OPENEXR_RELEASE_CANDIDATE_TAG="${{ github.ref_name }}"
# Explicitly install required dependencies before building each Python version.
CIBW_BEFORE_BUILD: |
pip install -r <(python -c "import tomli; print('\n'.join(tomli.load(open('pyproject.toml', 'rb'))['build-system']['requires']))")

- name: Upload artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/python-wheels-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-* cp311-* cp312-*"
CIBW_SKIP: "*-win32 *_i686"
CIBW_TEST_SKIP: "*arm64"
# Explicitly install required dependencies before building each Python version.
CIBW_BEFORE_BUILD: |
pip install -r <(python -c "import tomli; print('\n'.join(tomli.load(open('pyproject.toml', 'rb'))['build-system']['requires']))")

- name: Upload artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/python-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ jobs:
CIBW_SKIP: "*-win32 *_i686"
CIBW_TEST_SKIP: "*-macosx*arm64"
OPENEXR_TEST_IMAGE_REPO: "https://raw.githubusercontent.com/AcademySoftwareFoundation/openexr-images/main"
# Explicitly install required dependencies before building each Python version.
CIBW_BEFORE_BUILD: |
pip install -r <(python -c "import tomli; print('\n'.join(tomli.load(open('pyproject.toml', 'rb'))['build-system']['requires']))")

- name: Upload artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ build-nuget/
*~
.vscode
docs/_test_images/
dist/*
__pycache__/
*.py[cod]
*$py.class

# Ignore Bazel generated files
bazel-*
Expand Down
6 changes: 5 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.10.7", "pybind11"]
requires = ["scikit-build-core==0.10.7", "pybind11", "pybind11-stubgen", "numpy"]
build-backend = "scikit_build_core.build"

[project]
Expand All @@ -16,6 +16,10 @@ authors = [
]
requires-python = ">=3.7"

dependencies = [
"numpy>=1.18"
]

[project.urls]
"Homepage" = "https://openexr.com"
"Source" = "https://github.com/AcademySoftwareFoundation/OpenEXR"
Expand Down
10 changes: 9 additions & 1 deletion src/wrappers/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ endif()
install(TARGETS PyOpenEXR DESTINATION ${PYTHON_INSTALL_DIR} COMPONENT python)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/Imath.py DESTINATION ${PYTHON_INSTALL_DIR} COMPONENT python)

# Generate .pyi stub file using pybind11-stubgen. And install the generated .pyi file
add_custom_command(TARGET PyOpenEXR POST_BUILD
COMMAND PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR} ${Python_EXECUTABLE} -m pybind11_stubgen -o ${CMAKE_BINARY_DIR}/OpenEXR --ignore-all-errors OpenEXR

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should take I to account that this cmake file can be use to build the python extension without all the python build system ecosystem.bthis mean that pybind11_stubgen could be missing and someone might also want to explicitly opt-out of it.

WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating .pyi stub file"
)
install(FILES ${CMAKE_BINARY_DIR}/OpenEXR/OpenEXR.pyi DESTINATION ${PYTHON_INSTALL_DIR} COMPONENT python)

if(BUILD_TESTING AND OPENEXR_TEST_PYTHON)

add_test(OpenEXR.PyOpenEXR pytest ${CMAKE_CURRENT_SOURCE_DIR}/tests)
Expand All @@ -40,4 +48,4 @@ if(BUILD_TESTING AND OPENEXR_TEST_PYTHON)
ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}"
)

endif()
endif()