Skip to content

Commit

Permalink
Support uv export --no-header (#8096)
Browse files Browse the repository at this point in the history
## Summary

Resolves #8063

## Test Plan

`cargo test`
  • Loading branch information
blueraft authored Oct 10, 2024
1 parent 5a8f0ad commit 97af56a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
7 changes: 7 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3162,6 +3162,13 @@ pub struct ExportArgs {
#[arg(long, conflicts_with("no_dev"))]
pub only_dev: bool,

/// Exclude the comment header at the top of the generated output file.
#[arg(long, overrides_with("header"))]
pub no_header: bool,

#[arg(long, overrides_with("no_header"), hide = true)]
pub header: bool,

/// Install any editable dependencies, including the project and any workspace members, as
/// non-editable.
#[arg(long)]
Expand Down
16 changes: 10 additions & 6 deletions crates/uv/src/commands/project/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub(crate) async fn export(
editable: EditableMode,
locked: bool,
frozen: bool,
include_header: bool,
python: Option<String>,
settings: ResolverSettings,
python_preference: PythonPreference,
Expand Down Expand Up @@ -147,12 +148,15 @@ pub(crate) async fn export(
hashes,
&install_options,
)?;
writeln!(
writer,
"{}",
"# This file was autogenerated by uv via the following command:".green()
)?;
writeln!(writer, "{}", format!("# {}", cmd()).green())?;

if include_header {
writeln!(
writer,
"{}",
"# This file was autogenerated by uv via the following command:".green()
)?;
writeln!(writer, "{}", format!("# {}", cmd()).green())?;
}
write!(writer, "{export}")?;
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ async fn run_project(
args.editable,
args.locked,
args.frozen,
args.include_header,
args.python,
args.settings,
globals.python_preference,
Expand Down
4 changes: 4 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ pub(crate) struct ExportSettings {
pub(crate) output_file: Option<PathBuf>,
pub(crate) locked: bool,
pub(crate) frozen: bool,
pub(crate) include_header: bool,
pub(crate) python: Option<String>,
pub(crate) refresh: Refresh,
pub(crate) settings: ResolverSettings,
Expand All @@ -1014,6 +1015,8 @@ impl ExportSettings {
dev,
no_dev,
only_dev,
header,
no_header,
no_editable,
hashes,
no_hashes,
Expand Down Expand Up @@ -1047,6 +1050,7 @@ impl ExportSettings {
output_file,
locked,
frozen,
include_header: flag(header, no_header).unwrap_or(true),
python: python.and_then(Maybe::into_option),
refresh: Refresh::from(refresh),
settings: ResolverSettings::combine(resolver_options(resolver, build), filesystem),
Expand Down
43 changes: 43 additions & 0 deletions crates/uv/tests/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,49 @@ fn dependency() -> Result<()> {
Ok(())
}

#[test]
fn export_no_header() -> Result<()> {
let context = TestContext::new("3.12");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["anyio==3.7.0"]
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
"#,
)?;

context.lock().assert().success();

uv_snapshot!(context.filters(), context.export().arg("--no-header"), @r###"
success: true
exit_code: 0
----- stdout -----
-e .
anyio==3.7.0 \
--hash=sha256:275d9973793619a5374e1c89a4f4ad3f4b0a5510a2b5b939444bee8f4c4d37ce \
--hash=sha256:eddca883c4175f14df8aedce21054bfca3adb70ffe76a9f607aef9d7fa2ea7f0
idna==3.6 \
--hash=sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca \
--hash=sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f
sniffio==1.3.1 \
--hash=sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc \
--hash=sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2
----- stderr -----
Resolved 4 packages in [TIME]
"###);

Ok(())
}

#[test]
fn dependency_extra() -> Result<()> {
let context = TestContext::new("3.12");
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,8 @@ uv export [OPTIONS]

</dd><dt><code>--no-hashes</code></dt><dd><p>Omit hashes in the generated output</p>

</dd><dt><code>--no-header</code></dt><dd><p>Exclude the comment header at the top of the generated output file</p>

</dd><dt><code>--no-index</code></dt><dd><p>Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via <code>--find-links</code></p>

</dd><dt><code>--no-progress</code></dt><dd><p>Hide all progress outputs.</p>
Expand Down

0 comments on commit 97af56a

Please sign in to comment.