HDK
|
#include "pxr/pxr.h"
#include "pxr/base/tf/refPtr.h"
#include "pxr/base/tf/weakPtr.h"
#include "pxr/base/tf/diagnosticLite.h"
#include "pxr/base/tf/preprocessorUtilsLite.h"
#include "pxr/base/tf/py3Compat.h"
#include "pxr/base/tf/pyInterpreter.h"
#include "pxr/base/tf/pyLock.h"
#include "pxr/base/tf/api.h"
#include <functional>
#include <typeinfo>
#include <string>
#include <vector>
#include <hboost/python/dict.hpp>
#include <hboost/python/extract.hpp>
#include <hboost/python/handle.hpp>
#include <hboost/python/object.hpp>
#include <hboost/python/type_id.hpp>
Go to the source code of this file.
Macros | |
#define | TF_PY_REPR_PREFIX |
Miscellaneous Utilities for dealing with script.
Definition in file pyUtils.h.
#define TF_PY_REPR_PREFIX |
TF_API bool Tf_PyEvaluateWithErrorCheck | ( | const std::string & | expr, |
hboost::python::object * | obj | ||
) |
TF_API void Tf_PyLoadScriptModule | ( | std::string const & | name | ) |
Load the python module moduleName. This is used by some low-level infrastructure code to load python wrapper modules corresponding to C++ shared libraries when they are needed. It should generally not need to be called from normal user code.
TF_API void Tf_PyWrapOnceImpl | ( | hboost::python::type_info const & | , |
std::function< void()> const & | , | ||
bool * | |||
) |
TF_API hboost::python::object TfPyCopyBufferToByteArray | ( | const char * | buffer, |
size_t | size | ||
) |
Create a python bytearray from an input buffer and size.
If a size of zero is passed in this function will return a valid python bytearray of size zero.
An invalid object handle is returned on failure.
hboost::python::dict TfPyCopyMapToDictionary | ( | Map const & | map | ) |
hboost::python::list TfPyCopySequenceToList | ( | Seq const & | seq | ) |
hboost::python::object TfPyCopySequenceToSet | ( | Seq const & | seq | ) |
hboost::python::tuple TfPyCopySequenceToTuple | ( | Seq const & | seq | ) |
TF_API hboost::python::object TfPyEvaluate | ( | std::string const & | expr, |
hboost::python::dict const & | extraGlobals = hboost::python::dict() |
||
) |
Evaluate python expression expr with all the known script modules imported under their standard names. Additional globals may be provided in the extraGlobals
dictionary.
bool TfPyEvaluateAndExtract | ( | const std::string & | expr, |
T * | t | ||
) |
TF_API std::string TfPyGetClassName | ( | hboost::python::object const & | obj | ) |
Return the name of the class of obj.
TF_API hboost::python::object TfPyGetClassObject | ( | std::type_info const & | type | ) |
Return the python class object for type if type has been wrapped. Otherwise return None.
hboost::python::object TfPyGetClassObject | ( | ) |
Populates the vector passed in with pointers to strings containing the python interpreter stack frames. Note that TfPyGetStackFrames allocates these strings on the heap and its the caller's responsibility to free them.
TF_API std::vector<std::string> TfPyGetTraceback | ( | ) |
Return a vector of strings containing the current python traceback.
The vector contains the same strings that python's traceback.format_stack() returns.
TF_API bool TfPyIsInitialized | ( | ) |
Returns true if python is initialized.
TF_API bool TfPyIsNone | ( | hboost::python::object const & | obj | ) |
Return true iff obj is None.
TF_API int64_t TfPyNormalizeIndex | ( | int64_t | index, |
uint64_t | size, | ||
bool | throwError = false |
||
) |
Return a positive index in the range [0,size). If throwError is true, this will throw an index error if the resulting index is out of range.
hboost::python::object TfPyObject | ( | T const & | t, |
bool | complainOnFailure = true |
||
) |
|
inline |
TF_API std::string TfPyObjectRepr | ( | hboost::python::object const & | t | ) |
Return repr(t).
Calls PyObject_Repr on the given python object.
Print a standard traceback to sys.stderr and clear the error indicator. If the error is a KeyboardInterrupt then this does nothing. Call this function only when the error indicator is set.
std::string TfPyRepr | ( | T const & | t | ) |
std::string TfPyRepr | ( | const std::vector< T > & | v | ) |
TF_API bool TfPySetenv | ( | const std::string & | name, |
const std::string & | value | ||
) |
Set an environment variable in os.environ
.
This function is equivalent to
Calling this function without first initializing Python is an error and returns false
.
Note that this function will import the os
module, causing os.environ
to be poputated. All modifications to the environment after os
has been imported must be made with this function or TfSetenv
if it important that they appear in os.environ
.
TF_API void TfPyThrowIndexError | ( | std::string const & | msg | ) |
Raises a python IndexError
and throws a C++ exception. Intended to be used in wrapper code.
TF_API void TfPyThrowKeyError | ( | std::string const & | msg | ) |
Raises a python KeyError
and throws a C++ exception. Intended to be used in wrapper code.
TF_API void TfPyThrowRuntimeError | ( | std::string const & | msg | ) |
Raises a python RuntimError
and throws a C++ exception. Intended to be used in wrapper code.
TF_API void TfPyThrowStopIteration | ( | std::string const & | msg | ) |
Raises a python StopIteration
exception and throws a C++ exception. Intended to be used in wrapper code.
TF_API void TfPyThrowTypeError | ( | std::string const & | msg | ) |
Raises a python TypeError
and throws a C++ exception. Intended to be used in wrapper code.
TF_API void TfPyThrowValueError | ( | std::string const & | msg | ) |
Raises a python ValueError
and throws a C++ exception. Intended to be used in wrapper code.
TF_API bool TfPyUnsetenv | ( | const std::string & | name | ) |
Remove an environment variable from os.environ
.
This function is equivalent to
Calling this function without first initializing Python is an error and returns false
.
Note that this function will import the os
module, causing os.environ
to be poputated. All modifications to the environment after os
has been imported must be made with this function or TfUnsetenv
if it important that they appear in os.environ
.
Invokes wrapFunc
to wrap type T
if T
is not already wrapped.
Executing wrapFunc
must register T
with hboost python. Otherwise, wrapFunc
may be executed more than once.
TfPyWrapOnce will acquire the GIL prior to invoking wrapFunc
. Does not invoke wrapFunc
if Python has not been initialized.