Skip to content

Commit

Permalink
fix: keep tempdir to make recipe rendering from stdin work again (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Jan 18, 2025
1 parent c9c7adc commit 858541c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["rust-tests"]

[package]
name = "rattler-build"
version = "0.35.3"
version = "0.35.4"
authors = ["rattler-build contributors <[email protected]>"]
repository = "https://github.com/prefix-dev/rattler-build"
edition = "2021"
Expand Down
4 changes: 2 additions & 2 deletions py-rattler-build/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion py-rattler-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "py-rattler-build"
version = "0.35.3"
version = "0.35.4"
edition = "2021"
license = "BSD-3-Clause"
publish = false
Expand Down
16 changes: 11 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rattler_build::{
opt::{App, BuildData, ShellCompletion, SubCommands},
rebuild_from_args, run_test_from_args, upload_from_args,
};
use tempfile::tempdir;
use tempfile::{tempdir, TempDir};

fn main() -> miette::Result<()> {
// Initialize sandbox in sync/single-threaded context before tokio runtime
Expand Down Expand Up @@ -73,7 +73,9 @@ async fn async_main() -> miette::Result<()> {
let recipes = build_args.recipe.clone();
let recipe_dir = build_args.recipe_dir.clone();
let build_data = BuildData::from(build_args);
let recipe_paths = recipe_paths(recipes, recipe_dir)?;

// Get all recipe paths and keep tempdir alive until end of the function
let (recipe_paths, _temp_dir) = recipe_paths(recipes, recipe_dir)?;

if recipe_paths.is_empty() {
miette::bail!("Couldn't detect any recipes.")
Expand Down Expand Up @@ -124,20 +126,23 @@ async fn async_main() -> miette::Result<()> {
fn recipe_paths(
recipes: Vec<std::path::PathBuf>,
recipe_dir: Option<std::path::PathBuf>,
) -> Result<Vec<std::path::PathBuf>, miette::Error> {
) -> Result<(Vec<std::path::PathBuf>, Option<TempDir>), miette::Error> {
let mut recipe_paths = Vec::new();
let temp_dir = tempdir().into_diagnostic()?;
let mut temp_dir_opt = None;
if !std::io::stdin().is_terminal()
&& recipes.len() == 1
&& get_recipe_path(&recipes[0]).is_err()
{
let temp_dir = tempdir().into_diagnostic()?;

let recipe_path = temp_dir.path().join("recipe.yaml");
io::copy(
&mut io::stdin(),
&mut File::create(&recipe_path).into_diagnostic()?,
)
.into_diagnostic()?;
recipe_paths.push(get_recipe_path(&recipe_path)?);
temp_dir_opt = Some(temp_dir);
} else {
for recipe_path in &recipes {
recipe_paths.push(get_recipe_path(recipe_path)?);
Expand All @@ -153,5 +158,6 @@ fn recipe_paths(
}
}
}
Ok(recipe_paths)

Ok((recipe_paths, temp_dir_opt))
}
5 changes: 4 additions & 1 deletion test/end-to-end/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ def __init__(self, path):

def __call__(self, *args: Any, **kwds: Any) -> Any:
try:
return check_output([str(self.path), *args], **kwds).decode("utf-8")
output = check_output([str(self.path), *args], **kwds)
if "text" not in kwds:
return output.decode("utf-8")
return output
except CalledProcessError as e:
if kwds.get("stderr") is None:
print(e.output)
Expand Down
12 changes: 12 additions & 0 deletions test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,3 +1227,15 @@ def test_abi3(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path):
assert index["noarch"] == "python"
assert index["subdir"] == host_subdir()
assert index["platform"] == host_subdir().split("-")[0]


# This is how cf-scripts is using rattler-build - rendering recipes from stdin
def test_rendering_from_stdin(
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path
):
text = (recipes / "abi3" / "recipe.yaml").read_text()
# variants = recipes / "abi3" / "variants.yaml" "-m", variants
rendered = rattler_build("build", "--render-only", input=text, text=True)
loaded = json.loads(rendered)

assert loaded[0]["recipe"]["package"]["name"] == "python-abi3-package-sample"

0 comments on commit 858541c

Please sign in to comment.