(
mut config_path: Option<PathBuf>,
config_str: Option<String>,
dynamic_path: Option<PathBuf>,
dynamic_str: Option<String>,
plugin_path: Option<PathBuf>,
| 85 | dump = "false" |
| 86 | )] |
| 87 | fn new( |
| 88 | mut config_path: Option<PathBuf>, |
| 89 | config_str: Option<String>, |
| 90 | dynamic_path: Option<PathBuf>, |
| 91 | dynamic_str: Option<String>, |
| 92 | plugin_path: Option<PathBuf>, |
| 93 | module_path: Option<PathBuf>, |
| 94 | dump: bool, |
| 95 | ) -> PyResult<Graph> { |
| 96 | ONCE_INIT.call_once(|| { |
| 97 | // workaround for https://github.com/rust-lang/rust/issues/47384 |
| 98 | flow_plugins::export(); |
| 99 | ctrlc::set_handler(|| unsafe { libc::_exit(0) }).expect("Error setting Ctrl-C handler"); |
| 100 | }); |
| 101 | |
| 102 | // load graph |
| 103 | if let Some(plugin_path) = &plugin_path { |
| 104 | if config_str.is_none() && config_path.is_none() { |
| 105 | let mut config = std::fs::canonicalize(plugin_path).unwrap(); |
| 106 | let dirname = config.file_name().unwrap(); |
| 107 | let config_name = format!("{}.toml", dirname.to_str().unwrap()); |
| 108 | config.push(config_name); |
| 109 | config_path = Some(config); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if dump { |
| 114 | if let Some(config) = &config_path { |
| 115 | let mut dump_path = config.clone(); |
| 116 | dump_path.pop(); |
| 117 | let file_stem = config.file_stem().unwrap().to_str().unwrap(); |
| 118 | dump_path.push(format!("{}.png", file_stem)); |
| 119 | log::info!("dump path: {:?}", dump_path); |
| 120 | std::env::set_var("MEGFLOW_DUMP", dump_path.to_str().unwrap()); |
| 121 | } else { |
| 122 | let mut dump_path = std::env::current_dir().unwrap(); |
| 123 | dump_path.push("graph.png"); |
| 124 | log::info!("dump path: {:?}", dump_path); |
| 125 | std::env::set_var("MEGFLOW_DUMP", dump_path.to_str().unwrap()); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | let plugin_cfg = flow_rs::loader::LoaderConfig { |
| 130 | module_path, |
| 131 | plugin_path, |
| 132 | ty: flow_rs::loader::PluginType::Python, |
| 133 | }; |
| 134 | |
| 135 | let mut builder = Builder::new(); |
| 136 | if let Some(config_path) = config_path { |
| 137 | builder = builder |
| 138 | .template_file(&config_path) |
| 139 | .unwrap_or_else(|_| panic!("file[{:?}] not found", config_path)); |
| 140 | } |
| 141 | if let Some(config_str) = config_str { |
| 142 | builder = builder.template(config_str); |
| 143 | } |
| 144 | if let Some(dynamic_path) = dynamic_path { |
nothing calls this directly
no test coverage detected