Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source annotation in pip compile annotation-style=line output #3637

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions crates/uv-resolver/src/resolution/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,27 @@ impl std::fmt::Display for DisplayResolutionGraph<'_> {
};

match self.annotation_style {
AnnotationStyle::Line => {
if !edges.is_empty() {
AnnotationStyle::Line => match edges.as_slice() {
[] if source.is_empty() => {}
[] if source.len() == 1 => {
let separator = if has_hashes { "\n " } else { " " };
let comment = format!("# via {}", source.iter().next().unwrap())
.green()
.to_string();
annotation = Some((separator, comment));
}
edges => {
let separator = if has_hashes { "\n " } else { " " };
let deps = edges
.into_iter()
.iter()
.map(|dependency| format!("{}", dependency.name()))
.chain(source.iter().map(std::string::ToString::to_string))
.collect::<Vec<_>>()
.join(", ");
let comment = format!("# via {deps}").green().to_string();
annotation = Some((separator, comment));
}
}
},
AnnotationStyle::Split => match edges.as_slice() {
[] if source.is_empty() => {}
[] if source.len() == 1 => {
Expand Down
47 changes: 42 additions & 5 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn compile_requirements_in_annotation_line() -> Result<()> {
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z --annotation-style=line requirements.in
anyio==3.7.0
anyio==3.7.0 # via -r requirements.in
idna==3.6 # via anyio
sniffio==1.3.1 # via anyio
Expand Down Expand Up @@ -193,6 +193,43 @@ dependencies = [
Ok(())
}

/// Resolve a specific version of `anyio` from a `pyproject.toml` file with `--annotation-style=line`.
#[test]
fn compile_pyproject_toml_with_line_annotation() -> Result<()> {
let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"[build-system]
requires = ["setuptools", "wheel"]
[project]
name = "project"
dependencies = [
"anyio==3.7.0",
]
"#,
)?;

uv_snapshot!(context.compile()
.arg("--annotation-style=line")
.arg("pyproject.toml"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z --annotation-style=line pyproject.toml
anyio==3.7.0 # via project (pyproject.toml)
idna==3.6 # via anyio
sniffio==1.3.1 # via anyio
----- stderr -----
Resolved 3 packages in [TIME]
"###
);

Ok(())
}

/// Resolve a package from a `requirements.in` file, with a `constraints.txt` file.
#[test]
fn compile_constraints_txt() -> Result<()> {
Expand Down Expand Up @@ -880,7 +917,7 @@ fn compile_python_312_annotation_line() -> Result<()> {
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z --annotation-style=line requirements.in --python-version 3.12
black==23.10.1
black==23.10.1 # via -r requirements.in
click==8.1.7 # via black
mypy-extensions==1.0.0 # via black
packaging==24.0 # via black
Expand Down Expand Up @@ -2208,9 +2245,9 @@ optional-dependencies.bar = [
anyio==3.7.0 # via httpcore, project (pyproject.toml)
certifi==2024.2.2 # via httpcore
h11==0.14.0 # via httpcore
httpcore==0.18.0
httpcore==0.18.0 # via project (pyproject.toml)
idna==3.6 # via anyio
iniconfig==1.1.1
iniconfig==1.1.1 # via project (pyproject.toml)
sniffio==1.3.1 # via anyio, httpcore
----- stderr -----
Expand Down Expand Up @@ -8324,7 +8361,7 @@ fn emit_index_annotation_line() -> Result<()> {
# from https://pypi.org/simple
idna==3.6 # via requests
# from https://pypi.org/simple
requests==2.31.0
requests==2.31.0 # via -r requirements.in
# from https://pypi.org/simple
urllib3==2.2.1 # via requests
# from https://pypi.org/simple
Expand Down
Loading