Skip to content

Commit 4925c8a

Browse files
committed
feat(cli): add unified generate-metadata command
Signed-off-by: pyranota <pyra@duck.com>
1 parent 7a59e2b commit 4925c8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+6915
-187
lines changed

backend/.sqlx/query-25ac66a1022c41267df199a95f532b0f778c25fbe0f7a7f9734c1f7e536ed6ce.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.sqlx/query-2d523cd0d5b7107b15846b885fa40af492d4c8a8871cef972980150f319fe6ff.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.sqlx/query-c7cae4cf872fce0a989cf89aa35929218a9d459ee1c2b36a28b110e9741ab623.json renamed to backend/.sqlx/query-7d0d624400a15170622eb573d86b2a5488ab669121771eca4cc09cd156318adf.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.sqlx/query-88ec0ddcc86fb67089b551ccbce7b932800e33cd462a651f7e6716929ee9b6f2.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/Cargo.lock

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE IF EXISTS raw_script_temp;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Temporary storage for raw script content during CLI lock generation
2+
-- Content is stored with hash as key, cleaned up after 1 week
3+
CREATE TABLE raw_script_temp (
4+
workspace_id VARCHAR(50) NOT NULL REFERENCES workspace(id),
5+
hash CHAR(64) NOT NULL,
6+
content TEXT NOT NULL,
7+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
8+
PRIMARY KEY (workspace_id, hash)
9+
);

backend/parsers/windmill-parser-py-imports/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ regex.workspace = true
1616

1717
[dependencies]
1818
windmill-parser.workspace = true
19+
windmill-parser-py.workspace = true
1920
windmill-common.workspace = true
2021
rustpython-parser.workspace = true
2122
malachite.workspace = true

backend/parsers/windmill-parser-py-imports/src/lib.rs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,8 @@ fn process_import(module: Option<String>, path: &str, level: usize) -> Vec<NImpo
8282
}
8383
}
8484

85-
pub fn parse_relative_imports(code: &str, path: &str) -> error::Result<Vec<String>> {
86-
let nimports = parse_code_for_imports(code, path)?;
87-
return Ok(nimports
88-
.into_iter()
89-
.filter_map(|x| match x {
90-
NImport::Relative(path) => Some(path),
91-
_ => None,
92-
})
93-
.collect());
94-
}
85+
// Re-export from windmill-parser-py for WASM compatibility
86+
pub use windmill_parser_py::parse_relative_imports;
9587

9688
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
9789
enum NImport {
@@ -264,6 +256,7 @@ pub async fn parse_python_imports(
264256
version_specifiers: &mut Vec<pep440_rs::VersionSpecifier>,
265257
locked_v: &mut Option<pep440_rs::Version>,
266258
raw_workspace_dependencies_o: &Option<RawWorkspaceDependencies>,
259+
dependency_tree: &Option<HashMap<String, String>>,
267260
) -> error::Result<(Vec<String>, Option<String>)> {
268261
let mut compile_error_hint: Option<String> = None;
269262
let mut imports = parse_python_imports_inner(
@@ -276,6 +269,7 @@ pub async fn parse_python_imports(
276269
&mut None,
277270
locked_v,
278271
raw_workspace_dependencies_o,
272+
dependency_tree,
279273
)
280274
.await?
281275
.into_values()
@@ -331,6 +325,7 @@ async fn parse_python_imports_inner(
331325
path_where_annotated_pyv: &mut Option<String>,
332326
locked_v: &mut Option<pep440_rs::Version>,
333327
raw_workspace_dependencies_o: &Option<RawWorkspaceDependencies>,
328+
dependency_tree: &Option<HashMap<String, String>>,
334329
) -> error::Result<HashMap<String, NImportResolved>> {
335330
tracing::debug!("Parsing python imports for path: {}", path);
336331
let PythonAnnotations { py310, py311, py312, py313, .. } = PythonAnnotations::parse(&code);
@@ -494,17 +489,31 @@ async fn parse_python_imports_inner(
494489
for n in nimports.into_iter() {
495490
let mut nested = match n {
496491
NImport::Relative(rpath) => {
497-
let code = sqlx::query_scalar!(
498-
r#"
499-
SELECT content FROM script WHERE path = $1 AND workspace_id = $2
500-
AND archived = false ORDER BY created_at DESC LIMIT 1
501-
"#,
502-
&rpath,
503-
w_id
504-
)
505-
.fetch_optional(db)
506-
.await?
507-
.unwrap_or_else(|| "".to_string());
492+
// First check if the path is in dependency_tree (local/modified scripts from CLI)
493+
let code = if let Some(hash) = dependency_tree.as_ref().and_then(|dt| dt.get(&rpath)) {
494+
tracing::debug!("Found relative import '{}' in dependency_tree with hash '{}'", rpath, hash);
495+
// Fetch from raw_script_temp using the cache abstraction
496+
match windmill_common::cache::raw_script_temp::load(hash.clone(), db).await {
497+
Ok(content) => content,
498+
Err(e) => {
499+
tracing::warn!("dependency_tree hash '{}' not found in cache: {}, falling back to deployed script", hash, e);
500+
"".to_string()
501+
}
502+
}
503+
} else {
504+
// Fall back to deployed script from script table
505+
sqlx::query_scalar!(
506+
r#"
507+
SELECT content FROM script WHERE path = $1 AND workspace_id = $2
508+
AND archived = false ORDER BY created_at DESC LIMIT 1
509+
"#,
510+
&rpath,
511+
w_id
512+
)
513+
.fetch_optional(db)
514+
.await?
515+
.unwrap_or_else(|| "".to_string())
516+
};
508517

509518
if already_visited.contains(&rpath) {
510519
vec![]
@@ -522,6 +531,7 @@ async fn parse_python_imports_inner(
522531
path_where_annotated_pyv,
523532
locked_v,
524533
raw_workspace_dependencies_o,
534+
dependency_tree,
525535
)
526536
.await?
527537
.into_values()

backend/parsers/windmill-parser-py-imports/tests/tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def main():
2626
&mut vec![],
2727
&mut None,
2828
&None,
29+
&None,
2930
)
3031
.await?;
3132
// println!("{}", serde_json::to_string(&r)?);
@@ -67,6 +68,7 @@ def main():
6768
&mut vec![],
6869
&mut None,
6970
&None,
71+
&None,
7072
)
7173
.await?;
7274
println!("{}", serde_json::to_string(&r)?);
@@ -98,6 +100,7 @@ def main():
98100
&mut vec![],
99101
&mut None,
100102
&None,
103+
&None,
101104
)
102105
.await?;
103106
println!("{}", serde_json::to_string(&r)?);

0 commit comments

Comments
 (0)