| 94 | } // namespace |
| 95 | |
| 96 | PYBIND11_MODULE(_tf_stack, m) { |
| 97 | // TODO(slebedev): consider dropping convert_stack in favor of |
| 98 | // a lazily initialized StackFrame.code property (using linecache). |
| 99 | py::class_<StackFrame>(m, "StackFrame") |
| 100 | .def(py::init<const py::str&, int, const py::str&, const py::object&, |
| 101 | int>()) |
| 102 | .def_readonly("filename", &StackFrame::filename) |
| 103 | .def_readonly("lineno", &StackFrame::lineno) |
| 104 | .def_readonly("name", &StackFrame::name) |
| 105 | .def_readonly("globals", &StackFrame::globals) |
| 106 | .def_readonly("func_start_lineno", &StackFrame::func_start_lineno) |
| 107 | .def("__repr__", [](const StackFrame& self) { |
| 108 | return py::str( |
| 109 | "StackFrame(filename={}, lineno={}, name={}, globals={}, " |
| 110 | "func_start_lineno={})") |
| 111 | .format(self.filename, self.lineno, self.name, self.globals, |
| 112 | self.func_start_lineno); |
| 113 | }); |
| 114 | |
| 115 | py::bind_vector<std::vector<StackFrame>>(m, "Stack", py::module_local(true)); |
| 116 | |
| 117 | m.def("extract_stack", [](const py::object& limit, const py::list& mappers, |
| 118 | const py::list& filters) { |
| 119 | // In Python 3.X ``traceback.extract_stack`` allows ``limit`` to |
| 120 | // either be None or -1. |
| 121 | return ExtractStack(limit.is_none() ? -1 : py::cast<ssize_t>(limit), |
| 122 | mappers, filters); |
| 123 | }); |
| 124 | } |
| 125 | |
| 126 | } // namespace tensorflow |
nothing calls this directly
no test coverage detected