Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ tracing = "0.1"
serial_test = "3"

# Python bindings
pyo3 = { version = "0.24.2", features = ["extension-module", "generate-import-lib"] }
pyo3-async-runtimes = { version = "0.24", features = ["tokio-runtime"] }
pyo3 = { version = "0.28.2", features = ["extension-module", "generate-import-lib"] }
pyo3-async-runtimes = { version = "0.28", features = ["tokio-runtime"] }
30 changes: 15 additions & 15 deletions crates/bashkit-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use tokio::sync::Mutex;
// JSON <-> Python helpers
// ============================================================================

/// Convert serde_json::Value → PyObject
fn json_to_py(py: Python<'_>, val: &serde_json::Value) -> PyResult<PyObject> {
/// Convert serde_json::Value → Py<PyAny>
fn json_to_py(py: Python<'_>, val: &serde_json::Value) -> PyResult<Py<PyAny>> {
match val {
serde_json::Value::Null => Ok(py.None()),
serde_json::Value::Bool(b) => Ok(b.into_pyobject(py)?.to_owned().into_any().unbind()),
Expand All @@ -37,7 +37,7 @@ fn json_to_py(py: Python<'_>, val: &serde_json::Value) -> PyResult<PyObject> {
}
serde_json::Value::String(s) => Ok(s.into_pyobject(py)?.into_any().unbind()),
serde_json::Value::Array(arr) => {
let items: Vec<PyObject> = arr
let items: Vec<Py<PyAny>> = arr
.iter()
.map(|v| json_to_py(py, v))
.collect::<PyResult<_>>()?;
Expand All @@ -53,7 +53,7 @@ fn json_to_py(py: Python<'_>, val: &serde_json::Value) -> PyResult<PyObject> {
}
}

/// Convert PyObject → serde_json::Value (for schema dicts)
/// Convert Py<PyAny> → serde_json::Value (for schema dicts)
#[allow(clippy::only_used_in_recursion)]
fn py_to_json(py: Python<'_>, obj: &Bound<'_, pyo3::PyAny>) -> PyResult<serde_json::Value> {
if obj.is_none() {
Expand All @@ -71,14 +71,14 @@ fn py_to_json(py: Python<'_>, obj: &Bound<'_, pyo3::PyAny>) -> PyResult<serde_js
if let Ok(s) = obj.extract::<String>() {
return Ok(serde_json::Value::String(s));
}
if let Ok(list) = obj.downcast::<PyList>() {
if let Ok(list) = obj.cast::<PyList>() {
let arr: Vec<serde_json::Value> = list
.iter()
.map(|item| py_to_json(py, &item))
.collect::<PyResult<_>>()?;
return Ok(serde_json::Value::Array(arr));
}
if let Ok(dict) = obj.downcast::<PyDict>() {
if let Ok(dict) = obj.cast::<PyDict>() {
let mut map = serde_json::Map::new();
for (k, v) in dict.iter() {
let key: String = k.extract()?;
Expand All @@ -96,7 +96,7 @@ fn py_to_json(py: Python<'_>, obj: &Bound<'_, pyo3::PyAny>) -> PyResult<serde_js
// ============================================================================

/// Result from executing bash commands
#[pyclass]
#[pyclass(from_py_object)]
#[derive(Clone)]
pub struct ExecResult {
#[pyo3(get)]
Expand Down Expand Up @@ -134,7 +134,7 @@ impl ExecResult {

/// Return output as dict
fn to_dict(&self) -> pyo3::PyResult<pyo3::Py<PyDict>> {
Python::with_gil(|py| {
Python::attach(|py| {
let dict = PyDict::new(py);
dict.set_item("stdout", &self.stdout)?;
dict.set_item("stderr", &self.stderr)?;
Expand Down Expand Up @@ -332,7 +332,7 @@ struct PyToolEntry {
name: String,
description: String,
schema: serde_json::Value,
callback: PyObject,
callback: Py<PyAny>,
}

/// Compose Python callbacks as bash builtins for multi-tool orchestration.
Expand Down Expand Up @@ -370,7 +370,7 @@ pub struct ScriptedTool {

impl ScriptedTool {
/// Build a Rust ScriptedTool from stored Python config.
/// Each Python callback is wrapped via `Python::with_gil`.
/// Each Python callback is wrapped via `Python::attach`.
fn build_rust_tool(&self) -> RustScriptedTool {
let mut builder = RustScriptedTool::builder(&self.name);

Expand All @@ -379,12 +379,12 @@ impl ScriptedTool {
}

for entry in &self.tools {
let py_cb = Python::with_gil(|py| entry.callback.clone_ref(py));
let py_cb = Python::attach(|py| entry.callback.clone_ref(py));
let tool_name = entry.name.clone();

let callback = move |args: &ToolArgs| -> Result<String, String> {
Python::with_gil(|py| {
let params = json_to_py(py, &args.params).map_err(|e| e.to_string())?;
Python::attach(|py| {
let params = json_to_py(py, &args.params).map_err(|e: PyErr| e.to_string())?;
let stdin_arg = args.stdin.as_deref().map(|s| s.to_string());

let result = py_cb
Expand Down Expand Up @@ -466,7 +466,7 @@ impl ScriptedTool {
py: Python<'_>,
name: String,
description: String,
callback: PyObject,
callback: Py<PyAny>,
schema: Option<Bound<'_, pyo3::PyAny>>,
) -> PyResult<()> {
let schema_val = match schema {
Expand Down Expand Up @@ -590,7 +590,7 @@ impl ScriptedTool {
fn create_langchain_tool_spec() -> PyResult<pyo3::Py<PyDict>> {
let tool = RustBashTool::default();

Python::with_gil(|py| {
Python::attach(|py| {
let dict = PyDict::new(py);
dict.set_item("name", tool.name())?;
dict.set_item("description", tool.description())?;
Expand Down
26 changes: 5 additions & 21 deletions supply-chain/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,6 @@ criteria = "safe-to-deploy"
version = "2.13.0"
criteria = "safe-to-deploy"

[[exemptions.indoc]]
version = "2.0.7"
criteria = "safe-to-deploy"

[[exemptions.insta]]
version = "1.46.3"
criteria = "safe-to-run"
Expand Down Expand Up @@ -666,10 +662,6 @@ criteria = "safe-to-deploy"
version = "2.8.0"
criteria = "safe-to-deploy"

[[exemptions.memoffset]]
version = "0.9.1"
criteria = "safe-to-deploy"

[[exemptions.mime]]
version = "0.3.17"
criteria = "safe-to-deploy"
Expand Down Expand Up @@ -831,31 +823,27 @@ version = "1.10.0"
criteria = "safe-to-run"

[[exemptions.pyo3]]
version = "0.24.2"
version = "0.28.2"
criteria = "safe-to-deploy"

[[exemptions.pyo3-async-runtimes]]
version = "0.24.0"
criteria = "safe-to-deploy"

[[exemptions.pyo3-build-config]]
version = "0.24.2"
version = "0.28.0"
criteria = "safe-to-deploy"

[[exemptions.pyo3-build-config]]
version = "0.28.2"
criteria = "safe-to-deploy"

[[exemptions.pyo3-ffi]]
version = "0.24.2"
version = "0.28.2"
criteria = "safe-to-deploy"

[[exemptions.pyo3-macros]]
version = "0.24.2"
version = "0.28.2"
criteria = "safe-to-deploy"

[[exemptions.pyo3-macros-backend]]
version = "0.24.2"
version = "0.28.2"
criteria = "safe-to-deploy"

[[exemptions.python3-dll-a]]
Expand Down Expand Up @@ -1334,10 +1322,6 @@ criteria = "safe-to-deploy"
version = "1.3.0"
criteria = "safe-to-deploy"

[[exemptions.unindent]]
version = "0.2.4"
criteria = "safe-to-deploy"

[[exemptions.untrusted]]
version = "0.9.0"
criteria = "safe-to-deploy"
Expand Down
Loading