diff --git a/crates/uv/src/commands/project/export.rs b/crates/uv/src/commands/project/export.rs index 32d68bb59dbbd..2d01d79248e7f 100644 --- a/crates/uv/src/commands/project/export.rs +++ b/crates/uv/src/commands/project/export.rs @@ -4,6 +4,7 @@ use std::io::Write; use std::path::{Path, PathBuf}; use anyhow::{Context, Result, anyhow}; +use clap::ValueEnum; use itertools::Itertools; use owo_colors::OwoColorize; @@ -291,6 +292,22 @@ pub(crate) async fn export( target.validate_extras(&extras)?; target.validate_groups(&groups)?; + if output_file + .as_deref() + .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 `{}` (supported formats: {})", + "uv export".green(), + ExportFormat::value_variants() + .iter() + .filter_map(clap::ValueEnum::to_possible_value) + .map(|value| value.get_name().to_string()) + .join(", ") + )); + } + // Write the resolved dependencies to the output channel. let mut writer = OutputWriter::new(!quiet || output_file.is_none(), output_file.as_deref()); diff --git a/crates/uv/tests/it/export.rs b/crates/uv/tests/it/export.rs index 1f40ae859a506..c1b96bb47aee3 100644 --- a/crates/uv/tests/it/export.rs +++ b/crates/uv/tests/it/export.rs @@ -4482,29 +4482,14 @@ fn pep_751_infer_output_format() -> Result<()> { Resolved 4 packages in [TIME] "#); - // TODO(charlie): Error on `pyproject.toml`. Right now, it's treated as `requirements.txt`. uv_snapshot!(context.filters(), context.export().arg("-o").arg("pyproject.toml"), @r" - success: true - exit_code: 0 + success: false + exit_code: 2 ----- stdout ----- - # This file was autogenerated by uv via the following command: - # uv export --cache-dir [CACHE_DIR] -o pyproject.toml - -e . - anyio==3.7.0 \ - --hash=sha256:275d9973793619a5374e1c89a4f4ad3f4b0a5510a2b5b939444bee8f4c4d37ce \ - --hash=sha256:eddca883c4175f14df8aedce21054bfca3adb70ffe76a9f607aef9d7fa2ea7f0 - # via project - idna==3.6 \ - --hash=sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca \ - --hash=sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f - # via anyio - sniffio==1.3.1 \ - --hash=sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2 \ - --hash=sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc - # via anyio ----- stderr ----- Resolved 4 packages in [TIME] + error: `pyproject.toml` is not a supported output format for `uv export` (supported formats: requirements.txt, pylock.toml, cyclonedx1.5) "); Ok(())