Skip to content

Evaluate extras and groups when determining auditable packages#18511

Merged
woodruffw merged 6 commits intomainfrom
ww/uv-audit-filter
Mar 26, 2026
Merged

Evaluate extras and groups when determining auditable packages#18511
woodruffw merged 6 commits intomainfrom
ww/uv-audit-filter

Conversation

@woodruffw
Copy link
Copy Markdown
Member

@woodruffw woodruffw commented Mar 16, 2026

Summary

I've made uv audit's approach to handling extras and groups (explicitly) subtractive: we don't support flags like --dev (since uv audit audits everything by default); instead, we only support flags like --no-dev, --no-group, etc., that remove items from the to-be-audited set.

To accomplish that, I've abstracted the filtering into a new Lock::packages_for_audit API (maybe there's a better location for it?). Implementation wise, it does a BFS similar to the one used in uv tree. I think there's some room/opportunity for DRYing there but I wanted to keep the PR small/local 🙂

See #18506.

Test Plan

None yet.

@woodruffw woodruffw self-assigned this Mar 16, 2026
@woodruffw woodruffw added the preview Experimental behavior label Mar 16, 2026
@woodruffw woodruffw marked this pull request as ready for review March 16, 2026 16:37
@konstin
Copy link
Copy Markdown
Member

konstin commented Mar 16, 2026

Can you say a but more of what (sub)set of packages users want to audit? E.g., do we want to evaluate all packages by default, or only the set of default extras and the dev group, or only the set production dependencies without groups, etc.?

@woodruffw woodruffw temporarily deployed to uv-test-publish March 17, 2026 01:03 — with GitHub Actions Inactive
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 17, 2026

Merging this PR will not alter performance

✅ 5 untouched benchmarks


Comparing ww/uv-audit-filter (19e8ae6) with main (7228ad6)

Open in CodSpeed

@woodruffw
Copy link
Copy Markdown
Member Author

Can you say a but more of what (sub)set of packages users want to audit? E.g., do we want to evaluate all packages by default, or only the set of default extras and the dev group, or only the set production dependencies without groups, etc.?

Oh yeah, I under-thought this -- I think by default uv audit should audit everything in the lockfile. Then, if they only want to audit a specific extra/group/resolution, they need to pass flags to that effect.

@woodruffw woodruffw force-pushed the ww/uv-audit-filter branch from b0e6ad5 to ffb67a9 Compare March 17, 2026 01:21
@woodruffw
Copy link
Copy Markdown
Member Author

woodruffw commented Mar 17, 2026

Actually even that doesn't make a ton of sense -- I can't think of any user scenario/persona where they'd want to only audit a specific group/extra, rather than just the entire thing. I'm kind of inclined to just drop the extra/group flags entirely, at least for the MVP...

(For context, pip-audit doesn't try to do any of this.)

@woodruffw woodruffw force-pushed the ww/uv-audit-filter branch from ffb67a9 to 580cba8 Compare March 17, 2026 13:39
@zanieb
Copy link
Copy Markdown
Member

zanieb commented Mar 17, 2026

I do think it's reasonable to say --no-group ... and exclude dependency groups from your audit if you only care about production dependencies.

@zanieb
Copy link
Copy Markdown
Member

zanieb commented Mar 17, 2026

I think auditing everything by default and allowing subset selection broadly makes sense to me.

@woodruffw
Copy link
Copy Markdown
Member Author

SG, working on that now.

@woodruffw woodruffw marked this pull request as draft March 17, 2026 14:05
@woodruffw woodruffw marked this pull request as ready for review March 17, 2026 15:29
@woodruffw
Copy link
Copy Markdown
Member Author

OK, good for another look! I've updated the main PR description to clarify what I've changed here.

@woodruffw woodruffw requested review from konstin and zanieb March 17, 2026 15:33
@woodruffw woodruffw force-pushed the ww/uv-audit-filter branch 3 times, most recently from 72d9820 to 7d21220 Compare March 23, 2026 14:36
pub all_extras: bool,

/// Exclude the specified optional dependencies, if `--all-extras` is supplied.
/// Don't audit the specified optional dependencies.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can comment there, but can you also extend the top level description of the command to talk about extras and dep groups?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

dfe8033 LMK if this is what you're thinking 🙂

@woodruffw woodruffw requested a review from konstin March 25, 2026 15:44
Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
woodruffw and others added 3 commits March 25, 2026 12:21
Signed-off-by: William Woodruff <william@astral.sh>
Co-authored-by: konsti <konstin@mailbox.org>
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw force-pushed the ww/uv-audit-filter branch from dfe8033 to 19e8ae6 Compare March 25, 2026 16:21
@woodruffw woodruffw merged commit 25d5549 into main Mar 26, 2026
55 checks passed
@woodruffw woodruffw deleted the ww/uv-audit-filter branch March 26, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Experimental behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants