Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyO3: migrate to Bound smart pointer for src/rust/engine/src/externs/engine_aware.rs #21470

Merged
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
18 changes: 9 additions & 9 deletions src/rust/engine/src/externs/engine_aware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use workunit_store::{ArtifactOutput, Level, RunningWorkunit, UserMetadataItem, W
pub(crate) struct EngineAwareReturnType;

impl EngineAwareReturnType {
pub(crate) fn update_workunit(workunit: &mut RunningWorkunit, task_result: &PyAny) {
pub(crate) fn update_workunit(workunit: &mut RunningWorkunit, task_result: &Bound<'_, PyAny>) {
workunit.update_metadata(|old| {
let new_level = Self::level(task_result);

Expand All @@ -45,23 +45,23 @@ impl EngineAwareReturnType {
});
}

fn level(obj: &PyAny) -> Option<Level> {
fn level(obj: &Bound<'_, PyAny>) -> Option<Level> {
let level_val = obj.call_method0("level").ok()?;
if level_val.is_none() {
return None;
}
externs::val_to_log_level(level_val).ok()
externs::val_to_log_level(level_val.as_gil_ref()).ok()
}

fn message(obj: &PyAny) -> Option<String> {
fn message(obj: &Bound<'_, PyAny>) -> Option<String> {
let msg_val = obj.call_method0("message").ok()?;
if msg_val.is_none() {
return None;
}
msg_val.extract().ok()
}

fn artifacts(obj: &PyAny) -> Option<Vec<(String, ArtifactOutput)>> {
fn artifacts(obj: &Bound<'_, PyAny>) -> Option<Vec<(String, ArtifactOutput)>> {
let artifacts_val = obj.call_method0("artifacts").ok()?;
if artifacts_val.is_none() {
return None;
Expand All @@ -84,28 +84,28 @@ impl EngineAwareReturnType {
Some(output)
}

pub(crate) fn is_cacheable(obj: &PyAny) -> Option<bool> {
pub(crate) fn is_cacheable(obj: &Bound<'_, PyAny>) -> Option<bool> {
obj.call_method0("cacheable").ok()?.extract().ok()
}
}

pub struct EngineAwareParameter;

impl EngineAwareParameter {
pub fn debug_hint(obj: &PyAny) -> Option<String> {
pub fn debug_hint(obj: &Bound<'_, PyAny>) -> Option<String> {
let hint = obj.call_method0("debug_hint").ok()?;
if hint.is_none() {
return None;
}
hint.extract().ok()
}

pub fn metadata(obj: &PyAny) -> Vec<(String, UserMetadataItem)> {
pub fn metadata(obj: &Bound<'_, PyAny>) -> Vec<(String, UserMetadataItem)> {
metadata_for(obj).unwrap_or_default()
}
}

fn metadata_for(obj: &PyAny) -> Option<Vec<(String, UserMetadataItem)>> {
fn metadata_for(obj: &Bound<'_, PyAny>) -> Option<Vec<(String, UserMetadataItem)>> {
let metadata_val = obj.call_method0("metadata").ok()?;
if metadata_val.is_none() {
return None;
Expand Down
8 changes: 4 additions & 4 deletions src/rust/engine/src/nodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl NodeKey {

let displayable_param_names: Vec<_> = Python::with_gil(|py| {
Self::engine_aware_params(context, py, &task.params)
.filter_map(|k| EngineAwareParameter::debug_hint((*k.value).as_ref(py)))
.filter_map(|k| EngineAwareParameter::debug_hint((*k.value).bind(py)))
.collect()
});

Expand Down Expand Up @@ -502,7 +502,7 @@ impl Node for NodeKey {
if let Some(params) = maybe_params {
Python::with_gil(|py| {
Self::engine_aware_params(&context, py, params)
.flat_map(|k| EngineAwareParameter::metadata((*k.value).as_ref(py)))
.flat_map(|k| EngineAwareParameter::metadata((*k.value).bind(py)))
.collect()
})
} else {
Expand Down Expand Up @@ -601,7 +601,7 @@ impl Node for NodeKey {
}
(NodeKey::Task(ref t), NodeOutput::Value(ref v)) if t.task.engine_aware_return_type => {
Python::with_gil(|py| {
EngineAwareReturnType::is_cacheable((**v).as_ref(py)).unwrap_or(true)
EngineAwareReturnType::is_cacheable((**v).bind(py)).unwrap_or(true)
})
}
_ => true,
Expand Down Expand Up @@ -652,7 +652,7 @@ impl Display for NodeKey {
.keys()
.filter_map(|k| {
EngineAwareParameter::debug_hint(
k.to_value().clone_ref(py).into_ref(py),
k.to_value().clone_ref(py).bind(py),
)
})
.collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/src/nodes/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl Task {

if self.task.engine_aware_return_type {
Python::with_gil(|py| {
EngineAwareReturnType::update_workunit(workunit, (*result_val).as_ref(py))
EngineAwareReturnType::update_workunit(workunit, (*result_val).bind(py))
})
};

Expand Down
Loading