Skip to content

Commit

Permalink
refactor: Small follow up improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian committed Dec 4, 2024
1 parent 18279f7 commit 4d6eb5c
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions crates/pixi-build/src/bin/pixi-build-python/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,38 +406,37 @@ fn input_globs() -> Vec<String> {

/// Returns the entry points from pyproject.toml scripts table
fn get_entry_points(toml_document: &TomlDocument) -> miette::Result<Option<Vec<EntryPoint>>> {
let scripts = toml_document.get_nested_table("project.scripts").ok();
let Ok(scripts) = toml_document.get_nested_table("project.scripts") else {
return Ok(None);
};

// all the entry points are in the form of a table
if let Some(scripts) = scripts {
let entry_points = scripts
.get_values()
.iter()
.map(|(k, v)| {
// Ensure the key vector has exactly one element
let key = k
.first()
.ok_or_else(|| miette::miette!("entry points should have a key"))?;

if k.len() > 1 {
return Err(miette::miette!("entry points should be a single key"));
}
let entry_points = scripts
.get_values()
.iter()
.map(|(k, v)| {
// Ensure the key vector has exactly one element
let key = k
.first()
.ok_or_else(|| miette::miette!("entry points should have a key"))?;

if k.len() > 1 {
return Err(miette::miette!("entry points should be a single key"));
}

let value = v
.as_str()
.ok_or_else(|| miette::miette!("entry point value {v} should be a string"))?;
let value = v
.as_str()
.ok_or_else(|| miette::miette!("entry point value {v} should be a string"))?;

// format it as a script = some_module:some_function
let entry_point_str = format!("{} = {}", key, value);
EntryPoint::from_str(&entry_point_str).map_err(|e| {
miette::miette!("failed to parse entry point {}: {}", entry_point_str, e)
})
// format it as a script = some_module:some_function
let entry_point_str = format!("{} = {}", key, value);
EntryPoint::from_str(&entry_point_str).map_err(|e| {
miette::miette!("failed to parse entry point {}: {}", entry_point_str, e)
})
.collect::<Result<Vec<_>, _>>()?;

return Ok(Some(entry_points));
}
})
.collect::<Result<Vec<_>, _>>()?;

Ok(None)
Ok(Some(entry_points))
}

#[async_trait::async_trait]
Expand Down

0 comments on commit 4d6eb5c

Please sign in to comment.