Skip to content

Commit

Permalink
check if the file is python
Browse files Browse the repository at this point in the history
  • Loading branch information
j03-dev committed Dec 25, 2024
1 parent 8f9fc5f commit 0ce2079
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
8 changes: 2 additions & 6 deletions src/typegate/engine/src/py_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ fn read_file(path: &str) -> Result<String> {

#[deno_core::op2(fast)]
pub fn op_validate(#[string] input: String) -> Result<()> {
if let Some(file_name) = input.split(".").last() {
if file_name == "py" {
let python_source = read_file(&input)?;
ast::Suite::parse(&python_source, "<embedded>")?;
}
}
let python_source = read_file(&input)?;
ast::Suite::parse(&python_source, "<embedded>")?;
Ok(())
}
38 changes: 20 additions & 18 deletions src/typegate/src/runtimes/python/hooks/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,28 @@ export const codeValidations: PushHandler = async (
depMetas,
);

try {
logger.info(
`Validating Python code at entry point: ${entryPoint.path}`,
);
Meta.py_validation.validate(entryModulePath);
if (entryModulePath.split(".").slice(-1)[0] == "py") {
try {
logger.info(
`Validating Python code at entry point: ${entryPoint.path}`,
);
Meta.py_validation.validate(entryModulePath);

for (const dep of depMetas) {
const depPath = await artifactStore.getLocalPath(dep);
logger.info(`Validating Python code for dependency: ${depPath}`);
Meta.py_validation.validate(depPath);
}
for (const dep of depMetas) {
const depPath = await artifactStore.getLocalPath(dep);
logger.info(`Validating Python code for dependency: ${depPath}`);
Meta.py_validation.validate(depPath);
}

logger.info(
`Successfully validated Python code at entry point: ${entryPoint.path}`,
);
} catch (err) {
console.error({ err });
throw new ValidationFailure(
`Python code validation error at entry point '${entryPoint.path}': ${err.message}`,
);
logger.info(
`Successfully validated Python code at entry point: ${entryPoint.path}`,
);
} catch (err) {
console.error({ err });
throw new ValidationFailure(
`Python code validation error at entry point '${entryPoint.path}': ${err.message}`,
);
}
}
}
}
Expand Down

0 comments on commit 0ce2079

Please sign in to comment.