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

narrow pex_binary files warning #18619

Merged
merged 2 commits into from Mar 31, 2023

Conversation

cognifloyd
Copy link
Member

@cognifloyd cognifloyd commented Mar 29, 2023

There is a helpful warning when using pex_binary and one or more of the transitive dependencies is a files target. However, that warning is overly broad, as there are situations when it is ok to have files targets.

When a PEX depends on a packaged target, such as python_distribution, then any transitive files targets are irrelevant because pex just installs the wheel with whatever is included in it.

Background

I am building a pex_binary that has explicit dependencies on a number of python_distribution targets. This pex_binary has entry_point=None, because I am using it as a relocatable archived virtualenv. I set include_tools=True so that I can take the pex file and run PEX_TOOLS=1 dist/st2.pex venv /opt/stackstorm/st2 to quickly install the entire virutalenv (which consists of the exact versions of deps locked in the resolve's lockfile). So, the files warning was also irrelevant for me, because I'm not going to run any of the 1st party code from within the pex; it will be extracted as a venv before the 1st party code runs.

While studying pex_binary, I found that the include_sources option skips including the transitive sources. But, generated dependencies, such as the wheels generated by python_distribution still get included in the pex (because include_local_dists=True is hard-coded for pex_binary). Because include_sources skips including the transitive sources, I figured this would be a clean/predictable way to avoid the warning and still build the packaged-virtualenv pex like I want.

Note

I labeled this as category:bugfix because the warning was not accounting for the behavioral change that happens when using the include_sources flag. But I can also see calling this category:user api change (it minimizes when you see the warning) or category:new feature (it allows more uses of pex_binary without that warning).

@cognifloyd cognifloyd added category:bugfix Bug fixes for released features backend: Python Python backend-related issues labels Mar 29, 2023
@cognifloyd cognifloyd self-assigned this Mar 29, 2023
@cognifloyd cognifloyd force-pushed the pex_binary-files-warning branch 2 times, most recently from cd0414c to b326391 Compare March 29, 2023 21:48
@cognifloyd cognifloyd marked this pull request as ready for review March 29, 2023 23:52
@cognifloyd cognifloyd requested a review from benjyw March 29, 2023 23:55
@cognifloyd cognifloyd modified the milestones: 2.16.x, 2.17.x Mar 30, 2023
@benjyw
Copy link
Sponsor Contributor

benjyw commented Mar 30, 2023

This seems like yet another use case for "not traversing deps through build dependencies", as discussed in #18254

@cognifloyd
Copy link
Member Author

cognifloyd commented Mar 30, 2023

This seems like yet another use case for "not traversing deps through build dependencies", as discussed in #18254

Agreed. Not traversing package deps would prevent (possibly) duplicating the sources if include_sources=True. But that would not mean that we could delete this warning altogether. So, we would need to adopt the FilteredTransitiveDepWalking primitive in both ...util_rules.pex_from_targets.create_pex_from_targets() and in backend.python.goals.package_pex_binary.package_pex_binary(). Even if/when we do that, checking for files targets when include_sources=False seems to be a waste of cycles. So, I think this PR makes sense either way.

@cognifloyd cognifloyd requested a review from benjyw March 30, 2023 21:54
Copy link
Sponsor Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

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

Nice

@cognifloyd cognifloyd merged commit 5442013 into pantsbuild:main Mar 31, 2023
17 checks passed
cognifloyd added a commit that referenced this pull request Mar 31, 2023
There is a helpful warning when using `pex_binary` and one or more of
the transitive dependencies is a `files` target. However, that warning
is overly broad, as there are situations when it is ok to have `files`
targets.

When a PEX depends on a packaged target, such as `python_distribution`,
then any transitive `files` targets are irrelevant because pex just
installs the wheel with whatever is included in it.
cognifloyd added a commit that referenced this pull request Mar 31, 2023
There is a helpful warning when using `pex_binary` and one or more of
the transitive dependencies is a `files` target. However, that warning
is overly broad, as there are situations when it is ok to have `files`
targets.

When a PEX depends on a packaged target, such as `python_distribution`,
then any transitive `files` targets are irrelevant because pex just
installs the wheel with whatever is included in it.
@cognifloyd cognifloyd deleted the pex_binary-files-warning branch June 14, 2023 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Python Python backend-related issues category:bugfix Bug fixes for released features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants