14#include <boost/python/class.hpp>
15#include <boost/python/import.hpp>
16#include <boost/python/reference_existing_object.hpp>
17#include <boost/python/return_value_policy.hpp>
31std::once_flag INIT_FLAG;
32bool INSTANCE_CALLED =
false;
33constexpr auto PYTHONPATHS_KEY =
"pythonscripts.directories";
34constexpr auto PATH_SEPARATOR =
";";
48void updatePythonPaths() {
50 auto python_scripts_dir = ConfigService::Instance().
getValue<std::string>(PYTHONPATHS_KEY).value_or(
"");
52 if (!python_scripts_dir.empty()) {
54 object sys_pkg =
import(
"sys");
58 for (
auto python_dir : tokens) {
60 if (python_dir.ends_with(
"\\"))
61 python_dir = python_dir.substr(0, python_dir.size() - 1);
62 if (python_dir.ends_with(
"/"))
63 python_dir = python_dir.substr(0, python_dir.size() - 1);
66 if (!python_dir.empty()) {
68 sys_pkg.attr(
"path").attr(
"append")(python_dir);
88 auto &frameworkMgr = []() ->
auto & {
91 return FrameworkManager::Instance();
93 std::call_once(INIT_FLAG, []() {
94 INSTANCE_CALLED =
true;
95 declareCPPAlgorithms();
97 import(
"mantid.simpleapi");
102 PyRun_SimpleString(
"import atexit\n"
103 "def cleanupFrameworkManager():\n"
104 " from mantid.api import FrameworkManager\n"
105 " FrameworkManager.shutdown()\n"
106 "atexit.register(cleanupFrameworkManager)");
114bool hasInstance() {
return INSTANCE_CALLED; }
118 class_<FrameworkManagerImpl, boost::noncopyable>(
"FrameworkManagerImpl", no_init)
120 "Sets the number of OpenMP threads to the value "
125 "Set the number of OpenMP threads to the given value")
128 "Returns the number of OpenMP threads that will be used.")
133 "Clear memory held by algorithms (does not include workspaces)")
136 "Clear memory held by the data service (essentially all "
141 "Clear memory held by the cached instruments")
144 "Clear memory held by the PropertyManagerDataService")
148 .def(
"hasInstance", hasInstance,
"Returns True if Instance has been called, false otherwise")
149 .staticmethod(
"hasInstance")
151 .def(
"Instance", instance,
"Return a reference to the singleton instance",
152 return_value_policy<reference_existing_object>())
153 .staticmethod(
"Instance");
void export_FrameworkManager()
The main public API via which users interact with the Mantid framework.
void clearPropertyManagers()
Clear memory associated with the PropertyManagers.
void setNumOMPThreads(const int nthreads)
Set the number of OpenMP threads to the given value.
void clearInstruments()
Clear memory associated with the IDS.
void clearData()
Clear memory associated with the ADS.
void shutdown()
shuts down and performs clean up tasks
int getNumOMPThreads() const
Returns the number of OpenMP threads that will be used.
void setNumOMPThreadsToConfigValue()
Set the number of OpenMP threads to use based on the config value.
void clear()
Clears all memory associated with the AlgorithmManager, ADS & IDS.
void clearAlgorithms()
Clear memory associated with the AlgorithmManager.
T getValue(const std::string &name) const
Templated method to get the value of a property.
Defines a structure for releasing the Python GIL using the RAII pattern.
Mantid::Kernel::SingletonHolder< AlgorithmFactoryImpl > AlgorithmFactory
Mantid::Kernel::SingletonHolder< FrameworkManagerImpl > FrameworkManager
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService