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

sort dependencies in pyproject.toml #6388

Merged
merged 19 commits into from
Aug 29, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix the test (should be failing)
  • Loading branch information
ChannyClaus committed Aug 27, 2024
commit 01ecc17c8a8362d590b991c675df4ae5da66f268
19 changes: 4 additions & 15 deletions crates/uv-workspace/src/pyproject_mut.rs
Original file line number Diff line number Diff line change
@@ -504,6 +504,7 @@ pub fn add_dependency(
has_source: bool,
) -> Result<ArrayEdit, Error> {
let mut to_replace = find_dependencies(&req.name, Some(&req.marker), deps);

let edit = match to_replace.as_slice() {
[] => {
// determine the dependency list is sorted prior to
@@ -518,30 +519,18 @@ pub fn add_dependency(
.all(|w| w[0].to_string() <= w[1].to_string());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only pass when all values are strings. If they aren't the table is invalid; We could error, but for simplicity here it makes more sense to treat invalid files as unsorted, add our requirement to the end of the list and let it fail later when we try to use the pyproject.toml


deps.push(req.to_string());
let mut index = deps.len() - 1;
reformat_array_multiline(deps);

if sorted {
ChannyClaus marked this conversation as resolved.
Show resolved Hide resolved
deps.sort_by_key(|d| {
pep508_rs::Requirement::<VerbatimUrl>::parse(d.clone().as_str().unwrap(), &*CWD)
.unwrap()
.name
.clone()
});
index = deps
.iter()
.position(|d| {
pep508_rs::Requirement::<VerbatimUrl>::parse(
d.clone().as_str().unwrap(),
&*CWD,
)
.unwrap()
.name
== req.name
})
.unwrap();
}

reformat_array_multiline(deps);
Ok(ArrayEdit::Add(index))
Ok(ArrayEdit::Add(deps.len() - 1))
}
[_] => {
let (i, mut old_req) = to_replace.remove(0);
4 changes: 2 additions & 2 deletions crates/uv/tests/edit.rs
Original file line number Diff line number Diff line change
@@ -4106,10 +4106,10 @@ fn sorted_dependencies() -> Result<()> {
dependencies = [
"CacheControl[filecache]>=0.14,<0.15",
"mwparserfromhell",
"pydantic",
"pydantic>=2.6.4",
"pywikibot",
"sentry-sdk",
"yarl>=2.6.4",
"yarl",
]
"###
);