-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Allow passing arguments to PEX invocation used for pex_binary
#20737
Conversation
5567be0
to
6f495a8
Compare
In #20227, I indicated that maybe this sort of functionality could solve that issue, i.e. we expect someone who wants to pass If that's the way we want to go, we could potentially deprecate all the random fields that just set an argument (with no fancy pants functionality attached), e.g. However, this would mean something like # with extra_build_args only:
__defaults__({pex_binary: dict(extra_build_args=["--no-compress", "--sh-boot"])})
pex_binary(name="all-defaults", entry_point="foo.py")
pex_binary(name="half-defaults", entry_point="bar.py", extra_build_args=["--compress", "--sh-boot"]) # have to remember to pass the other defaults
# with dedicated fields per flag:
__defaults__({pex_binary: dict(compress=False, sh_boot=True)})
pex_binary(name="all-defaults", entry_point="foo.py")
pex_binary(name="half-defaults", entry_point="bar.py", compress=True) # sh_boot default still applies Thus, I'm now thinking that it would actually be good to add fields for each flag. Thoughts? I don't think this should block this PR though, having this |
I don't know that it's necessary to deprecate, but in the planned new Python backend it will make sense to learn from this and be "thinner". |
Nice! |
I thin this PR is good and this should exist even if we think of it as "just" an escape hatch. In general I think it's really hard to layer "thick abstractions" successfully and one commonly ends up where you need to be an expert in both the underlying tool and the one that is purporting to wrap it. I'm certainly disposed toward "thinner" abstractions in general. (There are a lot of geologic strata in Python packaging-land though so that might not be the best example, it's more like a 500% problem.) I think the typing and composability of fields is pretty valuable though and I'd still lean towards adding fields for most everything the underlying tool exposes. They are usually pretty cheap. If the interface became effective just args or |
😂
Yeah, that's fair. I think that's a better distillation of what I was attempting to reach for with the |
This moves the `extra_build_args` from being a field on `pex_binary` only to being a common field, so it appears on both `pex_binary` and the `pex_binaries` target generator. I'd missed this in #20737.
…ss globally (#21202) A new option `[pex-cli].global_args` has been added to be able to pass arbitrary arguments to the `pex` tool as part of any Pants goal invocation. This should make it a lot easier to modify behavior of `pex` tool without needing to make changes in the Pants codebase. Not having this ability to pass arbitrary arguments to pex makes it really hard to start taking advantage of new features that come with newer versions of pex. For instance, the new `--exclude` flag added recently would require making lots of changes in the codebase to be able to pass those extra arguments. This is because the pex invocations in the Pants codebase are numerous and it's really hard to make sure a particular argument is respected (by keeping the chain of calls correct making sure it does reach the final subprocess spawn). And if it's relevant for multiple goals, this becomes even harder. We would still need to make changes to pass arguments to individual targets, see #20737 or #20939 - this makes sense as those arguments apply only to those targets. However, some options would need to apply for any `pex` invocation (e.g. ignoring all 3rd party dependencies). I've looked into having environment variables support for all flags that PEX has (pex-tool/pex#2242) first (so that no changes are needed in Pants, one would just export a bunch of env vars as needed), but this is not going to happen any time soon, so doing it in the Pants codebase instead is the only path forward, I reckon.
This adds a new field
extra_build_args
topex_binary
that just faithfully passes through arbitrary arguments to thepex ...
invocation used to build the PEX. This gives users more control and flexibility for new PEX features that Pants might not (yet) expose natively.For instance, the functionality requested in #20227 can now be solved by passing
extra_build_args=["--no-compress"]
, and similarly people can now start taking advantage of the--no-pre-install-wheels
functionality for their own PEXes (relates to #20562).