Skip to content
Open
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: 2 additions & 1 deletion .github/workflows/wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ jobs:
- name: Build wheels
uses: pypa/cibuildwheel@v3.4.1
env:
CIBW_BUILD: "cp310-*"
CIBW_BUILD_FRONTEND: "build[uv]"
CIBW_ARCHS_LINUX: auto64
CIBW_ARCHS_WINDOWS: auto64
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
CIBW_SKIP: "*-musllinux* pp*"
CIBW_SKIP: "*-musllinux*"
CIBW_TEST_COMMAND: "pytest -s --pdb {project}/modules"
CIBW_TEST_REQUIRES: pytest
MACOSX_DEPLOYMENT_TARGET: 13.00
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else()
endif()

# Check required CMake version
cmake_minimum_required(VERSION 3.25.0)
cmake_minimum_required(VERSION 3.26.0)

cmake_policy(SET CMP0054 NEW) # Only interpret if() arguments as variables or keywords when unquoted.
cmake_policy(SET CMP0076 NEW) # target_sources() command converts relative paths to absolute.
Expand Down
2 changes: 1 addition & 1 deletion cmake/recipes/external/nanobind.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include(CPM)
CPMAddPackage(
NAME nanobind
GITHUB_REPOSITORY wjakob/nanobind
GIT_TAG v2.13.0
GIT_TAG v3.0.0-dev3
DOWNLOAD_ONLY ON
)

Expand Down
8 changes: 6 additions & 2 deletions cmake/recipes/external/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#
if(TARGET Python::Module)
if(TARGET Python::Module AND TARGET Python::SABIModule)
return()
endif()

set(Python_FIND_VIRTUALENV FIRST)
find_package(Python 3.9 COMPONENTS Interpreter Development.Module REQUIRED)
find_package(
Python 3.10
COMPONENTS Interpreter Development.Module Development.SABIModule
REQUIRED
)
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct type_caster<lagrange::python::StubType<T, Hint>>

NB_TYPE_CASTER(Wrapper, const_name(Hint::value))

bool from_python(handle src, uint8_t flags, cleanup_list* cleanup) noexcept
bool from_python(handle src, uint32_t flags, cleanup_list* cleanup) noexcept
{
TCaster caster;
if (!caster.from_python(src, flags, cleanup)) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

NAMESPACE_BEGIN(NB_NAMESPACE)

template <typename Vector, rv_policy Policy = rv_policy::automatic_reference, typename... Args>
template <
typename Vector,
rv_policy::value Policy = rv_policy::automatic_reference_v,
typename... Args>
class_<Vector> bind_safe_vector(handle scope, const char* name, Args&&... args)
{
using ValueRef = typename detail::iterator_access<typename Vector::iterator>::result_type;
Expand All @@ -43,7 +46,7 @@ class_<Vector> bind_safe_vector(handle scope, const char* name, Args&&... args)
static_assert(
!detail::is_base_caster_v<detail::make_caster<Value>> ||
detail::is_copy_constructible_v<Value> ||
(Policy != rv_policy::automatic_reference && Policy != rv_policy::copy),
(Policy != rv_policy::automatic_reference_v && Policy != rv_policy::copy_v),
"bind_safe_vector(): the generated __getitem__ would copy elements, so the "
"element type must be copy-constructible");

Expand Down Expand Up @@ -83,7 +86,7 @@ class_<Vector> bind_safe_vector(handle scope, const char* name, Args&&... args)
[](Vector& v, Py_ssize_t i) -> ValueRef {
return v.Vector::Super::operator[](detail::wrap(i, v.size()));
},
Policy)
rv_policy::policy_tag<Policy>{})

.def("clear", [](Vector& v) { v.clear(); }, "Remove all items from list.");

Expand Down
4 changes: 2 additions & 2 deletions modules/core/python/src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PythonLoggingSink : public spdlog::sinks::base_sink<std::mutex>
void sink_it_(const spdlog::details::log_msg& msg) override
{
// Logging in python requires the current thread to hold the GIL.
if (!PyGILState_Check()) return;
if (!NB_CALL(gil_check)()) return;

auto payload = msg.payload;
auto res = nb::str(payload.data(), payload.size());
Expand All @@ -62,7 +62,7 @@ class PythonLoggingSink : public spdlog::sinks::base_sink<std::mutex>
void flush_() override
{
// Logging in python requires the current thread to hold the GIL.
if (!PyGILState_Check()) return;
if (!NB_CALL(gil_check)()) return;

auto handlers = m_py_logger.attr("handlers");
for (auto handler : handlers) {
Expand Down
3 changes: 1 addition & 2 deletions modules/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ endif()
# 1. define module
include(nanobind)
lagrange_find_package(TBB CONFIG REQUIRED)
nanobind_add_module(lagrange_python NB_STATIC)
set_target_properties(nanobind-static PROPERTIES FOLDER third_party)
nanobind_add_module(lagrange_python BACKEND_MODULE nanobind_backend)
add_library(lagrange::python ALIAS lagrange_python)
set_target_properties(lagrange_python PROPERTIES
FOLDER "${LAGRANGE_IDE_PREFIX}Lagrange/Modules"
Expand Down
6 changes: 3 additions & 3 deletions modules/scene/python/src/bind_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct type_caster<lagrange::scene::Value>
NB_TYPE_CASTER(lagrange::scene::Value, const_name("int | float | str | list | dict | bool"));

template <typename T>
bool try_cast(const handle& src, uint8_t flags, cleanup_list* cleanup)
bool try_cast(const handle& src, uint32_t flags, cleanup_list* cleanup)
{
using CasterT = make_caster<T>;

Expand All @@ -34,7 +34,7 @@ struct type_caster<lagrange::scene::Value>
return true;
}

bool from_python(handle src, uint8_t flags, cleanup_list* cleanup) noexcept
bool from_python(handle src, uint32_t flags, cleanup_list* cleanup) noexcept
{
if (PyNumber_Check(src.ptr())) {
lagrange::logger().debug("Number!");
Expand All @@ -48,7 +48,7 @@ struct type_caster<lagrange::scene::Value>
size_t n;
PyObject* temp;
/* Will initialize 'temp' (NULL in the case of a failure.) */
PyObject** o = seq_get(src.ptr(), &n, &temp);
PyObject** o = NB_CALL(seq_get)(src.ptr(), &n, &temp);

bool success = o != nullptr;

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[build-system]
build-backend = "scikit_build_core.build"
requires = [
"nanobind-backend==1.0.0.dev3", # must match the nanobind development release
"numpy>=1.25", # needed at build time for default dtype args
"scikit-build-core==0.11.6",
"typing-extensions~=4.1",
Expand Down Expand Up @@ -30,6 +31,7 @@ dynamic = [ "version" ]
dependencies = [
"colorama>=0.4.4; platform_system!='Windows'",
"colorama>=0.4.6; platform_system=='Windows'",
"nanobind-backend==1.0.0.dev3",
"numpy>=1.25",
"scipy>=1.13.0",
]
Expand Down Expand Up @@ -70,6 +72,7 @@ ninja.version = ">=1.11.1"
ninja.make-fallback = false
install.components = [ "Lagrange_Python_Runtime" ]
wheel.packages = [ "modules/python/lagrange" ]
wheel.py-api = "cp310"
build-dir = "build-python"
editable.rebuild = false
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
Expand Down
Loading