mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 23:27:56 -05:00
wallet: deprecate pyo2, replace with rustpython
This commit is contained in:
@@ -21,11 +21,7 @@ thiserror = "1.0.57"
|
||||
smol = "1.3.0"
|
||||
atomic_float = "0.1.0"
|
||||
|
||||
starlark = "0.12.0"
|
||||
|
||||
[dependencies.pyo3]
|
||||
version = "0.21.2"
|
||||
features = ["auto-initialize"]
|
||||
rustpython-vm = "0.3.1"
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
android_logger = "0.13"
|
||||
|
||||
@@ -302,7 +302,8 @@ def draw():
|
||||
code = [["as_u32", ["/", ["load", "sw"], ["u32", 2]]]]
|
||||
api.set_property_expr(layer_id, "rect", 2, code)
|
||||
# h
|
||||
api.set_property_u32(layer_id, "rect", 3, int(2158/2))
|
||||
code = [["as_u32", ["/", ["load", "sh"], ["u32", 2]]]]
|
||||
api.set_property_expr(layer_id, "rect", 3, code)
|
||||
|
||||
api.link_node(layer_id, win_id)
|
||||
|
||||
@@ -351,7 +352,7 @@ def draw():
|
||||
# h
|
||||
#api.set_property_str(mesh_id, "rect", 3, "lh - 10")
|
||||
code = [["-", ["load", "lh"], ["f32", 10]]]
|
||||
api.set_property_f32(mesh_id, "rect", 3, 20)
|
||||
api.set_property_expr(mesh_id, "rect", 3, code)
|
||||
|
||||
api.link_node(mesh_id, layer_id)
|
||||
|
||||
|
||||
@@ -4,12 +4,6 @@ use fontdue::{
|
||||
Font, FontSettings,
|
||||
};
|
||||
use miniquad::*;
|
||||
use pyo3::{
|
||||
prelude::*,
|
||||
py_run,
|
||||
types::{IntoPyDict, PyDict},
|
||||
PyClass,
|
||||
};
|
||||
use std::{
|
||||
array::IntoIter,
|
||||
fmt,
|
||||
@@ -827,30 +821,6 @@ impl<'a> RenderContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn eval_py_str<'py>(code: &str, locals: Py<PyDict>) -> PyResult<f32> {
|
||||
Python::with_gil(|py| {
|
||||
let null = ();
|
||||
// https://stackoverflow.com/questions/35804961/python-eval-is-it-still-dangerous-if-i-disable-builtins-and-attribute-access
|
||||
// See safe_eval() by tardyp and astrun
|
||||
// We don't care about resource usage, just accessing system resources.
|
||||
// Can also use restrictedpython lib to eval the code.
|
||||
// Also PyPy sandboxing
|
||||
// and starlark / starlark-rust
|
||||
py_run!(
|
||||
py,
|
||||
null,
|
||||
r#"
|
||||
__builtins__.__dict__['__import__'] = None
|
||||
__builtins__.__dict__['open'] = None
|
||||
"#
|
||||
);
|
||||
|
||||
let locals = locals.bind(py);
|
||||
let result: f32 = py.eval_bound(code, None, Some(locals))?.extract()?;
|
||||
Ok(result)
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
fn get_obj_props(obj: &SceneNode) -> Result<(f32, f32, f32, f32, bool)> {
|
||||
let x = obj.get_property_f32("x")?;
|
||||
|
||||
@@ -37,36 +37,42 @@ fn init_zmq(scene_graph: SceneGraphPtr) {
|
||||
|
||||
fn main() {
|
||||
let scene_graph = Arc::new(Mutex::new(SceneGraph::new()));
|
||||
//init_zmq(scene_graph.clone());
|
||||
init_zmq(scene_graph.clone());
|
||||
run_gui(scene_graph);
|
||||
}
|
||||
|
||||
/*
|
||||
use pyo3::{prelude::*, types::{PyDict, IntoPyDict}, py_run};
|
||||
use rustpython_vm::{self as pyvm, convert::ToPyObject};
|
||||
|
||||
fn main() -> PyResult<()> {
|
||||
Python::with_gil(|py| {
|
||||
let null = ();
|
||||
// https://stackoverflow.com/questions/35804961/python-eval-is-it-still-dangerous-if-i-disable-builtins-and-attribute-access
|
||||
// See safe_eval() by tardyp and astrun
|
||||
// We don't care about resource usage, just accessing system resources.
|
||||
// Can also use restrictedpython lib to eval the code.
|
||||
// Also PyPy sandboxing
|
||||
// and starlark / starlark-rust
|
||||
py_run!(py, null, r#"
|
||||
__builtins__.__dict__['__import__'] = None
|
||||
__builtins__.__dict__['open'] = None
|
||||
"#);
|
||||
fn main() {
|
||||
let code_obj = pyvm::Interpreter::without_stdlib(Default::default()).enter(|vm| {
|
||||
let source = r#"
|
||||
max(1 + lw/3, 4*10) + foo(2, True)"#;
|
||||
let code_obj = vm
|
||||
.compile(source, pyvm::compiler::Mode::Eval, "<embedded>".to_owned())
|
||||
.map_err(|err| vm.new_syntax_error(&err, Some(source))).unwrap();
|
||||
code_obj
|
||||
});
|
||||
|
||||
let locals = PyDict::new_bound(py);
|
||||
locals.set_item("lw", 110)?;
|
||||
locals.set_item("lh", 4)?;
|
||||
fn foo(x: u32, y: bool) -> u32 {
|
||||
if y {
|
||||
2 * x
|
||||
} else {
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
let code = "min(1 + lw/3, 4*10)";
|
||||
let user: f32 = py.eval_bound(code, None, Some(&locals))?.extract()?;
|
||||
let res = pyvm::Interpreter::without_stdlib(Default::default()).enter(|vm| {
|
||||
let globals = vm.ctx.new_dict();
|
||||
globals.set_item("lw", vm.ctx.new_int(110).to_pyobject(vm), vm).unwrap();
|
||||
globals.set_item("lh", vm.ctx.new_int(4).to_pyobject(vm), vm).unwrap();
|
||||
globals.set_item("foo", vm.new_function("foo", foo).into(), vm).unwrap();
|
||||
|
||||
println!("{}", user);
|
||||
Ok(())
|
||||
})
|
||||
let scope = pyvm::scope::Scope::new(None, globals);
|
||||
|
||||
vm.run_code_obj(code_obj, scope).unwrap()
|
||||
});
|
||||
println!("{:?}", res);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user