Skip to content

Commit

Permalink
Fix Python wrappers for function callbacks (#1202)
Browse files Browse the repository at this point in the history
Need to include pybind11/functional.h for function callbacks (std::function refs) to be passable. Otherwise the types are considered to be incompatible between a Python function and C++ function pointer.
  • Loading branch information
kwokcb authored Feb 15, 2023
1 parent e306ebc commit 3704831
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion python/MaterialXTest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,18 @@ def test_TraverseGraph(self):
self.assertFalse(output.hasUpstreamCycle())
self.assertTrue(doc.validate()[0])

def test_ReadXml(self):
def test_Xmlio(self):
# Read the standard library.
libs = []
for filename in _libraryFilenames:
lib = mx.createDocument()
mx.readFromXmlFile(lib, filename, _searchPath)
libs.append(lib)

# Declare write predicate for write filter test
def skipLibraryElement(elem):
return not elem.hasSourceUri()

# Read and validate each example document.
for filename in _exampleFilenames:
doc = mx.createDocument()
Expand Down Expand Up @@ -473,6 +477,14 @@ def test_ReadXml(self):
doc2.importLibrary(lib)
self.assertTrue(doc2.validate()[0])

# Write without definitions
writeOptions.writeXIncludeEnable = False
writeOptions.elementPredicate = skipLibraryElement
result = mx.writeToXmlString(doc2, writeOptions)
doc3 = mx.createDocument()
mx.readFromXmlString(doc3, result)
self.assertTrue(len(doc3.getNodeDefs()) == 0)

# Read the same document twice, and verify that duplicate elements
# are skipped.
doc = mx.createDocument()
Expand Down
1 change: 1 addition & 0 deletions source/PyMaterialX/PyMaterialX.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// include within any PyMaterialX source file.
//

#include <pybind11/functional.h>
#include <pybind11/operators.h>
#include <pybind11/stl.h>

Expand Down

0 comments on commit 3704831

Please sign in to comment.