MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / load_from_file

Method load_from_file

flow-rs/src/loader/python/mod.rs:192–225  ·  view source on GitHub ↗
(
        &self,
        local_key: u64,
        module_path: Option<&Path>,
        plugin_path: &Path,
    )

Source from the content-addressed store, hash-verified

190 Ok(plugins)
191 }
192 fn load_from_file(
193 &self,
194 local_key: u64,
195 module_path: Option<&Path>,
196 plugin_path: &Path,
197 ) -> Result<Vec<Box<dyn Plugin>>> {
198 pyo3::prepare_freethreaded_python();
199 let cur = std::env::current_dir()?;
200 let module_path = module_path.unwrap_or(&cur);
201 let module_name = path_to_module(module_path, plugin_path)?;
202
203 Python::with_gil(|py| -> PyResult<_> {
204 let module_path = module_path.display().to_string();
205 let syspath: &PyList = py.import("sys")?.getattr("path")?.try_into()?;
206 if !syspath
207 .iter()
208 .any(|path| module_path.as_str() == path.extract::<&str>().unwrap())
209 {
210 syspath.insert(0, module_path)?;
211 }
212
213 ONCE_REGISTER.call_once(|| {
214 let module = py.import("megflow").expect("module megflow not found");
215 utils::utils_register(module).expect("python utility functions register fault");
216 envelope::envelope_register(module).expect("python envelope register fault");
217 });
218
219 py.import(module_name.as_str())?;
220
221 Ok(())
222 })?;
223
224 self.load_from_scope(local_key)
225 }
226}
227
228crate::submit!(

Callers 1

loadFunction · 0.80

Calls 5

path_to_moduleFunction · 0.85
utils_registerFunction · 0.85
envelope_registerFunction · 0.85
insertMethod · 0.80
load_from_scopeMethod · 0.80

Tested by

no test coverage detected