Skip to content

Add uv tree --show-sizes to show package sizes#15531

Merged
zanieb merged 12 commits intoastral-sh:mainfrom
harsh-ps-2003:size
Aug 29, 2025
Merged

Add uv tree --show-sizes to show package sizes#15531
zanieb merged 12 commits intoastral-sh:mainfrom
harsh-ps-2003:size

Conversation

@harsh-ps-2003
Copy link
Contributor

@harsh-ps-2003 harsh-ps-2003 commented Aug 26, 2025

Summary

Adds the enhancement proposed in #15470. Each package in the dependency tree now shows its compressed wheel file size, reading the wheel sizes directly from the lockfile (uv.lock). Doesn't break existing tree formatting or options. If no wheel size is available, nothing is added.

Now, developers can identify large packages in their dependency tree.

The tree still shows extras exactly as before, and then appends a size for the package.

Test Plan

Manually tested :

harsh@fcr-node:~/uv/test-uv-tree-sizes$ ../target/debug/uv tree
Using CPython 3.13.7
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.13`.
Resolved 4 packages in 6ms
pure-python v0.1.0
├── click v8.2.1
└── six v1.17.0
harsh@fcr-node:~/uv/test-uv-tree-sizes$ ../target/debug/uv tree --show-sizes
Using CPython 3.13.7
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.13`.
Resolved 4 packages in 6ms
pure-python v0.1.0
├── click v8.2.1 (99.8KiB)
└── six v1.17.0 (10.8KiB)

@zanieb
Copy link
Member

zanieb commented Aug 26, 2025

I think this should probably be gated by --show-sizes

Comment on lines +694 to +697
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::cast_precision_loss,
clippy::cast_sign_loss
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to do all this? Doesn't wrapping or sign loss seem important?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw a very similar implementation here.

Just being a bit practical here, file sizes rarely exceed the precision limits of f32 and the slight precision loss should be acceptable for display purposes. They don't seem practically important to me, so I prioritised usability over mathematical precision.

Copy link
Member

Choose a reason for hiding this comment

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

Ah okay if that's pre-existing that seems fine. Can we share the implementation somewhere?

Copy link
Contributor Author

@harsh-ps-2003 harsh-ps-2003 Aug 27, 2025

Choose a reason for hiding this comment

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

The CLI (crates/uv) cannot be depended on by uv-resolver, so if we strictly want to share, we will need to put it in an existing low-level crate. I don't think exporting a UI-ish formatter from uv-resolver as a public API is great for boundaries.

Again, being a bit practical here, this ~10 LOC duplication keeps dependencies simple. If we expect more byte-formatting call sites or want strict DRY, then maybe some sort of micro-crate is worth it. Otherwise, keeping both copies is not that bad.

Copy link
Member

Choose a reason for hiding this comment

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

It's less about LOC duplication and more about it being a pretty obscure implementation that opts out of a bunch of our typical safety rules.

I think we could move it into uv-fs, uv-normalize, or some other shared crate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The uv-fs is filesystem utilities; bytes-to-human is unrelated, and uv-normalise normalises names; not generic formatting. What do you think of uv-types? It’s a low-level, tiny, pure helper, which is safe for both crates to depend on, from which both call sites can import it cleanly.

Copy link
Member

Choose a reason for hiding this comment

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

🤷‍♀️ I don't think uv-types is any better really, it's just a display function not a type that we need to share across a bunch of interfaces. We could also use uv-console or uv-logging.

);
if show_sizes {
tree = tree.with_show_sizes(true);
}
Copy link
Member

Choose a reason for hiding this comment

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

Why use a .with... pattern here instead of passing the value to new like all the other settings?

@zanieb
Copy link
Member

zanieb commented Aug 26, 2025

We'll need a new test case in it/tree. What does this do with extras?

@harsh-ps-2003
Copy link
Contributor Author

What does this do with extras?

It's orthogonal to extras. The size is taken from the first wheel in the lockfile that has a size field. Extras do not change which size is shown; there’s no per-extra size.

@harsh-ps-2003
Copy link
Contributor Author

I think the failing test is a flake!

@zanieb zanieb changed the title add size in uv tree Add uv tree --show-sizes to show package sizes Aug 27, 2025
@zanieb
Copy link
Member

zanieb commented Aug 28, 2025

I can't push the fix

diff --git a/Cargo.lock b/Cargo.lock
index a65e547f1..11368662b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6241,6 +6241,7 @@ dependencies = [
  "uv-cache-key",
  "uv-client",
  "uv-configuration",
+ "uv-console",
  "uv-distribution",
  "uv-distribution-filename",
  "uv-distribution-types",

@harsh-ps-2003
Copy link
Contributor Author

harsh-ps-2003 commented Aug 29, 2025

I can't push the fix

I pushed for you, but Docker images are failing now! Weird

@zanieb
Copy link
Member

zanieb commented Aug 29, 2025

The Docker image auth is a GitHub issue.

@zanieb zanieb merged commit d877899 into astral-sh:main Aug 29, 2025
146 of 157 checks passed
@harsh-ps-2003 harsh-ps-2003 deleted the size branch August 29, 2025 15:31
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 5, 2025
This MR contains the following updates:

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

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.15`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0815)

[Compare Source](astral-sh/uv@0.8.14...0.8.15)

##### Python

- Upgrade SQLite 3.50.4 in CPython builds for [CVE-2025-6965](GHSA-2m69-gcr7-jv3q) (see also [python/cpython#137134](python/cpython#137134))

##### Enhancements

- Add `uv auth` commands for credential management ([#&#8203;15570](astral-sh/uv#15570))
- Add pyx support to `uv auth` commands ([#&#8203;15636](astral-sh/uv#15636))
- Add `uv tree --show-sizes` to show package sizes ([#&#8203;15531](astral-sh/uv#15531))
- Add `--python-platform riscv64-unknown-linux` ([#&#8203;15630](astral-sh/uv#15630))
- Add `--python-platform` to `uv run` and `uv tool` ([#&#8203;15515](astral-sh/uv#15515))
- Add `uv publish --dry-run` ([#&#8203;15638](astral-sh/uv#15638))
- Add zstandard support for wheels ([#&#8203;15645](astral-sh/uv#15645))
- Allow registries to pre-provide core metadata ([#&#8203;15644](astral-sh/uv#15644))
- Retry streaming Python and binary download errors ([#&#8203;15567](astral-sh/uv#15567))

##### Bug fixes

- Fix settings rendering for `extra-build-dependencies` ([#&#8203;15622](astral-sh/uv#15622))
- Skip non-existent directories in bytecode compilation ([#&#8203;15608](astral-sh/uv#15608))

##### Error messages

- Add error trace to invalid package format ([#&#8203;15626](astral-sh/uv#15626))

</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:eyJjcmVhdGVkSW5WZXIiOiI0MS45My4zIiwidXBkYXRlZEluVmVyIjoiNDEuOTMuMyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
@pablofueros
Copy link

Hello everyone. Thanks for this PR, i also proposed this idea a few months ago on #11883 it's great to see it implemented.

Just wanted to also point it out here, if repeated packages existis, sizes could not be shown more than one time (in my Issue I suggest an idea for that). With this, the total sum computation would trivial, and that was my actual concern, just to make an idea of the total project size.

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.

3 participants