-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
pex-cli: add [pex-cli].args option to pass arguments to the PEX process globally #21202
pex-cli: add [pex-cli].args option to pass arguments to the PEX process globally #21202
Conversation
48e0e9d
to
2bb9b3e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this.
Pants invokes pex in a lot of different ways, e.g. pex ...
to build pex files, but also various pex3
subcommands like pex3 lock create ...
for pants generate-lockfiles
. Does this flag get passed to all of them? If so, I wonder if that isn't the best, e.g. some args might make sense for pex
only. Thoughts?
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.
Fully agreed, Pants should try to avoid getting in users way, by being as thin a wrapper around the underlying tool as possible, and this means exposing whatever args it needs.
@@ -281,3 +281,31 @@ def test_run_script_from_3rdparty_dist_issue_13747() -> None: | |||
result = run_pants(args) | |||
result.assert_success() | |||
assert SAY in result.stdout.strip() | |||
|
|||
|
|||
def test_pass_extra_pex_cli_subsystem_args() -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option would be adding a mocked test to pex_cli_util.py
, rather than only testing the pants run ...
version of this. In particular, this ends up being a very heavy-weight test, because it's having to do a full run_pants
call (level 4 in https://www.pantsbuild.org/2.23/docs/writing-plugins/the-rules-api/testing-plugins).
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a unit test to make sure that Process
object created does have the --pex-cli-args
flags passed which exercises the modified rule (where those arguments are added). I think that having just unit test is probably enough since this is what verifies that arguments are going to be passed. How pex is going to handle them is probably outside of the scope being tested, but I think having this integration (in addition to the most recently added unit test) would be beneficial, but I am not sure about that. Happy to go either way.
That's right, it would be passed to whatever |
I think this is fine as a step 1, given that all of the subsystem-level args are "global" in that sense - but maybe we should document/flag harder that users will likely want to add these at the command line, rather than in pants.toml? Or maybe even naming them thusly ("pex-cli-global-args") - though I think this is kinda silly, now that I've written it out. I think the alternative would be something closer to docker with "build_args", "run_args", etc? Eventually, I'd assume that each of the pex-related targets would have some sort of pex_cli_args |
Alright, with some time away, I'm now wondering if this might be a better overall approach. e.g. from pex --help
|
Thank you, @sureshjoshi!
The help string produced pants/src/python/pants/option/option_types.py Lines 827 to 836 in d99977e
should be clear enough that these arguments are going to be passed to all pex invocations, I reckon? If that's not obvious, we could add the
This is what has been done for some of the targets in the PRs I linked in the description. However, as soon as there's some PEX feature Pants users may want to start using (by providing a custom PEX version in their So this PR makes it possible to pass the arguments globally when it makes sense (e.g.
So I think having a way to pass arguments "globally" would cover the needs of everyone (albeit sometimes forcing to have multiple pants invocations to pass different flags). Then, as additional feature, individual targets may have
I am not sure I follow what you mean with having those subsections, would you be able to elaborate just a bit? |
@huonw @sureshjoshi I am sorry I am not sure if you have any feedback for me since the last interaction we had in this PR? No rush, just checking if I have missed something. |
Co-authored-by: Huon Wilson <[email protected]>
2589e5c
to
ee2b123
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just some doc tweaks
Alexey and I talked on slack and came to the conclusion that if we renamed this it makes this good enough to go ahead: the args
doesn't emphasise (to me) that this will apply across all the variety of invocations of pex that pants does. We brainstormed names like overall-args
, universal-args
, global-args
and Alexey wisely chose the last one 😄 (my other two are bad)
A new option
[pex-cli].global_args
has been added to be able to pass arbitrary arguments to thepex
tool as part of any Pants goal invocation. This should make it a lot easier to modify behavior ofpex
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.
Usage in practice:
With practical usage (could be applied to any target, but showing something that actually can be easily verified to proof the flag value is being used), see below.
With
--pex-cli-args="--no-compile"
:With
--pex-cli-args="--compile"
: