Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions crates/uv/src/commands/pip/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ pub(crate) async fn pip_compile(
printer: Printer,
preview: PreviewMode,
) -> Result<ExitStatus> {
// If the user provides a `pyproject.toml` or other TOML file as the output file, raise an
// error.
if output_file
.and_then(Path::file_name)
.is_some_and(|name| name.eq_ignore_ascii_case("pyproject.toml"))
{
return Err(anyhow!(
"`pyproject.toml` is not a supported output format for `{}` (only `requirements.txt`-style output is supported)",
"uv pip compile".green()
));
}
if output_file
.and_then(Path::extension)
.is_some_and(|name| name.eq_ignore_ascii_case("toml"))
{
return Err(anyhow!(
"TOML is not a supported output format for `{}` (only `requirements.txt`-style output is supported)",
"uv pip compile".green()
));
}

// Respect `UV_PYTHON`
if python.is_none() && python_version.is_none() {
if let Ok(request) = std::env::var("UV_PYTHON") {
Expand Down
35 changes: 35 additions & 0 deletions crates/uv/tests/it/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16234,3 +16234,38 @@ fn compile_quotes() -> Result<()> {

Ok(())
}

#[test]
fn compile_invalid_output_file() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("anyio==3.7.0")?;

uv_snapshot!(context
.pip_compile()
.arg("requirements.in")
.arg("-o")
.arg("pyproject.toml"), @r"
success: false
exit_code: 2
----- stdout -----

----- stderr -----
error: `pyproject.toml` is not a supported output format for `uv pip compile` (only `requirements.txt`-style output is supported)
");

uv_snapshot!(context
.pip_compile()
.arg("requirements.in")
.arg("-o")
.arg("uv.toml"), @r"
success: false
exit_code: 2
----- stdout -----

----- stderr -----
error: TOML is not a supported output format for `uv pip compile` (only `requirements.txt`-style output is supported)
");

Ok(())
}
Loading