Skip to content

Ensure consistent indentation when adding dependencies#14991

Merged
zanieb merged 2 commits intomainfrom
charlie/ind
Jul 31, 2025
Merged

Ensure consistent indentation when adding dependencies#14991
zanieb merged 2 commits intomainfrom
charlie/ind

Conversation

@charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Jul 31, 2025

Summary

The basic problem here is that when we had multiple items in an inline array, and that array expanded to multiple lines, we accidentally changed the indentation part-way through due to how prefixes work in the TOML.

Here's Claude's explanation of the root cause, which I find pretty decent:

  Here's what happened step by step:

  1. First item ("iniconfig"): Has empty prefix "" → indentation_prefix stays None → uses default 4 spaces
  2. Second item ("ruff"): Has empty prefix "" → indentation_prefix stays None → uses default 4 spaces
  3. Third item ("typing-extensions"): Has prefix " " (single space from inline format) → indentation_prefix becomes
  Some(" ") → uses only 1 space!

  This produced:
  [dependency-groups]
  dev = [
      "iniconfig>=2.0.0",
      "ruff",
   "typing-extensions",  # ← Only 1 space instead of 4!
  ]

  Why the Third Item Had a Different Prefix

  In inline arrays like ["ruff", "typing-extensions"], the items are separated by commas and spaces. When parsed by
  the TOML library:
  - "ruff" has no prefix (it comes right after [)
  - "typing-extensions" has a single space prefix (the space after the comma)

  The Fix

  Moving the indentation calculation outside the loop ensures it's calculated only once:

  // Calculate indentation ONCE before the loop
  if let Some(first_item) = deps.iter().next() {
      let decor_prefix = /* get prefix from first item */
      indentation_prefix = (!decor_prefix.is_empty()).then_some(decor_prefix.to_string());
  }

  // Now use the same indentation for ALL items
  for item in deps.iter_mut() {
      // Apply consistent indentation to every item
  }

  This ensures all items get the same indentation (4 spaces by default when converting from inline arrays), producing
   the correct output:

  [dependency-groups]
  dev = [
      "iniconfig>=2.0.0",
      "ruff",
      "typing-extensions",  # ← Correct 4-space indentation
  ]

  The bug only affected arrays being converted from inline to multiline format, where different items might have
  different residual formatting from their inline representation.

Closes #14961.

@charliermarsh charliermarsh added the bug Something isn't working label Jul 31, 2025
@charliermarsh charliermarsh marked this pull request as ready for review July 31, 2025 11:25
@zanieb zanieb enabled auto-merge (squash) July 31, 2025 11:37
@zanieb zanieb temporarily deployed to uv-test-registries July 31, 2025 11:40 — with GitHub Actions Inactive
@zanieb zanieb merged commit 3564e88 into main Jul 31, 2025
92 checks passed
@zanieb zanieb deleted the charlie/ind branch July 31, 2025 11:50
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 6, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.8.4` -> `0.8.5` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>astral-sh/uv (astral-sh/uv)</summary>

### [`v0.8.5`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#085)

[Compare Source](astral-sh/uv@0.8.4...0.8.5)

##### Enhancements

- Enable `uv run` with a GitHub Gist ([#&#8203;15058](astral-sh/uv#15058))
- Improve HTTP response caching log messages ([#&#8203;15067](astral-sh/uv#15067))
- Show wheel tag hints in install plan ([#&#8203;15066](astral-sh/uv#15066))
- Support installing additional executables in `uv tool install` ([#&#8203;14014](astral-sh/uv#14014))

##### Preview features

- Enable extra build dependencies to 'match runtime' versions ([#&#8203;15036](astral-sh/uv#15036))
- Remove duplicate `extra-build-dependencies` warnings for `uv pip` ([#&#8203;15088](astral-sh/uv#15088))
- Use "option" instead of "setting" in `pylock` warning ([#&#8203;15089](astral-sh/uv#15089))
- Respect extra build requires when reading from wheel cache ([#&#8203;15030](astral-sh/uv#15030))
- Preserve lowered extra build dependencies ([#&#8203;15038](astral-sh/uv#15038))

##### Bug fixes

- Add Python versions to markers implied from wheels ([#&#8203;14913](astral-sh/uv#14913))
- Ensure consistent indentation when adding dependencies ([#&#8203;14991](astral-sh/uv#14991))
- Fix handling of `python-preference = system` when managed interpreters are on the PATH ([#&#8203;15059](astral-sh/uv#15059))
- Fix symlink preservation in virtual environment creation ([#&#8203;14933](astral-sh/uv#14933))
- Gracefully handle entrypoint permission errors ([#&#8203;15026](astral-sh/uv#15026))
- Include wheel hashes from local Simple indexes ([#&#8203;14993](astral-sh/uv#14993))
- Prefer system Python installations over managed ones when `--system` is used ([#&#8203;15061](astral-sh/uv#15061))
- Remove retry wrapper when matching on error kind ([#&#8203;14996](astral-sh/uv#14996))
- Revert `h2` upgrade ([#&#8203;15079](astral-sh/uv#15079))

##### Documentation

- Improve visibility of copy and line separator in dark mode ([#&#8203;14987](astral-sh/uv#14987))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS41Mi4yIiwidXBkYXRlZEluVmVyIjoiNDEuNTIuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv add uses inconsistent indentation in toml after conversion to multiline list

2 participants

Comments