I’ve got two `pex_binary` targets that own the sam...
# general
h
I’ve got two
pex_binary
targets that own the same script but supply different BUILD properties similar to:
Copy code
pex_binary(
    name="do-the-thing",
    entry_point="file.py:main",
)
pex_binary(
    name="do-the-thing-arm64",
    entry_point="file.py:main",
    platforms=["linux_aarch64-cp-310-cp310"],
    # BUILD props ...
)
When running the underlying script directly e.g.
pants run file.py
is there a way I can detect the host platform and run the appropriate target? Bear in mind I’m on an older Pants version
2.17.0
so some of the new shiny environments features may not be available.
g
custom macro/plugin would work I think. • detect arch (probably using some Pants lib) • forward to pex_binary
b
you can also make the build graph "dynamic": • using
if ...:
or otherwise compute the `name`s differently • read environment variables with
env("NAME", optional_default_value)
(
.pants.bootstrap
can be used to set env vars via a shell script: https://www.pantsbuild.org/prerelease/docs/using-pants/key-concepts/options#pantsbootstrap-file) That said, the
pex_binary
configuration doesn't influence(*)
pants run file.py
, that always uses a "run on the current host" default configuration.
pants run path/to:do-the-thing
is the only way in which a pex is invoked (* this behaviour changed in Pants 2.x's lifetime... I'm pretty sure it was before 2.17, but potentially not, so I may be telling fibs)