mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-24 00:00:46 +00:00
fix python relative imports in diff folders
This commit is contained in:
@@ -145,19 +145,20 @@ pub async fn parse_python_imports(
|
||||
.collect();
|
||||
for n in nimports.iter() {
|
||||
let nested = if n.starts_with("relative:") {
|
||||
let rpath = n.replace("relative:", "");
|
||||
let code = sqlx::query_scalar!(
|
||||
r#"
|
||||
SELECT content FROM script WHERE path = $1 AND workspace_id = $2
|
||||
AND created_at = (SELECT max(created_at) FROM script WHERE path = $1 AND
|
||||
workspace_id = $2)
|
||||
"#,
|
||||
n.replace("relative:", ""),
|
||||
&rpath,
|
||||
w_id
|
||||
)
|
||||
.fetch_optional(db)
|
||||
.await?
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
parse_python_imports(&code, w_id, path, db).await?
|
||||
parse_python_imports(&code, w_id, &rpath, db).await?
|
||||
} else {
|
||||
vec![replace_import(n.to_string())]
|
||||
};
|
||||
|
||||
@@ -2556,4 +2556,27 @@ import numpy as np
|
||||
'{}',
|
||||
'',
|
||||
'',
|
||||
'f/foo/baz', -28028598712388161, 'python3', '');
|
||||
'f/foo/baz', -28028598712388161, 'python3', '');
|
||||
|
||||
INSERT INTO public.script(workspace_id, created_by, content, schema, summary, description, path, hash, language, lock) VALUES (
|
||||
'test-workspace',
|
||||
'system',
|
||||
'
|
||||
import difffolder
|
||||
from .bar import main
|
||||
',
|
||||
'{}',
|
||||
'',
|
||||
'',
|
||||
'f/foobar/baz', -28028598712388160, 'python3', '');
|
||||
|
||||
INSERT INTO public.script(workspace_id, created_by, content, schema, summary, description, path, hash, language, lock) VALUES (
|
||||
'test-workspace',
|
||||
'system',
|
||||
'
|
||||
import innerdifffolder
|
||||
',
|
||||
'{}',
|
||||
'',
|
||||
'',
|
||||
'f/foobar/bar', -28028598712388159, 'python3', '');
|
||||
@@ -57,7 +57,7 @@ from f.foo.bar import main1
|
||||
from .baz import main2
|
||||
from ..foo.bar import main3
|
||||
import f.foo.bar as bar
|
||||
|
||||
from ..foobar.baz import main4
|
||||
|
||||
def main():
|
||||
pass
|
||||
@@ -65,7 +65,17 @@ def main():
|
||||
";
|
||||
let r = parse_python_imports(code, "test-workspace", "f/foo/bar", &db).await?;
|
||||
println!("{}", serde_json::to_string(&r)?);
|
||||
assert_eq!(r, ["numpy", "pandas", "pandas2", "requests"]);
|
||||
assert_eq!(
|
||||
r,
|
||||
[
|
||||
"difffolder",
|
||||
"innerdifffolder",
|
||||
"numpy",
|
||||
"pandas",
|
||||
"pandas2",
|
||||
"requests"
|
||||
]
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user