OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp} Namespace Reference

Functions

boost::filesystem::path canonical_or_absolute (const boost::filesystem::path &path)
std::string plugin_package_extension (const boost::filesystem::path &path)
boost::filesystem::path local_plugin_root ()
boost::filesystem::path local_plugin_install_dir (const boost::filesystem::path &source_path)
void assign_local_plugin_key (PluginDescriptor &plugin_descriptor, const boost::filesystem::path &entry_file)
bool read_local_plugin_package_metadata (const boost::filesystem::path &source_path, PluginDescriptor &plugin_descriptor, std::string &error)
void teardown_capabilities (std::vector< std::shared_ptr< PluginCapabilityInterface > > &capabilities, std::size_t lifecycle_count)
bool add_wheel_dependencies_to_sys_path (const PluginDescriptor &descriptor, std::vector< std::string > &plugin_paths, std::string &error)
PyObject * import_plugin_module (const PluginDescriptor &descriptor, std::vector< std::string > &plugin_paths, std::vector< std::string > &plugin_modules, std::string &error)
std::string plugin_module_name (const PluginDescriptor &descriptor)

Function Documentation

◆ add_wheel_dependencies_to_sys_path()

bool Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp}::add_wheel_dependencies_to_sys_path ( const PluginDescriptor & descriptor,
std::vector< std::string > & plugin_paths,
std::string & error )
155{
156 namespace fs = boost::filesystem;
157
158 const fs::path entry_path(descriptor.entry_path);
159 const fs::path plugin_dir = entry_path.has_extension() ? entry_path.parent_path() : entry_path;
160 if (!fs::exists(plugin_dir) || !fs::is_directory(plugin_dir))
161 return true;
162
164 for (fs::directory_iterator it(plugin_dir); it != fs::directory_iterator(); ++it) {
165 if (!fs::is_regular_file(it->status()) || it->path().extension() != ".whl")
166 continue;
167 // Skip the entry file itself — it is loaded by its own path.
168 if (it->path() == entry_path)
169 continue;
170
171 const fs::path dep_dir = plugin_dir / "__whl_extracted__" / it->path().stem().string();
172 if (!fs::exists(dep_dir)) {
173 std::string extract_error;
174 if (!extract_zip_to_directory(it->path(), dep_dir, extract_error)) {
175 // TRN %1% is the dependency file, %2% the error detail.
176 error = GUI::format(_u8L("Failed to extract plugin .whl dependency %1%: %2%"), it->path().string(), extract_error);
177 return false;
178 }
179 }
180
181 std::string syspath_error;
182 if (!interpreter.add_plugin_sys_path(dep_dir.string(), syspath_error)) {
183 error = GUI::format(_u8L("Failed to add .whl dependency to sys.path: %1%"), syspath_error);
184 return false;
185 }
186 plugin_paths.push_back(dep_dir.string());
187 }
188
189 return true;
190}
Definition PythonInterpreter.hpp:40
bool add_plugin_sys_path(const std::string &path, std::string &error)
Definition PythonInterpreter.cpp:805
static PythonInterpreter & instance()
Definition PythonInterpreter.cpp:434
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:36
bool extract_zip_to_directory(const boost::filesystem::path &zip_path, const boost::filesystem::path &destination, std::string &error)
Definition PluginFsUtils.cpp:659
Definition Utils.hpp:97
#define _u8L(s)
Definition I18N.hpp:11
std::string entry_path
Definition PluginDescriptor.hpp:63

References _u8L, Slic3r::PythonInterpreter::add_plugin_sys_path(), add_wheel_dependencies_to_sys_path(), Slic3r::PluginDescriptor::entry_path, Slic3r::extract_zip_to_directory(), Slic3r::GUI::format(), and Slic3r::PythonInterpreter::instance().

Referenced by add_wheel_dependencies_to_sys_path().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ assign_local_plugin_key()

void Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp}::assign_local_plugin_key ( PluginDescriptor & plugin_descriptor,
const boost::filesystem::path & entry_file )
87{
88 plugin_descriptor.plugin_key = make_local_plugin_key(entry_file.stem().string());
89}
std::string make_local_plugin_key(const std::string &stem)
Definition PluginDescriptor.hpp:214
std::string plugin_key
Definition PluginDescriptor.hpp:54

References assign_local_plugin_key(), Slic3r::make_local_plugin_key(), and Slic3r::PluginDescriptor::plugin_key.

Referenced by assign_local_plugin_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canonical_or_absolute()

boost::filesystem::path Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp}::canonical_or_absolute ( const boost::filesystem::path & path)
51{
52 namespace fs = boost::filesystem;
53
54 boost::system::error_code ec;
55 fs::path resolved = fs::weakly_canonical(path, ec);
56 if (!ec && !resolved.empty())
57 return resolved;
58
59 ec.clear();
60 resolved = fs::absolute(path, ec);
61 if (!ec && !resolved.empty())
62 return resolved;
63
64 return path;
65}

References canonical_or_absolute().

Referenced by canonical_or_absolute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ import_plugin_module()

PyObject * Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp}::import_plugin_module ( const PluginDescriptor & descriptor,
std::vector< std::string > & plugin_paths,
std::vector< std::string > & plugin_modules,
std::string & error )
196{
198
199 if (descriptor.entry_package.empty())
200 return interpreter.load_module_from_file(descriptor.entry_path, error, &plugin_paths, &plugin_modules);
201
202 if (boost::filesystem::path(descriptor.entry_path).extension() == ".whl")
203 return interpreter.load_module_from_whl(
204 descriptor.entry_path, descriptor.entry_package, error, &plugin_paths, &plugin_modules);
205
206 return interpreter.load_module_from_directory(
207 descriptor.entry_path, descriptor.entry_package, error, &plugin_paths, &plugin_modules);
208}
PyObject * load_module_from_file(const std::string &file_path, std::string &error, std::vector< std::string > *plugin_paths=nullptr, std::vector< std::string > *plugin_modules=nullptr)
Definition PythonInterpreter.cpp:1091
PyObject * load_module_from_whl(const std::string &whl_path, const std::string &pkg_name, std::string &error, std::vector< std::string > *plugin_paths=nullptr, std::vector< std::string > *plugin_modules=nullptr)
Definition PythonInterpreter.cpp:1192
PyObject * load_module_from_directory(const std::string &dir_path, const std::string &pkg_name, std::string &error, std::vector< std::string > *plugin_paths=nullptr, std::vector< std::string > *plugin_modules=nullptr)
Definition PythonInterpreter.cpp:1144
std::string entry_package
Definition PluginDescriptor.hpp:64

References Slic3r::PluginDescriptor::entry_package, Slic3r::PluginDescriptor::entry_path, import_plugin_module(), Slic3r::PythonInterpreter::instance(), Slic3r::PythonInterpreter::load_module_from_directory(), Slic3r::PythonInterpreter::load_module_from_file(), and Slic3r::PythonInterpreter::load_module_from_whl().

Referenced by import_plugin_module().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ local_plugin_install_dir()

boost::filesystem::path Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp}::local_plugin_install_dir ( const boost::filesystem::path & source_path)
80{
81 // Folder name follows the plugin filename and is the install/backup conflict unit;
82 // plugin_key is the file stem of the same file.
83 return local_plugin_root() / filesystem_safe_escape(source_path.filename().string());
84}
boost::filesystem::path local_plugin_root()
Definition PluginLoader.cpp:74
std::string filesystem_safe_escape(const std::string &value)
Definition PluginDescriptor.hpp:167

References Slic3r::filesystem_safe_escape(), local_plugin_install_dir(), and local_plugin_root().

Referenced by local_plugin_install_dir().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ local_plugin_root()

boost::filesystem::path Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp}::local_plugin_root ( )
75{
76 return boost::filesystem::path(data_dir()) / "orca_plugins";
77}
const std::string & data_dir()
Definition utils.cpp:365

References Slic3r::data_dir(), and local_plugin_root().

Referenced by local_plugin_install_dir(), and local_plugin_root().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plugin_module_name()

std::string Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp}::plugin_module_name ( const PluginDescriptor & descriptor)
211{
212 if (!descriptor.entry_package.empty())
213 return descriptor.entry_package;
214 return boost::filesystem::path(descriptor.entry_path).stem().string();
215}

References Slic3r::PluginDescriptor::entry_package, Slic3r::PluginDescriptor::entry_path, and plugin_module_name().

Referenced by plugin_module_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plugin_package_extension()

std::string Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp}::plugin_package_extension ( const boost::filesystem::path & path)
68{
69 std::string ext = path.extension().string();
70 boost::algorithm::to_lower(ext);
71 return ext;
72}

References plugin_package_extension().

Referenced by plugin_package_extension(), and read_local_plugin_package_metadata().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_local_plugin_package_metadata()

bool Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp}::read_local_plugin_package_metadata ( const boost::filesystem::path & source_path,
PluginDescriptor & plugin_descriptor,
std::string & error )
94{
95 error.clear();
96
97 const std::string ext = plugin_package_extension(source_path);
98 if (ext != ".py" && ext != ".whl") {
99 error = GUI::format(_u8L("Plugin package must be a .py or .whl file, got: %1%"), ext);
100 return false;
101 }
102
103 bool ok = false;
104 if (ext == ".whl")
105 ok = read_wheel_plugin_metadata(source_path, plugin_descriptor, error);
106 else
107 ok = read_python_plugin_metadata(source_path, plugin_descriptor, error);
108
109 if (!ok)
110 return false;
111
112 plugin_descriptor.cloud = std::nullopt;
113 return true;
114}
std::string plugin_package_extension(const boost::filesystem::path &path)
Definition PluginLoader.cpp:67
bool read_python_plugin_metadata(const boost::filesystem::path &py_path, PluginDescriptor &descriptor, std::string &error)
Definition PluginFsUtils.cpp:919
bool read_wheel_plugin_metadata(const boost::filesystem::path &whl_path, PluginDescriptor &descriptor, std::string &error)
Definition PluginFsUtils.cpp:1004
std::optional< CloudPluginState > cloud
Definition PluginDescriptor.hpp:69

References _u8L, Slic3r::PluginDescriptor::cloud, Slic3r::GUI::format(), plugin_package_extension(), read_local_plugin_package_metadata(), Slic3r::read_python_plugin_metadata(), and Slic3r::read_wheel_plugin_metadata().

Referenced by read_local_plugin_package_metadata().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ teardown_capabilities()

void Slic3r::plugin_loader::anonymous_namespace{PluginLoader.cpp}::teardown_capabilities ( std::vector< std::shared_ptr< PluginCapabilityInterface > > & capabilities,
std::size_t lifecycle_count )
120{
121 if (capabilities.empty())
122 return;
123
124 if (!PythonInterpreter::instance().is_initialized()) {
125 capabilities.clear();
126 return;
127 }
128
129 PythonGILState gil;
130 if (!gil) {
131 capabilities.clear();
132 return;
133 }
134
135 lifecycle_count = std::min(lifecycle_count, capabilities.size());
136 for (std::size_t index = 0; index < lifecycle_count; ++index) {
137 const auto& capability = capabilities[index];
138 if (!capability)
139 continue;
140 try {
141 capability->on_unload();
142 } catch (const std::exception& ex) {
143 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": Plugin on_unload failed: " << ex.what();
144 } catch (...) {
145 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": Plugin on_unload failed";
146 }
147 }
148 capabilities.clear();
149}
Definition PythonInterpreter.hpp:169

References Slic3r::PythonInterpreter::instance(), and teardown_capabilities().

Referenced by teardown_capabilities().

Here is the call graph for this function:
Here is the caller graph for this function: