Skip to content

Commit 04a58b9

Browse files
authored
Merge pull request #2456 from fermyon/tmpl-extension
Allow template to have tmpl extension
2 parents 2efad6a + 07e365c commit 04a58b9

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

crates/templates/src/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ mod tests {
746746
);
747747

748748
let content_dir = template.content_dir().as_ref().unwrap();
749-
let cargo = tokio::fs::read_to_string(content_dir.join("Cargo.toml"))
749+
let cargo = tokio::fs::read_to_string(content_dir.join("Cargo.toml.tmpl"))
750750
.await
751751
.unwrap();
752752
assert!(cargo.contains("name = \"{{project-name | kebab_case}}\""));

crates/templates/src/run.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,18 @@ impl Run {
344344
let template_parser = Self::template_parser();
345345
let contents = paths
346346
.iter()
347-
.map(std::fs::read)
348-
.map(|c| {
349-
c.map_err(|e| e.into())
350-
.and_then(|cc| TemplateContent::infer_from_bytes(cc, &template_parser))
351-
})
347+
.map(|path| TemplateContent::infer_from_bytes(std::fs::read(path)?, &template_parser))
352348
.collect::<Result<Vec<_>, _>>()?;
353-
let pairs = paths.into_iter().zip(contents).collect();
349+
// Strip optional .tmpl extension
350+
// Templates can use this if they don't want to store files with their final extensions
351+
let paths = paths.into_iter().map(|p| {
352+
if p.extension().is_some_and(|e| e == "tmpl") {
353+
p.with_extension("")
354+
} else {
355+
p
356+
}
357+
});
358+
let pairs = paths.zip(contents).collect();
354359
Ok(pairs)
355360
}
356361

tests/integration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ Caused by:
485485

486486
#[test]
487487
#[cfg(feature = "extern-dependencies-tests")]
488+
#[ignore = "https://github.com/fermyon/spin/issues/2457"]
488489
// TODO: Check why python is not picking up the spin_sdk from site_packages
489490
// Currently installing to the local directory to get around it.
490491
fn http_python_template_smoke_test() -> anyhow::Result<()> {

0 commit comments

Comments
 (0)