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

Rework reformatting in PyProjectTomlMut to respect original indentation #5075

Merged

Conversation

flyaroundme
Copy link
Contributor

Summary

So this PR introduces change to how Array of dependencies representation is reformatted while PyProjectTomlMut is manipulated. These changes are here for it to respect the original indentation.
Closes #5009

Test Plan

Using pyproject.toml like

[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
  "requests"
]

Executed

$ uv add httpx

And expected in pyproject.toml

[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
  "requests",
  "httpx",
]

Preserving original indentation

@zanieb zanieb requested a review from ibraheemdev July 15, 2024 15:46
Copy link
Member

@ibraheemdev ibraheemdev left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

Can we add a test to ensure this is working as expected? You can see https://github.com/astral-sh/uv/blob/main/crates/uv/tests/edit.rs#L14 for an example (you can probably omit the part checking uv.lock).

@flyaroundme
Copy link
Contributor Author

Thanks for doing this!

Can we add a test to ensure this is working as expected? You can see https://github.com/astral-sh/uv/blob/main/crates/uv/tests/edit.rs#L14 for an example (you can probably omit the part checking uv.lock).

Sure, will do

@flyaroundme
Copy link
Contributor Author

Updated, please re-review 🙏

let decor_prefix = decor
.prefix()
.and_then(|s| s.as_str())
.map(|s| s.split('#').next().unwrap_or("").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.

Hmm I'm a little unclear how this works if the line doesn't have a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the decor.prefix() does not have a comment this whole expression will return the String that is in decor.prefix() trimmed by "\n" from the left

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you're asking about this particular line

.map(|s| s.split('#').next().unwrap_or("").to_string())

in case there is no '#' in the string it well return the whole string

Copy link
Member

Choose a reason for hiding this comment

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

Ah that makes sense.

Copy link
Member

@ibraheemdev ibraheemdev left a comment

Choose a reason for hiding this comment

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

Nice work!

@ibraheemdev ibraheemdev merged commit 14a1ea4 into astral-sh:main Jul 15, 2024
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uv add changes pyproject.toml indentation
2 participants