Skip to content

Commit

Permalink
Fix python wheel builds
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Oct 27, 2022
1 parent bd328d4 commit 7652c39
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -578,16 +578,24 @@ if (NANOGUI_BUILD_PYTHON)
message(STATUS "NanoGUI: building the Python plugin.")
if (NOT TARGET nanobind::module)
if (SKBUILD)
# Constrain FindPython to find the Python version used by scikit-build
set(Python_VERSION "${PYTHON_VERSION_STRING}")
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
set(Python_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}")
set(Python_LIBRARIES "${PYTHON_LIBRARY}")

find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)

execute_process(
COMMAND
"${PYTHON_EXECUTABLE}" -c
"import nanobind; print(nanobind.get_cmake_dir())"
"${PYTHON_EXECUTABLE}" -c "import nanobind; print(nanobind.cmake_dir())"
OUTPUT_VARIABLE _tmp_dir
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")
list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")

find_package(nanobind CONFIG REQUIRED)
else()
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)

# Allow overriding the nanobind library used to compile NanoGUI
set(NANOGUI_NANOBIND_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanobind"
Expand Down
16 changes: 6 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
NanoGUI
========================================================================================
|docs| |travis| |appveyor|
|docs| |gha|

.. |docs| image:: https://readthedocs.org/projects/nanogui/badge/?version=latest
:target: http://nanogui.readthedocs.org/en/latest/?badge=latest
:alt: Docs

.. |travis| image:: https://travis-ci.org/wjakob/nanogui.svg?branch=master
:target: https://travis-ci.org/wjakob/nanogui
:alt: Travis Build Status

.. |appveyor| image:: https://ci.appveyor.com/api/projects/status/m8h3uyvdb4ej2i02/branch/master?svg=true
:target: https://ci.appveyor.com/project/wjakob/nanogui/branch/master
:alt: Appveyor Build Status
.. |gha| image:: https://github.com/mitsuba-renderer/nanogui/actions/workflows/build.yml/badge.svg
:target: https://github.com/mitsuba-renderer/nanogui/actions/workflows/build.yml
:alt: GitHub Actions Build Status

.. begin_brief_description
NanoGUI is a minimalistic cross-platform widget library for OpenGL 3+, GLES
2/3, and Metal. It supports automatic layout generation, stateful C++ lambdas
callbacks, a variety of useful widget types and Retina-capable rendering on
Apple devices thanks to NanoVG_ by Mikko Mononen. Python bindings of all
functionality are provided using pybind11_. Binary wheels of NanoGUI are
functionality are provided using nanobind_. Binary wheels of NanoGUI are
available on PyPI_.

**Note**: This repository contains an improved port of the original NanoGUI_.
Expand Down Expand Up @@ -57,7 +53,7 @@ the the repository here incorporates the following changes:
7. The Entypo_ icon font has been replaced by FontAwesome_ (v5.10.1).

.. _NanoVG: https://github.com/memononen/NanoVG
.. _pybind11: https://github.com/wjakob/pybind11
.. _nanobind: https://github.com/wjakob/nanobind
.. _PyPi: https://pypi.org/project/nanogui
.. _NanoGUI: https://github.com/wjakob/nanogui
.. _Tekari: https://rgl.epfl.ch/tekari?url=%2F%2Frgl.s3.eu-central-1.amazonaws.com%2Fmedia%2Fuploads%2Fwjakob%2F2018%2F08%2F27%2Firidescent-paper.txt&log=1
Expand Down
2 changes: 1 addition & 1 deletion nanogui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

_import('nanogui.nanogui_ext')

def get_cmake_dir():
def cmake_dir():
from os import path
file_dir = path.abspath(path.dirname(__file__))
cmake_path = path.join(file_dir, "share", "cmake", "nanogui")
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[build-system]
requires = ["setuptools", "wheel", "scikit-build @ git+https://github.com/scikit-build/scikit-build.git@master", "cmake", "ninja", "nanobind>=0.0.7"]
requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja", "nanobind>=0.0.8"]
build-backend = "setuptools.build_meta"
10 changes: 10 additions & 0 deletions src/python/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ int widget_tp_traverse_base(PyObject *self, visitproc visit, void *arg, PyTypeOb
strcmp(name + name_len - suffix_len, suffix) != 0)
continue;


#if PY_VERSION_HEX < 0x03090000
PyObject *func = PyObject_GetAttr(self, key),
*result = nullptr;
if (func) {
result = PyObject_CallNoArgs(func);
Py_DECREF(func);
}
#else
PyObject *args[] = { self };
PyObject *result = PyObject_VectorcallMethod(
key, args, 1 | PY_VECTORCALL_ARGUMENTS_OFFSET, nullptr);
#endif

if (!result) {
PyErr_Clear();
Expand Down

0 comments on commit 7652c39

Please sign in to comment.