-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
fix python_dist() caching #5479
fix python_dist() caching #5479
Conversation
I haven't dug into the diff yet, but inspection of the pre-existing code/mechanism brings to light what looks like a flaw: a distribution is built via |
To underscore the above, this artifact: |
Some discussion on the slack:
|
To confirm, the resolver will use the 1st |
@kwlzn and I have had some discussion around this and one potential solution is to write a setuptools plugin that injects a local version identifier into the wheel name during setup.py execution so as to properly use the new artifact. Another solution could be to modify the caching strategy to give local py_dist wheels special treatment to avoid this. @jsirois So you are saying that the resolver will use pypi if that exists over a local find-links repo? The current implementation creates a synthetic req lib for the local wheel and gives it the .pants.d path as its Given that rebuilding on source code changes has worked before when we did not create a synthetic lib, I believe that this stale usage is a byproduct of creating the synthetic req lib and passing it to the pex resolver with a find-links repo. |
And yet another solution is to not resolve the local dists at all since we already know their location. We only need resolve their requirements, not them themselves.
Ack, and I think I was just wrong on this one. I did not review the code to see if the find-links were mixed in to the resolver set or used individually. So yay! |
Yep! This intention of this was to get all of the |
Yeah, this can lie dormant for now, or I/someone can close it if it's going to be covered by other PRs. |
…we don't use the first cached one (#6022) ### Problem I made #5479 because the dist resolved for a `python_dist()` would not change after changing any of the source files, and this persisted even after a `clean-all`. This issue is more thoroughly explained in #5449 (which I literally didn't see before making this PR, but describes almost exactly what this PR does, it seems -- great minds think alike?). We were building the `python_dist()` targets each time they were invalidated, but caching the package locally in `~/.cache/pants/` after we built it the first time and using that instead, because the version string was the same for both the first and subsequent builds of the `python_dist()` target. ### Solution - Move argv generation for setup.py invocations into `BuildLocalPythonDistributions`. - Append the `python_dist()` target's fingerprint to the version string using `--tag-build`. This conforms to the "local" version specifier format as per [PEP 440](https://www.python.org/dev/peps/pep-0440/#local-version-identifiers). This tagged version is then used in the synthetic `PythonRequirement` stitched into the build graph for the local dist. - Add an integration test `test_invalidation()` using `mock_buildroot()` (which fails on master, but not in this PR) where we run a binary depending on a `python_dist()`, rewrite the contents of a source file to change the output, then run pants again to verify that the new dist is resolved. *Separately:* - Made `PythonDistribution` subclass `PythonTarget` to avoid duplicated logic. It's not clear what the original reason for not subclassing it was at first, but it seems to be not be in effect anymore. - Changed the `dir` field name for the `Manager` namedtuple in `mock_buildroot()` to be `new_buildroot` so it doesn't get highlighted as a builtin in certain text editors. ### Result When we resolve local dists in any python requirements task, we get the dist corresponding to the target we just built. Resolves #5449.
Problem
python_dist()
doesn't update the binary created when sources change. On master, you can run:Then, change either
super_greet.c
orhello.py
to modify the output (I added an exclamation point to"Super hello!"
insuper_greet.c
). Then run:The same output appears. This also occurs after a
clean-all
-- I'm not exactly sure why.Solution
Add the built dists to the pex builder in
ResolveRequirementsTaskBase#_build_requirements_pex()
. I haven't investigated enough into pex or python dists in pants enough to know exactly why this works yet.Result
Binaries built with
python_dist()
are now updated when source files change. I have added atest_invalidation()
test totest_python_distribution_integration.py
, but I'm not sure whether this tests everything it should be, as the change that fixes it isn't in binary creation, but inresolve_requirements_task_base.py
. I would love if someone with more experience with the python backend could give me more insight on that (but will totally investigate myself before this is merged). I would also like to know why the original error would occur even after a clean-all, which seems indicative of some greater issue, but might be nothing.