Allow pants export --resolve to take targets#23415
Open
wisechengyi wants to merge 7 commits into
Open
Conversation
Previously the export goal rejected any target specs. Now, when targets are provided alongside `--resolve`, only the 3rd-party requirements transitively needed by those targets are included in the exported virtualenv (via Pex native lockfile subsetting). Exporting without targets retains the existing full-resolve behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
wisechengyi
marked this pull request as draft
June 10, 2026 21:55
pants export --resolve to filter by target transitive depspants export --resolve to take targets
…pendency graph Models A→B,C; B→req_x→req_y; C→req_z and asserts that transitive req_strings correctly includes only the packages reachable from each root target. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ements Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
wisechengyi
marked this pull request as ready for review
June 10, 2026 22:38
Also filter transitive req_strings by resolve to exclude shared deps that may appear in multiple resolves' closures. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
wisechengyi
commented
Jun 11, 2026
Comment on lines
+561
to
+573
| wrong_resolve = [ | ||
| tgt.address | ||
| for tgt in transitive_tgts.roots | ||
| if tgt.has_field(PythonResolveField) | ||
| and tgt[PythonResolveField].normalized_value(python_setup) != resolve | ||
| ] | ||
| if wrong_resolve: | ||
| raise ExportError( | ||
| f"The following targets do not belong to the resolve `{resolve}` " | ||
| f"and cannot be used to filter its export:\n" | ||
| + "\n".join(f" {addr}" for addr in wrong_resolve) | ||
| + f"\nEnsure all targets belong to the `{resolve}` resolve." | ||
| ) |
Contributor
Author
There was a problem hiding this comment.
Potentially worth reviewing whether this is an overkill. E.g. do we need to care at export phase? For targets that can't build due to diverging resolves, is it okay to ignore the failure during export?
Contributor
|
Thanks for the contribution. We've just branched for 2.33.x, so merging this pull request now will come out in 2.34.x, please move the release notes updates to docs/notes/2.34.x.md if that's appropriate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
exportgoal--resolve, the exported virtualenv contains only the 3rd-party requirements transitively needed by those targets (via Pex native lockfile subsetting)Example usage:
Test plan
test_export_venv_new_codepath,test_export_tool, andtest_export_codegen_outputsstill pass (full-resolve path unchanged)test_export_venv_filtered_by_targetsverifies targets flow through the rule chain and the transitive-closure branch is takenAdhoc tests
Full resolve (no targets) — baseline unchanged:
Filtered by a source target with no 3rd-party deps (
src/python/pants/core/goals/export.py):Filtered by a test file with pytest in its transitive closure (
src/python/pants/backend/python/goals/export_test.py):pytest and its transitive deps are present; unrelated packages from the full resolve are absent.
🤖 Generated with Claude Code