Ensure python_wheel sources are linked after dependent targets are built#308
Open
marcuscaisey wants to merge 2 commits into
Open
Ensure python_wheel sources are linked after dependent targets are built#308marcuscaisey wants to merge 2 commits into
marcuscaisey wants to merge 2 commits into
Conversation
Contributor
Author
|
The FreeBSD tests will fail because the ports need to be updated. I did that in #297 |
marcuscaisey
commented
May 8, 2026
| "python": [interpreter], | ||
| }, | ||
| post_build = None if licences else _add_licences, | ||
| sandbox = False, |
Contributor
Author
There was a problem hiding this comment.
This was never needed since the build doesn't make any network requests
marcuscaisey
commented
May 8, 2026
| # Hacky solution to handle things being in subdirectories in awkward ways. | ||
| before, _, after = outs[0].partition('/') | ||
| if after: | ||
| cmd = f'rm -rf {before} && {cmd}' |
Contributor
Author
There was a problem hiding this comment.
I think this logic was trying to handle the scenario where the sources are output into the same directory as one of the deps. The #srcs rule doesn't define any deps, so this isn't required anymore.
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.
Problem
python_wheelsources are not symlinked intoplz-out/python/venvafter dependent targets are built.Worked example
After running the following commands in this repo:
plz clean --nobackground plz test //test:name_scheme_testWhen I open the test file

test/name_scheme_test.py:My language server can't resolve the sources from either of the
python_wheeltargets//third_party/python:clickand//third_party/python:click-logthat//test:name_scheme_testdepends on. I've configured it to look inplz-out/python/venvfor modules, but the sources aren't there.Expected Behaviour
After building a
python_xxxtarget which depends on apython_wheeltarget, the sources of thepython_wheelhave been symlinked intoplz-out/python/venv.Actual Behaviour
The sources are not symlinked unless
//test:name_scheme_testis built directly. This is annoying and usually results in me just doingplz build //third_party/python/...to link everything even though not all of the targets are required. This behaviour doesn't align withproto_library,go_repo, orpip_library.Cause
While
//third_party/python:clickhas the appropriatelink:plz-out/python/venvlabel://test:name_scheme_testdepends on//third_party/python:_click#wheelinstead because//test:_name_scheme_test#pexhas apydependency requirement:So
//test:name_scheme_testnever gets built.Solution
Split
//third_party/python:_click#wheelinto//third_party/python:_click#srcsand//third_party/python:_click#wheel::_click#srcsdoes everything that:_click#wheeldid except create the.pex.zip. This target is labelled withlink:plz-out/python/venvinstead of:click.//test:_name_scheme_test#wheelnow just zips up the output of//test:_name_scheme_test#srcs. The output of this target is unchanged.:clickis now a filegroup which exposes_click#srcs. The output of this target is unchanged, however it now doesn't depend on_click#wheelas it did before (see bonus change for more on this).Now, regardless of whether a target depends on
//third_party/python:_click#wheelor//third_party/python:click, the sources will be symlinked intoplz-out:Bonus Change
After updating
python_wheel, the following test failed to build:The root cause is thought-machine/please#3531.
plz-out/gen/third_party/python/setuptools.pex.zipis the output of//third_party/python:_setuptools#wheelwhich was previously being built because//test:_namespaced_packages_test#pexdepends on//third_party/python:_setuptools#wheeltransitively through//test:_namespaced_packages_test#pex->//third_party/python:googleapis_common_protos->//third_party/python:protobuf_pip->//third_party/python:setuptools->//third_party/python:_setuptools#wheel.After the
python_wheelchange,//third_party/python:setuptoolsdoesn't depend on//third_party/python:_setuptools#wheelso its output is not available when//test:_namespaced_packages_test#pexis being built.To get around this, i've added the
pyrequirement to the mainpip_librarytarget (which//third_party/python:protobuf_pipis) so that it depends on//third_party/python:_setuptools#wheelinstead of//third_party/python:setuptools. I've also excluded.pex.zipfiles from the.whloutput by//third_party/python:protobuf_pip. Overall, this is an improvement because//third_party/python:protobuf_pipwas including all of the setuptools sources in its.whl.Before:
After:
I've included this change as a separate commit.