1 /* SPDX-FileCopyrightText: 2020 Blender Authors
3 * SPDX-License-Identifier: GPL-2.0-or-later */
6 * \ingroup pythonintern
9 #include "BLI_utildefines.h"
12 #include "bpy_app_usd.hh"
14 #include "../generic/py_capi_utils.hh"
20 static PyTypeObject BlenderAppUSDType
;
22 static PyStructSequence_Field app_usd_info_fields
[] = {
23 {"supported", "Boolean, True when Blender is built with USD support"},
24 {"version", "The USD version as a tuple of 3 numbers"},
25 {"version_string", "The USD version formatted as a string"},
29 static PyStructSequence_Desc app_usd_info_desc
= {
30 /*name*/ "bpy.app.usd",
32 "This module contains information about the Universal Scene Description library Bender is "
34 /*fields*/ app_usd_info_fields
,
35 /*n_in_sequence*/ ARRAY_SIZE(app_usd_info_fields
) - 1,
38 static PyObject
*make_usd_info()
40 PyObject
*usd_info
= PyStructSequence_New(&BlenderAppUSDType
);
42 if (usd_info
== nullptr) {
49 # define SetStrItem(str) PyStructSequence_SET_ITEM(usd_info, pos++, PyUnicode_FromString(str))
52 #define SetObjItem(obj) PyStructSequence_SET_ITEM(usd_info, pos++, obj)
55 const int curversion
= blender::io::usd::USD_get_version();
56 const int major
= curversion
/ 10000;
57 const int minor
= (curversion
/ 100) % 100;
58 const int patch
= curversion
% 100;
60 SetObjItem(PyBool_FromLong(1));
61 SetObjItem(PyC_Tuple_Pack_I32({major
, minor
, patch
}));
62 SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", major
, minor
, patch
));
64 SetObjItem(PyBool_FromLong(0));
65 SetObjItem(PyC_Tuple_Pack_I32({0, 0, 0}));
66 SetStrItem("Unknown");
69 if (UNLIKELY(PyErr_Occurred())) {
80 PyObject
*BPY_app_usd_struct()
82 PyStructSequence_InitType(&BlenderAppUSDType
, &app_usd_info_desc
);
84 PyObject
*ret
= make_usd_info();
86 /* prevent user from creating new instances */
87 BlenderAppUSDType
.tp_init
= nullptr;
88 BlenderAppUSDType
.tp_new
= nullptr;
89 /* Without this we can't do `set(sys.modules)` #29635. */
90 BlenderAppUSDType
.tp_hash
= (hashfunc
)_Py_HashPointer
;