-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpythonHelpers.cpp
More file actions
35 lines (32 loc) · 972 Bytes
/
pythonHelpers.cpp
File metadata and controls
35 lines (32 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "pythonHelpers.hpp"
#include "pathUtils.hpp"
#include <stdlib.h>
namespace scorepy
{
CString get_module_name(const PyFrameObject& frame)
{
PyObject* module_name = PyDict_GetItemString(frame.f_globals, "__name__");
if (module_name)
return get_string_from_python(*module_name);
// this is a NUMPY special situation, see NEP-18, and Score-P issue #63
const CString filename = get_string_from_python(*frame.f_code->co_filename);
if (filename == "<__array_function__ internals>")
{
return "numpy.__array_function__";
}
else
{
return "unkown";
}
}
CString get_file_name(const PyFrameObject& frame)
{
PyObject* filename = frame.f_code->co_filename;
if (filename == Py_None)
{
return "None";
}
const std::string full_file_name = abspath(PyUnicode_AsUTF8(filename));
return !full_file_name.empty() ? CStrubg(full_file_name) : CString("ErrorPath");
}
} // namespace scorepy