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 TF_API
53 extern int TfPyRunSimpleString(const std::string & cmd);
54 
55 /// Runs the given string using PyRun_String().
56 ///
57 /// \a start is Py_eval_input, Py_single_input or Py_file_input.
58 /// \a globals and locals can be dictionaries to use when evaluating the
59 /// string in python. Defaults to reusing globals from main module. If
60 /// only the globals are provided, they will also be used as locals.
61 ///
62 /// Starts the interpreter if necessary. Deals with necessary thread state
63 /// setup.
64 TF_API
65 extern hboost::python::handle<>
66 TfPyRunString(const std::string & cmd, int start,
69  );
70 
71 /// Runs the given file using PyRun_File().
72 ///
73 /// \a start is Py_eval_input, Py_single_input or Py_file_input.
74 /// \a globals and locals can be dictionaries to use when evaluating the
75 /// string in python. Defaults to reusing globals from main module. If
76 /// only the globals are provided, they will also be used as locals.
77 ///
78 /// Starts the interpreter if necessary. Deals with necessary thread state
79 /// setup.
80 TF_API
81 extern hboost::python::handle<>
82 TfPyRunFile(const std::string &filename, int start,
85  );
86 
87 /// Returns the disk path to the given module as an NSString.
88 ///
89 /// Starts the interpreter if necessary. Deals with necessary thread state
90 /// setup.
91 TF_API
92 extern std::string TfPyGetModulePath(const std::string & moduleName);
93 
95 
96 #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())
PXR_NAMESPACE_OPEN_SCOPE TF_API void TfPyInitialize()
GLuint object
Definition: glew.h:8986
GLuint start
Definition: glew.h:1253
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
#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 std::string TfPyGetModulePath(const std::string &moduleName)
TF_API int TfPyRunSimpleString(const std::string &cmd)