feat(python): per import requirement pin (#5520)

* implement single line pin

* make panic-safe

* use pin even if multiple modules imported withing single statement

* add repins and make imports respect pins

* keep all pins

* Allow multiple pins

* add comments + handle stuff more safely

* fix fully qualified imports

* remove ignore

* sort nested

* apply unique to output requirements list

* fix typo

* remove mut

* update sqlx

* sort imports

* sort imports

* fix formatter and format

* refactor

* fix comptime error

* write tests

* perf: do not capture if string is empty
This commit is contained in:
pyranota
2025-04-11 23:31:51 +02:00
committed by GitHub
parent d5186da271
commit 0b6d017fed
8 changed files with 638 additions and 117 deletions

View File

@@ -1439,6 +1439,7 @@ async fn handle_python_deps(
.clone();
let mut requirements;
let compilation_error_hint;
let mut annotated_pyv = None;
let mut annotated_pyv_numeric = None;
let is_deployed = requirements_o.is_some();
@@ -1449,23 +1450,26 @@ async fn handle_python_deps(
None => {
let mut already_visited = vec![];
requirements = match conn {
Connection::Sql(db) => windmill_parser_py_imports::parse_python_imports(
inner_content,
w_id,
script_path,
db,
&mut already_visited,
&mut annotated_pyv_numeric,
)
.await?
.join("\n"),
(requirements, compilation_error_hint) = match conn {
Connection::Sql(db) => {
let (r, h) = windmill_parser_py_imports::parse_python_imports(
inner_content,
w_id,
script_path,
db,
&mut already_visited,
&mut annotated_pyv_numeric,
)
.await?;
(r.join("\n"), h)
}
Connection::Http(_) => match precomputed_agent_info {
Some(PrecomputedAgentInfo::Python { py_version, requirements }) => {
annotated_pyv_numeric = py_version;
requirements.clone().unwrap_or_else(|| "".to_string())
(requirements.clone().unwrap_or_else(|| "".to_string()), None)
}
_ => "".to_string(),
_ => ("".to_string(), None),
},
};
@@ -1487,7 +1491,11 @@ async fn handle_python_deps(
)
.await
.map_err(|e| {
Error::ExecutionErr(format!("pip compile failed: {}", e.to_string()))
Error::ExecutionErr(format!(
"pip compile failed: {}{}",
e.to_string(),
compilation_error_hint.unwrap_or_default()
))
})?;
}
&requirements