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/pySafePython.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 |
Functions | |
TF_API bool | TfPyIsInitialized () |
Returns true if python is initialized. More... | |
TF_API void | TfPyThrowIndexError (const char *msg) |
void | TfPyThrowIndexError (std::string const &msg) |
TF_API void | TfPyThrowRuntimeError (const char *msg) |
void | TfPyThrowRuntimeError (std::string const &msg) |
TF_API void | TfPyThrowStopIteration (const char *msg) |
void | TfPyThrowStopIteration (std::string const &msg) |
TF_API void | TfPyThrowKeyError (const char *msg) |
void | TfPyThrowKeyError (std::string const &msg) |
TF_API void | TfPyThrowValueError (const char *msg) |
void | TfPyThrowValueError (std::string const &msg) |
TF_API void | TfPyThrowTypeError (const char *msg) |
void | TfPyThrowTypeError (std::string const &msg) |
TF_API bool | TfPyIsNone (hboost::python::object const &obj) |
Return true iff obj is None. More... | |
TF_API bool | TfPyIsNone (hboost::python::handle<> const &obj) |
Return true iff obj is None. More... | |
TF_API void | Tf_PyObjectError (bool printError) |
template<typename T > | |
hboost::python::object | TfPyObject (T const &t, bool complainOnFailure=true) |
hboost::python::object | TfPyObject (PyObject *t, bool complainOnFailure=true) |
TF_API std::string | TfPyObjectRepr (hboost::python::object const &t) |
template<typename T > | |
std::string | TfPyRepr (T const &t) |
template<typename T > | |
std::string | TfPyRepr (const std::vector< T > &v) |
Return repr(t) for a vector as a python list. More... | |
TF_API hboost::python::object | TfPyEvaluate (std::string const &expr, hboost::python::dict const &extraGlobals=hboost::python::dict()) |
TF_API int64_t | TfPyNormalizeIndex (int64_t index, uint64_t size, bool throwError=false) |
TF_API std::string | TfPyGetClassName (hboost::python::object const &obj) |
Return the name of the class of obj. More... | |
TF_API hboost::python::object | TfPyGetClassObject (std::type_info const &type) |
template<typename T > | |
hboost::python::object | TfPyGetClassObject () |
TF_API void | Tf_PyWrapOnceImpl (hboost::python::type_info const &, std::function< void()> const &, bool *) |
template<typename T > | |
void | TfPyWrapOnce (std::function< void()> const &wrapFunc) |
TF_API void | Tf_PyLoadScriptModule (std::string const &name) |
template<class Map > | |
hboost::python::dict | TfPyCopyMapToDictionary (Map const &map) |
Creates a python dictionary from a std::map. More... | |
template<class Seq > | |
hboost::python::list | TfPyCopySequenceToList (Seq const &seq) |
template<class Seq > | |
hboost::python::object | TfPyCopySequenceToSet (Seq const &seq) |
template<class Seq > | |
hboost::python::tuple | TfPyCopySequenceToTuple (Seq const &seq) |
TF_API hboost::python::object | TfPyCopyBufferToByteArray (const char *buffer, size_t size) |
TF_API std::vector< std::string > | TfPyGetTraceback () |
TF_API void | TfPyGetStackFrames (std::vector< uintptr_t > *frames) |
TF_API void | TfPyDumpTraceback () |
Print the current python traceback to stdout. More... | |
TF_API bool | TfPySetenv (const std::string &name, const std::string &value) |
TF_API bool | TfPyUnsetenv (const std::string &name) |
TF_API bool | Tf_PyEvaluateWithErrorCheck (const std::string &expr, hboost::python::object *obj) |
template<typename T > | |
bool | TfPyEvaluateAndExtract (const std::string &expr, T *t) |
TF_API void | TfPyPrintError () |
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 bool TfPyIsNone | ( | hboost::python::handle<> 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
.
Raises a Python IndexError
with the given error msg
and throws a hboost::python::error_already_set exception. Callers must hold the GIL before calling this function.
|
inline |
Raises a Python KeyError
with the given error msg
and throws a hboost::python::error_already_set exception. Callers must hold the GIL before calling this function.
|
inline |
Raises a Python RuntimeError
with the given error msg
and throws a hboost::python::error_already_set exception. Callers must hold the GIL before calling this function.
|
inline |
Raises a Python StopIteration
with the given error msg
and throws a hboost::python::error_already_set exception. Callers must hold the GIL before calling this function.
|
inline |
Raises a Python TypeError
with the given error msg
and throws a hboost::python::error_already_set exception. Callers must hold the GIL before calling this function.
|
inline |
Raises a Python ValueError
with the given error msg
and throws a hboost::python::error_already_set exception. Callers must hold the GIL before calling this function.
|
inline |
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.