mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-01 12:24:15 +00:00
Fix source annotation in pip compile annotation-style=line output (#3637)
## Summary
Fixes a small discrepancy between the pip compile outputs for
`annotation-style=split` and `annotation-style=line` commands.
### Problem
Consider the following `pyproject.toml` file.
```sh
$ cat pyproject.toml
[project]
name = "uv_test"
dynamic = ["version"]
dependencies = ["click"]
```
Running uv pip compile with annotation-style=split on uv 0.1.44 version
yields the following:
```sh
❯ uv pip compile pyproject.toml --annotation-style=split
Resolved 1 package in 2ms
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml --annotation-style=split
click==8.1.7
# via uv-test (pyproject.toml)
```
However, running uv pip compile with annotation-style=line doesn't
include source info for root level dependencies.
```sh
❯ uv pip compile pyproject.toml --annotation-style=line
Resolved 1 package in 1ms
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml --annotation-style=line
click==8.1.7
```
With this PR:
```sh
❯ ../target/debug/uv pip compile --annotation-style=line pyproject.toml
Resolved 1 package in 6ms
# This file was autogenerated by uv via the following command:
# uv pip compile --annotation-style=line pyproject.toml
click==8.1.7 # via uv-test (pyproject.toml)
```
This also now matches `pip-tools` output:
```sh
❯ pip-compile --annotation-style=line pyproject.toml
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --annotation-style=line pyproject.toml
#
click==8.1.7 # via uv_test (pyproject.toml)
```
## Test Plan
`cargo test`
This commit is contained in:
parent
3383510b1d
commit
e3e7895605
2 changed files with 54 additions and 9 deletions
|
|
@ -207,11 +207,19 @@ 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<_>>()
|
||||
|
|
@ -219,7 +227,7 @@ impl std::fmt::Display for DisplayResolutionGraph<'_> {
|
|||
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 => {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -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<()> {
|
||||
|
|
@ -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
|
||||
|
|
@ -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 -----
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue