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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_TF_PY_INTERPRETER_H
25 #define PXR_BASE_TF_PY_INTERPRETER_H
26 
27 /// \file tf/pyInterpreter.h
28 /// Python runtime utilities.
29 
30 #include "pxr/pxr.h"
31 
32 #include "pxr/base/tf/api.h"
33 #include <hboost/python/handle.hpp>
34 #include <hboost/python/object.hpp>
35 #include <string>
36 
38 
39 /// Starts up the python runtime.
40 /// IMPORTANT: The GIL will NOT be held when this returns.
41 /// (If Python is already initialized, the GIL will be unchanged)
42 ///
43 /// The program name and arguments are set automatically. sys.argv has no
44 /// arguments other than an argv[0] matching the program name.
45 TF_API
46 extern void TfPyInitialize();
47 
48 /// Runs the given string using PyRun_SimpleString().
49 ///
50 /// Starts the interpreter if necessary. Deals with necessary thread state
51 /// setup.
52 ///
53 /// Callers are not required to hold the GIL, though of course they may.
54 ///
55 /// Returns zero on success, nonzero on failure.
56 TF_API
57 extern int TfPyRunSimpleString(const std::string & cmd);
58 
59 /// Runs the given string using PyRun_String().
60 ///
61 /// \a start is Py_eval_input, Py_single_input or Py_file_input.
62 /// \a globals and locals can be dictionaries to use when evaluating the
63 /// string in python. Defaults to reusing globals from main module. If
64 /// only the globals are provided, they will also be used as locals.
65 ///
66 /// Starts the interpreter if necessary. Deals with necessary thread state
67 /// setup.
68 ///
69 /// Callers must hold the GIL before calling; see TfPyLock. This is true for
70 /// any hboost::python call, including constructing and destroying the default
71 /// values of \p globals and \p locals. Holding the GIL will also make it safe
72 /// to inspect the returned hboost::python::handle.
73 TF_API
74 extern hboost::python::handle<>
75 TfPyRunString(const std::string & cmd, int start,
78  );
79 
80 /// Runs the given file using PyRun_File().
81 ///
82 /// \a start is Py_eval_input, Py_single_input or Py_file_input.
83 /// \a globals and locals can be dictionaries to use when evaluating the
84 /// string in python. Defaults to reusing globals from main module. If
85 /// only the globals are provided, they will also be used as locals.
86 ///
87 /// Starts the interpreter if necessary. Deals with necessary thread state
88 /// setup.
89 ///
90 /// Callers must hold the GIL before calling; see TfPyLock. This is true for
91 /// any hboost::python call, including constructing and destroying the default
92 /// values of \p globals and \p locals. Holding the GIL will also make it safe
93 /// to inspect the returned hboost::python::handle.
94 TF_API
95 extern hboost::python::handle<>
96 TfPyRunFile(const std::string &filename, int start,
99  );
100 
102 
103 #endif // PXR_BASE_TF_PY_INTERPRETER_H
GT_API const UT_StringHolder filename
#define TF_API
Definition: api.h:40
TF_API hboost::python::handle TfPyRunString(const std::string &cmd, int start, hboost::python::object const &globals=hboost::python::object(), hboost::python::object const &locals=hboost::python::object())
GLuint start
Definition: glcorearb.h:475
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
PXR_NAMESPACE_OPEN_SCOPE TF_API void TfPyInitialize()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
TF_API hboost::python::handle TfPyRunFile(const std::string &filename, int start, hboost::python::object const &globals=hboost::python::object(), hboost::python::object const &locals=hboost::python::object())
TF_API int TfPyRunSimpleString(const std::string &cmd)