forked from LadybugDB/ladybug-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy_cached_import.cpp
More file actions
31 lines (24 loc) · 784 Bytes
/
Copy pathpy_cached_import.cpp
File metadata and controls
31 lines (24 loc) · 784 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
#include "cached_import/py_cached_import.h"
#include "common/exception/runtime.h"
namespace lbug {
std::shared_ptr<PythonCachedImport> importCache;
PythonCachedImport::~PythonCachedImport() {
py::gil_scoped_acquire acquire;
allObjects.clear();
}
py::handle PythonCachedImport::addToCache(py::object obj) {
auto ptr = obj.ptr();
allObjects.push_back(obj);
return ptr;
}
bool doesPyModuleExist(std::string moduleName) {
py::gil_scoped_acquire acquire;
auto find_spec = importCache->importlib.util.find_spec();
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
return find_spec(moduleName) != Py_None;
}
} // namespace lbug