Skip to content

Commit 109b17e

Browse files
committed
EMSUSD-2810 - Integrate USD v25.08 into ecg-maya-usd builds
* Fix crash with python object lifetime. * Remove old python2 'pkg_resources.declare_namespace' and replace with 'pkgutil.extend_path'. * Replace renamed python function assertRegexpMatches with assertRegex.
1 parent 0cbdacf commit 109b17e

10 files changed

Lines changed: 26 additions & 29 deletions

File tree

plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/wrapTranslatorBase.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,26 @@ class TranslatorBaseWrapper
104104
std::size_t generateUniqueKey(const UsdPrim& prim) const override
105105
{
106106
if (Override o = GetOverride("generateUniqueKey")) {
107+
// Acquire Python lock before making any Python calls
108+
TfPyLock pyLock;
109+
110+
// Call the Python function with proper exception handling
107111
auto res = std::function<PXR_BOOST_PYTHON_NAMESPACE::object(const UsdPrim&)>(
108112
TfPyCall<PXR_BOOST_PYTHON_NAMESPACE::object>(o))(prim);
109-
if (!res) {
113+
114+
// Check if the result is valid (not None or null)
115+
if (!res || res.is_none()) {
110116
return 0;
111117
}
112-
TfPyLock pyLock;
118+
113119
PXR_BOOST_PYTHON_NAMESPACE::str strObj(res);
114120
PXR_BOOST_PYTHON_NAMESPACE::extract<std::string> strValue(strObj);
115121
if (strValue.check()) {
116-
return std::hash<std::string> {}(strValue);
122+
std::string keyStr = strValue();
123+
// Ensure we don't hash empty strings
124+
if (!keyStr.empty()) {
125+
return std::hash<std::string> {}(keyStr);
126+
}
117127
}
118128
}
119129
return 0;
@@ -155,6 +165,7 @@ class TranslatorBaseWrapper
155165
// "import" is a python keyword so python's override will be called
156166
// "importObject" instead
157167
if (Override o = GetOverride("importObject")) {
168+
TfPyLock pyLock;
158169
MDagPath path;
159170
MDagPath::getAPathTo(parent, path);
160171

@@ -170,7 +181,8 @@ class TranslatorBaseWrapper
170181
MStatus postImport(const UsdPrim& prim) override
171182
{
172183
if (Override o = GetOverride("postImport")) {
173-
auto res = std::function<bool(const UsdPrim&)>(TfPyCall<bool>(o))(prim);
184+
TfPyLock pyLock;
185+
auto res = std::function<bool(const UsdPrim&)>(TfPyCall<bool>(o))(prim);
174186
return res ? MS::kSuccess : MS::kFailure;
175187
}
176188
return MS::kSuccess;
@@ -233,6 +245,7 @@ class TranslatorBaseWrapper
233245
std::string name(dagPath.fullPathName().asChar());
234246
// pass a dagPath name and dictionary of params to the python method
235247
if (Override o = GetOverride("exportObject")) {
248+
TfPyLock pyLock;
236249
return std::function<UsdPrim(
237250
UsdStageRefPtr, const char*, SdfPath, PXR_BOOST_PYTHON_NAMESPACE::dict)>(
238251
TfPyCall<UsdPrim>(o))(stage, name.c_str(), usdPath, pyParams);

plugin/al/lib/AL_USDMaya/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ install(FILES
289289
)
290290
install(CODE
291291
"file(WRITE \"${CMAKE_CURRENT_BINARY_DIR}/lib/python/AL/__init__.py\"
292-
\"try:\n\t__import__('pkg_resources').declare_namespace(__name__)\nexcept:\n\tfrom pkgutil import extend_path\n\t__path__ = extend_path(__path__, __name__)\")"
292+
\"from pkgutil import extend_path\n__path__ = extend_path(__path__, __name__)\n\")"
293293
)
294294
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib/python/AL/__init__.py
295295
DESTINATION ${AL_INSTALL_PREFIX}/lib/python/AL

plugin/al/schemas/AL/usd/schemas/maya/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ if(${listCount} STRGREATER 1)
174174
string(REPLACE ";" "/" currentPath "${currentPath}")
175175
file(WRITE
176176
${CMAKE_BINARY_DIR}/${currentPath}/__init__.py
177-
"try:\n\t__import__('pkg_resources').declare_namespace(__name__)\nexcept:\n\tfrom pkgutil import extend_path\n\t__path__ = extend_path(__path__, __name__)\n"
177+
"from pkgutil import extend_path\n__path__ = extend_path(__path__, __name__)\n"
178178
)
179179
endforeach(i)
180180
endif()

plugin/al/schemas/AL/usd/schemas/mayatest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ if(${listCount} STRGREATER 1)
159159
string(REPLACE ";" "/" currentPath "${currentPath}")
160160
file(WRITE
161161
${CMAKE_BINARY_DIR}/${currentPath}/__init__.py
162-
"try:\n\t__import__('pkg_resources').declare_namespace(__name__)\nexcept:\n\tfrom pkgutil import extend_path\n\t__path__ = extend_path(__path__, __name__)\n"
162+
"from pkgutil import extend_path\n__path__ = extend_path(__path__, __name__)\n"
163163
)
164164
endforeach(i)
165165
endif()
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
try:
2-
__import__('pkg_resources').declare_namespace(__name__)
3-
except:
4-
pass
1+
from pkgutil import extend_path
2+
__path__ = extend_path(__path__, __name__)
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
try:
2-
__import__('pkg_resources').declare_namespace(__name__)
3-
except:
4-
pass
1+
from pkgutil import extend_path
2+
__path__ = extend_path(__path__, __name__)

plugin/pxr/cmake/macros/Public.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function(pxr_setup_python)
171171
# see UsdMaya module inside pxr subdirectory
172172
_get_install_dir(lib/python/pxr installPrefix)
173173
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/__init__.py"
174-
"try:\n __import__('pkg_resources').declare_namespace(__name__)\nexcept:\n from pkgutil import extend_path\n __path__ = extend_path(__path__, __name__)\n")
174+
"from pkgutil import extend_path\n__path__ = extend_path(__path__, __name__)\n")
175175
execute_process(COMMAND ${Python_EXECUTABLE} -m compileall ${CMAKE_CURRENT_BINARY_DIR}/__init__.py)
176176
install(
177177
FILES

test/lib/mayaUsd/fileio/testCacheToUsd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def runTestCacheToUsd(self, createMayaRefPrimFn, checkCacheParentFn):
313313
if relativePath:
314314
if self.stage.GetRootLayer().anonymous:
315315
self.assertNotIn('payload = @testCacheToUsd.usda', self.stage.GetRootLayer().ExportToString())
316-
self.assertRegexpMatches(self.stage.GetRootLayer().ExportToString(), 'payload = @.*testCacheToUsd.usda')
316+
self.assertRegex(self.stage.GetRootLayer().ExportToString(), 'payload = @.*testCacheToUsd.usda')
317317
self.makeRootLayerNotAnonymous()
318318
mayaUsd.lib.Util.updatePostponedRelativePaths(self.stage.GetRootLayer())
319319

test/lib/mayaUsd/utils/testDiagnosticDelegate.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ class testDiagnosticDelegate(unittest.TestCase):
3535
def setUpClass(cls):
3636
fixturesUtils.setUpClass(__file__)
3737

38-
# Deprecated since version 3.2: assertRegexpMatches and assertRaisesRegexp
39-
# have been renamed to assertRegex() and assertRaisesRegex()
40-
if sys.version_info.major < 3 or sys.version_info.minor < 2:
41-
cls.assertRegex = cls.assertRegexpMatches
42-
cls.assertRaisesRegex = cls.assertRaisesRegexp
43-
4438
@classmethod
4539
def tearDownClass(cls):
4640
standalone.uninitialize()

test/lib/usd/translators/testUsdExportStripNamespaces.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ class testUsdExportStripNamespaces(unittest.TestCase):
3535
def setUpClass(cls):
3636
fixturesUtils.setUpClass(__file__)
3737

38-
# Deprecated since version 3.2: assertRegexpMatches and assertRaisesRegexp
39-
# have been renamed to assertRegex() and assertRaisesRegex()
40-
if sys.version_info.major < 3 or sys.version_info.minor < 2:
41-
cls.assertRegex = cls.assertRegexpMatches
42-
cls.assertRaisesRegex = cls.assertRaisesRegexp
43-
4438
@classmethod
4539
def tearDownClass(cls):
4640
standalone.uninitialize()

0 commit comments

Comments
 (0)