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 36 37 38 39 40 41 42 43
|
#include "../Config.hh"
#include "../InstallPrefix.hh"
#include <fstream>
#include "py_helpers.hh"
#include "nlohmann/json.hpp"
#include <iostream>
namespace cadabra {
namespace py = pybind11;
py::object get_locals()
{
return py::reinterpret_borrow<py::object>(PyEval_GetLocals());
}
py::object get_globals()
{
return py::globals();
}
bool scope_has(const py::dict& dict, const std::string& obj)
{
for (const auto& item : dict)
if (item.first.cast<std::string>() == obj)
return true;
return false;
}
std::string read_manual(const char* category, const char* name)
{
std::string manual_page = std::string(cadabra::cmake_install_prefix()) + "/share/cadabra2/manual/" + category + "/" + name + ".cnb";
std::ifstream ifs(manual_page);
try {
nlohmann::json root=nlohmann::json::parse(ifs);
return (*root["cells"].begin())["source"].get<std::string>();
}
catch(nlohmann::json::exception& ex) {
return "Failed to collect help information; no info at "+manual_page+".";
}
}
}
|