How do I set the `args` and `name` field in the `p...
# general
q
How do I set the
args
and
name
field in the
pex_binary
target if I use
pex_binaries
instead of individually writing each
pex_binary
target with different
entry_points
?
q
I tried that. But it says:
If you'd like to override a field's value for every
pex_binary
target generated by this target, change the field directly on this target rather than using the
overrides
field.
I am not sure what that means
b
Ah, if you tried something, can you share it? And how it doesn't work how you expect
q
I tried to use this:
Copy code
__defaults__(extend=True, pex_binary=dict(name="bin", args=["-h"]))
and got this:
Copy code
TypeError: set_defaults() got an unexpected keyword argument 'pex_binary'
b
Ah, okay, I think
__defaults__
takes a
dict
not kwargs directly (https://www.pantsbuild.org/2.21/docs/using-pants/key-concepts/targets-and-build-files#field-default-values)
Copy code
__defaults__({pex_binary: dict(name="bin", args=["-h"])}, extend=True)
(NB the
{...}
) However that's something slightly different to
overrides
q
I am getting this now:
Copy code
InvalidFieldException: Unrecognized field `name` for target pex_binary. Valid fields are: args, check, complete_platforms, dependencies, description, emit_warnings, entry_point, env, environment, executable, execution_mode, extra_build_args, ignore_errors, include_requirements, include_sources, include_tools, inherit_path, interpreter_constraints, layout, output_path, platforms, resolve, resolve_local_platforms, restartable, script, sh_boot, shebang, strip_pex_env, tags, venv_hermetic_scripts, venv_site_packages_copies.
b
With
__defaults__
? I think the
name
field may be special and so may not work with
__defaults__
. But, it's a bit surprising that to be setting the name by default, one cannot have two targets with the same name in a single directory
I'd be expecting something like
pex_binaries(..., overrides={....: dict(name="a"), ...: dict(name="b")})
where the
...
depend on your specifics
q
if we dont populate the name field, how does
pex_binaries
name each
pex_binary
target? And is there a way to customize it?
b
I'm not sure how it does that. A good way to find out would be to introspect it with
pants list
, e.g.
pants list path/to/directory:
will print the names of all the targets defined in
path/to/directory/BUILD
I think
q
Oh ohk. thank you!