diff --git a/crates/uv/src/commands/pip_compile.rs b/crates/uv/src/commands/pip_compile.rs index 083567af2..b949c3bc5 100644 --- a/crates/uv/src/commands/pip_compile.rs +++ b/crates/uv/src/commands/pip_compile.rs @@ -346,7 +346,7 @@ pub(crate) async fn pip_compile( writeln!( writer, "{}", - format!("# {}", cmd(include_index_url)).green() + format!("# {}", cmd(include_index_url, include_find_links)).green() )?; } @@ -393,29 +393,49 @@ pub(crate) async fn pip_compile( } /// Format the `uv` command used to generate the output file. -fn cmd(include_index_url: bool) -> String { +fn cmd(include_index_url: bool, include_find_links: bool) -> String { let args = env::args_os() .skip(1) .map(|arg| arg.normalized_display().to_string()) .scan(None, move |skip_next, arg| { - if let Some(true) = skip_next { + if matches!(skip_next, Some(true)) { // Reset state; skip this iteration. *skip_next = None; - Some(None) - } else if !include_index_url - && (arg.starts_with("--extra-index-url=") || arg.starts_with("--index-url=")) - { - // Reset state; skip this iteration. - *skip_next = None; - Some(None) - } else if !include_index_url && (arg == "--extra-index-url" || arg == "--index-url") { - // Mark the next item as (to be) skipped. - *skip_next = Some(true); - Some(None) - } else { - // Return the argument. - Some(Some(arg)) + return Some(None); } + + // Skip any index URLs, unless requested. + if !include_index_url { + if arg.starts_with("--extra-index-url=") || arg.starts_with("--index-url=") { + // Reset state; skip this iteration. + *skip_next = None; + return Some(None); + } + + // Mark the next item as (to be) skipped. + if arg == "--index-url" || arg == "--extra-index-url" { + *skip_next = Some(true); + return Some(None); + } + } + + // Skip any `--find-links` URLs, unless requested. + if !include_find_links { + if arg.starts_with("--find-links=") || arg.starts_with("-f=") { + // Reset state; skip this iteration. + *skip_next = None; + return Some(None); + } + + // Mark the next item as (to be) skipped. + if arg == "--find-links" || arg == "-f" { + *skip_next = Some(true); + return Some(None); + } + } + + // Return the argument. + Some(Some(arg)) }) .flatten() .join(" "); diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index 1e25d7bbf..40a18d8b3 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -2889,7 +2889,7 @@ fn find_links_directory() -> Result<()> { exit_code: 0 ----- stdout ----- # This file was autogenerated by uv via the following command: - # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --find-links [PROJECT_ROOT]/scripts/wheels + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in markupsafe==2.1.3 # via werkzeug numpy==1.26.2 @@ -2919,7 +2919,7 @@ fn find_links_url() -> Result<()> { exit_code: 0 ----- stdout ----- # This file was autogenerated by uv via the following command: - # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --no-index --find-links https://download.pytorch.org/whl/torch_stable.html + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --no-index tqdm==4.64.1 ----- stderr ----- diff --git a/crates/uv/tests/pip_compile_scenarios.rs b/crates/uv/tests/pip_compile_scenarios.rs index 8fb0548b9..f2ca6a9b9 100644 --- a/crates/uv/tests/pip_compile_scenarios.rs +++ b/crates/uv/tests/pip_compile_scenarios.rs @@ -83,7 +83,7 @@ fn requires_incompatible_python_version_compatible_override() -> Result<()> { exit_code: 0 ----- stdout ----- # This file was autogenerated by uv via the following command: - # uv pip compile requirements.in --find-links https://raw.githubusercontent.com/zanieb/packse/de0bab473eeaa4445db5a8febd732c655fad3d52/vendor/links.html --cache-dir [CACHE_DIR] --python-version=3.11 + # uv pip compile requirements.in --cache-dir [CACHE_DIR] --python-version=3.11 albatross==1.0.0 ----- stderr ----- @@ -244,7 +244,7 @@ fn requires_incompatible_python_version_compatible_override_no_wheels_available_ exit_code: 0 ----- stdout ----- # This file was autogenerated by uv via the following command: - # uv pip compile requirements.in --find-links https://raw.githubusercontent.com/zanieb/packse/de0bab473eeaa4445db5a8febd732c655fad3d52/vendor/links.html --cache-dir [CACHE_DIR] --python-version=3.11 + # uv pip compile requirements.in --cache-dir [CACHE_DIR] --python-version=3.11 albatross==1.0.0 ----- stderr ----- @@ -464,7 +464,7 @@ fn requires_python_patch_version_override_patch_compatible() -> Result<()> { exit_code: 0 ----- stdout ----- # This file was autogenerated by uv via the following command: - # uv pip compile requirements.in --find-links https://raw.githubusercontent.com/zanieb/packse/de0bab473eeaa4445db5a8febd732c655fad3d52/vendor/links.html --cache-dir [CACHE_DIR] --python-version=3.8.0 + # uv pip compile requirements.in --cache-dir [CACHE_DIR] --python-version=3.8.0 albatross==1.0.0 ----- stderr -----