From c4209c80eae127e83927776e81b2839ddfaff14d Mon Sep 17 00:00:00 2001 From: BakerNet Date: Tue, 19 Mar 2024 15:18:59 -0700 Subject: [PATCH 1/5] Add CUSTOM_COMPILE_COMMAND support to uv pip compile --- crates/uv/src/commands/pip_compile.rs | 20 ++++++++- crates/uv/src/main.rs | 5 +++ crates/uv/tests/pip_compile.rs | 61 +++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/crates/uv/src/commands/pip_compile.rs b/crates/uv/src/commands/pip_compile.rs index 8afd94c855d2..808b4f0d2a3c 100644 --- a/crates/uv/src/commands/pip_compile.rs +++ b/crates/uv/src/commands/pip_compile.rs @@ -56,6 +56,7 @@ pub(crate) async fn pip_compile( no_emit_packages: Vec, include_annotations: bool, include_header: bool, + custom_compile_command: Option, include_index_url: bool, include_find_links: bool, index_locations: IndexLocations, @@ -369,7 +370,15 @@ pub(crate) async fn pip_compile( writeln!( writer, "{}", - format!("# {}", cmd(include_index_url, include_find_links,)).green() + format!( + "# {}", + cmd( + include_index_url, + include_find_links, + custom_compile_command + ) + ) + .green() )?; } @@ -435,7 +444,14 @@ pub(crate) async fn pip_compile( /// Format the `uv` command used to generate the output file. #[allow(clippy::fn_params_excessive_bools)] -fn cmd(include_index_url: bool, include_find_links: bool) -> String { +fn cmd( + include_index_url: bool, + include_find_links: bool, + custom_compile_command: Option, +) -> String { + if let Some(cmd_str) = custom_compile_command { + return cmd_str; + } let args = env::args_os() .skip(1) .map(|arg| arg.simplified_display().to_string()) diff --git a/crates/uv/src/main.rs b/crates/uv/src/main.rs index ee99de892001..6202ae15b6c2 100644 --- a/crates/uv/src/main.rs +++ b/crates/uv/src/main.rs @@ -324,6 +324,10 @@ struct PipCompileArgs { #[clap(long)] no_header: bool, + /// Change header comment to reflect custom command wrapping `uv pip compile`. + #[clap(long, env = "CUSTOM_COMPILE_COMMAND")] + custom_compile_command: Option, + /// Run offline, i.e., without accessing the network. #[arg( global = true, @@ -1507,6 +1511,7 @@ async fn run() -> Result { args.no_emit_package, !args.no_annotate, !args.no_header, + args.custom_compile_command, args.emit_index_url, args.emit_find_links, index_urls, diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index 9430c6f1fec2..4000b9f13689 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -3482,6 +3482,67 @@ fn no_header() -> Result<()> { Ok(()) } +/// Include custom compile command in the header. +#[test] +fn custom_compile_command() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("black==23.10.1")?; + + uv_snapshot!(context.compile() + .arg("requirements.in") + .arg("--custom-compile-command ./custom-uv-compile.sh"), @r###" + # This file was autogenerated by uv via the following command: + # ./custom-uv-compile.sh + success: true + exit_code: 0 + ----- stdout ----- + black==23.10.1 + click==8.1.7 + # via black + mypy-extensions==1.0.0 + # via black + packaging==23.2 + # via black + pathspec==0.11.2 + # via black + platformdirs==4.0.0 + # via black + + ----- stderr ----- + Resolved 6 packages in [TIME] + "### + ); + + // with env var + uv_snapshot!(context.compile() + .arg("requirements.in") + .env("CUSTOM_COMPILE_COMMAND", "./custom-uv-compile.sh"), @r###" + # This file was autogenerated by uv via the following command: + # ./custom-uv-compile.sh + success: true + exit_code: 0 + ----- stdout ----- + black==23.10.1 + click==8.1.7 + # via black + mypy-extensions==1.0.0 + # via black + packaging==23.2 + # via black + pathspec==0.11.2 + # via black + platformdirs==4.0.0 + # via black + + ----- stderr ----- + Resolved 6 packages in [TIME] + "### + ); + + Ok(()) +} + /// Emit warnings when users pass redundant options from `pip-compile`. #[test] fn allow_unsafe() -> Result<()> { From 8b84ee873c21459b8936f534cff4f1fd118516f3 Mon Sep 17 00:00:00 2001 From: BakerNet Date: Tue, 19 Mar 2024 15:26:25 -0700 Subject: [PATCH 2/5] Fix test --- crates/uv/tests/pip_compile.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index 4000b9f13689..fa27ce090011 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -3491,7 +3491,8 @@ fn custom_compile_command() -> Result<()> { uv_snapshot!(context.compile() .arg("requirements.in") - .arg("--custom-compile-command ./custom-uv-compile.sh"), @r###" + .arg("--custom-compile-command") + .arg("./custom-uv-compile.sh"), @r###" # This file was autogenerated by uv via the following command: # ./custom-uv-compile.sh success: true From 4630ad3c96ceebc084c73e54c557fa75b03ef8c8 Mon Sep 17 00:00:00 2001 From: BakerNet Date: Tue, 19 Mar 2024 16:12:53 -0700 Subject: [PATCH 3/5] Actually fix test --- crates/uv/tests/pip_compile.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index fa27ce090011..823f1e65faf7 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -3493,11 +3493,11 @@ fn custom_compile_command() -> Result<()> { .arg("requirements.in") .arg("--custom-compile-command") .arg("./custom-uv-compile.sh"), @r###" - # This file was autogenerated by uv via the following command: - # ./custom-uv-compile.sh success: true exit_code: 0 ----- stdout ----- + # This file was autogenerated by uv via the following command: + # ./custom-uv-compile.sh black==23.10.1 click==8.1.7 # via black @@ -3519,11 +3519,11 @@ fn custom_compile_command() -> Result<()> { uv_snapshot!(context.compile() .arg("requirements.in") .env("CUSTOM_COMPILE_COMMAND", "./custom-uv-compile.sh"), @r###" - # This file was autogenerated by uv via the following command: - # ./custom-uv-compile.sh success: true exit_code: 0 ----- stdout ----- + # This file was autogenerated by uv via the following command: + # ./custom-uv-compile.sh black==23.10.1 click==8.1.7 # via black From a7db11ba4acd009ce9086a9065a0b61cf4adfb72 Mon Sep 17 00:00:00 2001 From: konsti Date: Wed, 20 Mar 2024 12:13:15 +0100 Subject: [PATCH 4/5] Update crates/uv/src/main.rs Co-authored-by: Hans Baker --- crates/uv/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/uv/src/main.rs b/crates/uv/src/main.rs index 6202ae15b6c2..2404e11733d1 100644 --- a/crates/uv/src/main.rs +++ b/crates/uv/src/main.rs @@ -325,7 +325,7 @@ struct PipCompileArgs { no_header: bool, /// Change header comment to reflect custom command wrapping `uv pip compile`. - #[clap(long, env = "CUSTOM_COMPILE_COMMAND")] + #[clap(long, env = "UV_CUSTOM_COMPILE_COMMAND")] custom_compile_command: Option, /// Run offline, i.e., without accessing the network. From f42410780a67dca94f941a2d9d5eab3392980eca Mon Sep 17 00:00:00 2001 From: konsti Date: Wed, 20 Mar 2024 12:13:20 +0100 Subject: [PATCH 5/5] Update crates/uv/tests/pip_compile.rs Co-authored-by: Hans Baker --- crates/uv/tests/pip_compile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index 823f1e65faf7..9efdbde77a82 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -3518,7 +3518,7 @@ fn custom_compile_command() -> Result<()> { // with env var uv_snapshot!(context.compile() .arg("requirements.in") - .env("CUSTOM_COMPILE_COMMAND", "./custom-uv-compile.sh"), @r###" + .env("UV_CUSTOM_COMPILE_COMMAND", "./custom-uv-compile.sh"), @r###" success: true exit_code: 0 ----- stdout -----