HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyInterpreter.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_TF_PY_INTERPRETER_H
8 #define PXR_BASE_TF_PY_INTERPRETER_H
9 
10 /// \file tf/pyInterpreter.h
11 /// Python runtime utilities.
12 
13 #include "pxr/pxr.h"
14 
15 #include "pxr/base/tf/api.h"
16 #include "pxr/external/boost/python/handle.hpp"
17 #include "pxr/external/boost/python/object.hpp"
18 #include <string>
19 
21 
22 /// Starts up the python runtime.
23 /// IMPORTANT: The GIL will NOT be held when this returns.
24 /// (If Python is already initialized, the GIL will be unchanged)
25 ///
26 /// The program name and arguments are set automatically. sys.argv has no
27 /// arguments other than an argv[0] matching the program name.
28 TF_API
29 extern void TfPyInitialize();
30 
31 /// Runs the given string using PyRun_SimpleString().
32 ///
33 /// Starts the interpreter if necessary. Deals with necessary thread state
34 /// setup.
35 ///
36 /// Callers are not required to hold the GIL, though of course they may.
37 ///
38 /// Returns zero on success, nonzero on failure.
39 TF_API
40 extern int TfPyRunSimpleString(const std::string & cmd);
41 
42 /// Runs the given string using PyRun_String().
43 ///
44 /// \a start is Py_eval_input, Py_single_input or Py_file_input.
45 /// \a globals and locals can be dictionaries to use when evaluating the
46 /// string in python. Defaults to reusing globals from main module. If
47 /// only the globals are provided, they will also be used as locals.
48 ///
49 /// Starts the interpreter if necessary. Deals with necessary thread state
50 /// setup.
51 ///
52 /// Callers must hold the GIL before calling; see TfPyLock. This is true for
53 /// any pxr_boost::python call, including constructing and destroying the default
54 /// values of \p globals and \p locals. Holding the GIL will also make it safe
55 /// to inspect the returned pxr_boost::python::handle.
56 TF_API
57 extern pxr_boost::python::handle<>
58 TfPyRunString(const std::string & cmd, int start,
61  );
62 
63 /// Runs the given file using PyRun_File().
64 ///
65 /// \a start is Py_eval_input, Py_single_input or Py_file_input.
66 /// \a globals and locals can be dictionaries to use when evaluating the
67 /// string in python. Defaults to reusing globals from main module. If
68 /// only the globals are provided, they will also be used as locals.
69 ///
70 /// Starts the interpreter if necessary. Deals with necessary thread state
71 /// setup.
72 ///
73 /// Callers must hold the GIL before calling; see TfPyLock. This is true for
74 /// any pxr_boost::python call, including constructing and destroying the default
75 /// values of \p globals and \p locals. Holding the GIL will also make it safe
76 /// to inspect the returned pxr_boost::python::handle.
77 TF_API
78 extern pxr_boost::python::handle<>
79 TfPyRunFile(const std::string &filename, int start,
82  );
83 
85 
86 #endif // PXR_BASE_TF_PY_INTERPRETER_H
GT_API const UT_StringHolder filename
#define TF_API
Definition: api.h:23
GLuint start
Definition: glcorearb.h:475
PXR_NAMESPACE_OPEN_SCOPE TF_API void TfPyInitialize()
TF_API pxr_boost::python::handle TfPyRunFile(const std::string &filename, int start, pxr_boost::python::object const &globals=pxr_boost::python::object(), pxr_boost::python::object const &locals=pxr_boost::python::object())
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
TF_API int TfPyRunSimpleString(const std::string &cmd)
TF_API pxr_boost::python::handle TfPyRunString(const std::string &cmd, int start, pxr_boost::python::object const &globals=pxr_boost::python::object(), pxr_boost::python::object const &locals=pxr_boost::python::object())