mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-04-20 05:39:54 +08:00
改掉一点之前写的比较粗糙的地方
This commit is contained in:
parent
546214f52f
commit
d4999d1ab3
|
@ -11,9 +11,12 @@ use std::time::SystemTime;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use pyo3::exceptions::PyTypeError;
|
use pyo3::{
|
||||||
use pyo3::types::PyTuple;
|
exceptions::PyTypeError,
|
||||||
use pyo3::{intern, prelude::*};
|
intern,
|
||||||
|
types::{PyAny, PyAnyMethods, PyModule, PyTracebackMethods, PyTuple},
|
||||||
|
Bound, Py, PyErr, PyResult, Python,
|
||||||
|
};
|
||||||
use tracing::{event, span, warn, Level};
|
use tracing::{event, span, warn, Level};
|
||||||
|
|
||||||
use crate::error::PyPluginError;
|
use crate::error::PyPluginError;
|
||||||
|
@ -121,7 +124,7 @@ pub fn get_py_err_traceback(py_err: &PyErr) -> String {
|
||||||
pub struct PyPlugin {
|
pub struct PyPlugin {
|
||||||
pub file_path: PathBuf,
|
pub file_path: PathBuf,
|
||||||
pub changed_time: Option<SystemTime>,
|
pub changed_time: Option<SystemTime>,
|
||||||
pub py_module: Py<PyAny>,
|
pub py_module: Py<PyModule>,
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +379,7 @@ impl TryFrom<RawPyPlugin> for PyPlugin {
|
||||||
Ok(PyPlugin {
|
Ok(PyPlugin {
|
||||||
file_path: path,
|
file_path: path,
|
||||||
changed_time,
|
changed_time,
|
||||||
py_module: module.clone().into_any().unbind(),
|
py_module: module.unbind(),
|
||||||
enabled: true,
|
enabled: true,
|
||||||
})
|
})
|
||||||
} else if config.is_none() {
|
} else if config.is_none() {
|
||||||
|
@ -384,7 +387,7 @@ impl TryFrom<RawPyPlugin> for PyPlugin {
|
||||||
Ok(PyPlugin {
|
Ok(PyPlugin {
|
||||||
file_path: path,
|
file_path: path,
|
||||||
changed_time,
|
changed_time,
|
||||||
py_module: module.clone().into_any().unbind(),
|
py_module: module.unbind(),
|
||||||
enabled: true,
|
enabled: true,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -406,7 +409,7 @@ impl TryFrom<RawPyPlugin> for PyPlugin {
|
||||||
Ok(PyPlugin {
|
Ok(PyPlugin {
|
||||||
file_path: path,
|
file_path: path,
|
||||||
changed_time,
|
changed_time,
|
||||||
py_module: module.clone().into_any().unbind(),
|
py_module: module.unbind(),
|
||||||
enabled: true,
|
enabled: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -471,9 +474,8 @@ pub fn py_module_from_code(content: &str, path: &Path) -> PyResult<Py<PyModule>>
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_c_str(),
|
.as_c_str(),
|
||||||
// !!!! 请注意, 一定要给他一个名字, cpython 会自动把后面的重名模块覆盖掉前面的
|
// !!!! 请注意, 一定要给他一个名字, cpython 会自动把后面的重名模块覆盖掉前面的
|
||||||
)
|
)?;
|
||||||
.map(|module| module.unbind());
|
Ok(module.unbind())
|
||||||
module
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user