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

Function find_lib_from_python

flow-plugins/src/utils/find_lib.rs:2–22  ·  view source on GitHub ↗
(module_name: &str, libs: &[&str])

Source from the content-addressed store, hash-verified

1#[cfg(feature = "python")]
2pub fn find_lib_from_python(module_name: &str, libs: &[&str]) -> Option<Vec<std::path::PathBuf>> {
3 use pyo3::prelude::*;
4 if let Ok(path) = Python::with_gil(|py| -> PyResult<String> {
5 let module = py.import(module_name)?;
6 module.getattr("__file__")?.extract()
7 }) {
8 let mut path = std::path::PathBuf::from(path);
9 path.pop();
10 Some(
11 libs.iter()
12 .map(|x| {
13 let mut path = path.clone();
14 path.push(x);
15 path
16 })
17 .collect(),
18 )
19 } else {
20 None
21 }
22}

Callers

nothing calls this directly

Calls 3

popMethod · 0.80
pushMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected