File: plugin.rs

package info (click to toggle)
rust-breezyshim 0.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 996 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,011 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Plugin loading and management.
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;

/// Load all Breezy plugins.
///
/// This function loads all available Breezy plugins. It should be called
/// before using functionality that might depend on plugins, such as
/// support for specific version control systems.
///
/// # Returns
///
/// `true` if plugins were loaded, `false` if Breezy was already initialized
pub fn load_plugins() -> bool {
    Python::attach(|py| {
        let m = py.import("breezy.plugin").unwrap();
        match m.call_method0("load_plugins") {
            Ok(_) => true,
            Err(e)
                if e.is_instance_of::<PyRuntimeError>(py)
                    && e.to_string().contains("Breezy already initialized") =>
            {
                false
            }
            Err(e) => panic!("Error loading plugins: {}", e),
        }
    })
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_load_plugins() {
        load_plugins();
    }
}