chore(python): Print Python interpreter version (#3118)

* chore(pyo3_backend): Print bundle Python interpreter version

Signed-off-by: tison <wander4096@gmail.com>

* print RustPython interpreter version on init

Signed-off-by: tison <wander4096@gmail.com>

---------

Signed-off-by: tison <wander4096@gmail.com>
This commit is contained in:
tison
2024-01-09 15:04:23 +08:00
committed by GitHub
parent 225ae953d1
commit 0db1861452
3 changed files with 16 additions and 8 deletions

View File

@@ -25,12 +25,12 @@ use datatypes::vectors::{BooleanVector, Float64Vector, Int64Vector, VectorRef};
#[cfg(feature = "pyo3_backend")]
use pyo3::{types::PyDict, Python};
use rustpython_compiler::Mode;
use rustpython_vm::class::PyClassImpl;
use rustpython_vm::{vm, AsObject};
use rustpython_vm::AsObject;
use crate::python::ffi_types::PyVector;
#[cfg(feature = "pyo3_backend")]
use crate::python::pyo3::{init_cpython_interpreter, vector_impl::into_pyo3_cell};
use crate::python::rspython::init_interpreter;
#[derive(Debug, Clone)]
struct TestCase {
@@ -155,10 +155,7 @@ fn eval_pyo3(testcase: TestCase, locals: HashMap<String, PyVector>) {
}
fn eval_rspy(testcase: TestCase, locals: HashMap<String, PyVector>) {
vm::Interpreter::with_init(Default::default(), |vm| {
let _ = PyVector::make_class(&vm.ctx);
})
.enter(|vm| {
init_interpreter().enter(|vm| {
let scope = vm.new_scope_with_builtins();
locals.into_iter().for_each(|(k, v)| {
scope

View File

@@ -45,8 +45,12 @@ pub(crate) fn init_cpython_interpreter() -> PyResult<()> {
if !*start {
pyo3::append_to_inittab!(greptime_builtins);
pyo3::prepare_freethreaded_python();
let version = Python::with_gil(|py| -> PyResult<String> {
let builtins = PyModule::import(py, "sys")?;
builtins.getattr("version")?.extract()
})?;
*start = true;
info!("Started CPython Interpreter");
info!("Started CPython Interpreter {version}");
}
Ok(())
}

View File

@@ -221,7 +221,14 @@ pub(crate) fn init_interpreter() -> Rc<Interpreter> {
init_greptime_builtins("greptime", vm);
init_data_frame("data_frame", vm);
}));
info!("Initialized Python interpreter.");
interpreter
.enter(|vm| {
let sys = vm.sys_module.clone();
let version = sys.get_attr("version", vm)?.str(vm)?;
info!("Initialized RustPython interpreter {version}");
Ok::<(), PyBaseExceptionRef>(())
})
.expect("fail to display RustPython interpreter version");
interpreter
})
.clone()