Skip to content

Commit

Permalink
Fix nanobind dependence. Re-introduce stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
rtabbara committed Oct 1, 2024
1 parent ea73845 commit 688d4f5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
env:
CIBW_TEST_COMMAND: "python -c \"import mitsuba\""
CIBW_TEST_REQUIRES: ""
CIBW_REPAIR_WHEEL_COMMAND_LINUX: "python .github/workflows/tag_wheel_manylinux.py {wheel} {dest_dir}"
CIBW_REPAIR_WHEEL_COMMAND_MACOS: "delocate-wheel --require-archs {delocate_archs} -w {dest_dir} --ignore-missing-dependencies {wheel}"


jobs:
build_wheels:
Expand Down Expand Up @@ -45,6 +48,11 @@ jobs:
with:
python-version: '3.10'

- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v2
with:
version: "11.0"

- name: Prepare compiler environment for Windows
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
Expand Down
2 changes: 1 addition & 1 deletion ext/drjit
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[build-system]
requires = [
"scikit-build-core",
"nanobind @ git+https://github.com/wjakob/nanobind@master",
"nanobind @ git+https://github.com/wjakob/nanobind@8ce0dee7f62add575f85c0de386a9c819e4d50af",
"drjit @ git+https://github.com/njroussel/drjit-fork@rami",
"typing_extensions",
"hatch-fancy-pypi-readme"
Expand Down
61 changes: 61 additions & 0 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,67 @@ endif()
# Generate type information stubs (mitsuba)
# ----------------------------------------------------------

set(STUB_ARGS
PYTHON_PATH ${MI_BINARY_DIR}/python
PATTERN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/stubs.pat
DEPENDS ${MI_STUB_DEPENDS}
)

# The sanitizers require preloading shared libraries into Python, and that
# doesn't play well with stub generation. Disable stubs if sanitizers are
# enabled.
if (NOT (MI_SANITIZE_ADDRESS OR MI_SANITIZE_MEMORY))

set(MI_STUB_SUBMODULES "math" "quad" "spline" "mueller" "warp" "misc"
"python.ad" "python.chi2" "python.math_py" "python.util" "python.xml")

nanobind_add_stub(
mitsuba-stub
MODULE mitsuba.mitsuba_stubs
OUTPUT ${MI_BINARY_DIR}/python/mitsuba/stubs.pyi
MARKER_FILE ${MI_BINARY_DIR}/python/mitsuba/py.typed
${STUB_ARGS}
)

add_custom_command(
OUTPUT ${MI_BINARY_DIR}/python/mitsuba/__init__.pyi
DEPENDS ${MI_BINARY_DIR}/python/mitsuba/stubs.pyi
COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/../../resources/variant-stub.cmake
${MI_BINARY_DIR}/python/mitsuba/stubs.pyi
${MI_BINARY_DIR}/python/mitsuba/__init__.pyi
)

set(MI_STUB_TARGET_DEPS
${MI_BINARY_DIR}/python/mitsuba/__init__.pyi
${MI_BINARY_DIR}/python/mitsuba/py.typed)

foreach (value ${MI_STUB_SUBMODULES})
string(REPLACE "." "/" value_path ${value})
nanobind_add_stub(
mitsuba-stub-${value}
MODULE mitsuba.mitsuba_stubs.${value}
OUTPUT ${MI_BINARY_DIR}/python/mitsuba/${value_path}_stubs.pyi
${STUB_ARGS}
)

add_custom_command(
OUTPUT ${MI_BINARY_DIR}/python/mitsuba/${value_path}.pyi
DEPENDS ${MI_BINARY_DIR}/python/mitsuba/${value_path}_stubs.pyi
COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/../../resources/variant-stub.cmake
${MI_BINARY_DIR}/python/mitsuba/${value_path}_stubs.pyi
${MI_BINARY_DIR}/python/mitsuba/${value_path}.pyi
)

list(APPEND MI_STUB_TARGET_DEPS ${MI_BINARY_DIR}/python/mitsuba/${value_path}.pyi)
endforeach()

add_custom_target(
mitsuba-stubs
ALL
DEPENDS ${MI_STUB_TARGET_DEPS}
)

endif()


# ----------------------------------------------------------
Expand Down

0 comments on commit 688d4f5

Please sign in to comment.