Omit `--find-links` from annotation header unless requested (#1898)

## Summary

Like #1835, but for `--find-links` (for consistency).
This commit is contained in:
Charlie Marsh 2024-02-22 23:05:53 -05:00 committed by GitHub
parent 3bd4ccad11
commit 73ed0f0cf1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 22 deletions

View File

@ -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="))
{
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;
Some(None)
} else if !include_index_url && (arg == "--extra-index-url" || arg == "--index-url") {
return Some(None);
}
// Mark the next item as (to be) skipped.
if arg == "--index-url" || arg == "--extra-index-url" {
*skip_next = Some(true);
Some(None)
} else {
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(" ");

View File

@ -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 -----

View File

@ -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 -----