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

Method load_from_scope

flow-rs/src/loader/python/mod.rs:141–191  ·  view source on GitHub ↗
(&self, local_key: u64)

Source from the content-addressed store, hash-verified

139
140impl Loader for PythonLoader {
141 fn load_from_scope(&self, local_key: u64) -> Result<Vec<Box<dyn Plugin>>> {
142 pyo3::prepare_freethreaded_python();
143 let mut plugins = vec![];
144 Python::with_gil(|py| -> PyResult<()> {
145 let plugins_param: HashMap<String, Vec<&PyDict>> = py
146 .import("megflow")?
147 .getattr("collect")?
148 .call0()?
149 .extract()?;
150 for plugin_param in &plugins_param["nodes"] {
151 let name: String = plugin_param.get_item("name").expect(ERR_MSG).extract()?;
152 let inputs: Vec<String> =
153 plugin_param.get_item("inputs").expect(ERR_MSG).extract()?;
154 let outputs: Vec<String> =
155 plugin_param.get_item("outputs").expect(ERR_MSG).extract()?;
156 let code: PyObject = plugin_param.get_item("code").expect(ERR_MSG).extract()?;
157 let exclusive: bool = plugin_param
158 .get_item("exclusive")
159 .expect(ERR_MSG)
160 .extract()?;
161 plugins.push(
162 NodePlugin::new(
163 local_key,
164 RegistryNodeParams {
165 name,
166 code,
167 inputs,
168 outputs,
169 exclusive,
170 },
171 )
172 .boxed(),
173 );
174 }
175 for plugin_param in &plugins_param["resources"] {
176 let name: String = plugin_param.get_item("name").expect(ERR_MSG).extract()?;
177 let code: PyObject = plugin_param.get_item("code").expect(ERR_MSG).extract()?;
178 plugins.push(
179 ResourcePlugin {
180 local_key,
181 name,
182 res: code,
183 }
184 .boxed(),
185 )
186 }
187 Ok(())
188 })?;
189
190 Ok(plugins)
191 }
192 fn load_from_file(
193 &self,
194 local_key: u64,

Callers 2

loadFunction · 0.80
load_from_fileMethod · 0.80

Calls 2

pushMethod · 0.80
boxedMethod · 0.45

Tested by

no test coverage detected