Is there a way to parametrize such that 2 fields c...
# general
p
Is there a way to parametrize such that 2 fields change, but without producing a cartesian product of the two fields? ie, the docs say (https://www.pantsbuild.org/v2.16/docs/targets#parametrizing-targets):
If multiple fields are parametrized, a target will be created for each value in the Cartesian product, with
,
as the delimiter in the address. See the next example.
But, I want to parametrize two
pex_binary
fields:
interpreter_constraints
and
output_path
. I want to use the named interpreter constraint in the
output_path
. So, IC
py36
has
output_path="st2-py36.pex"
I tried the following, but that (of course) did the Cartesian product which does not make sense:
Copy code
pex_binary(
    ...
    interpreter_constraints=parametrize(
        py36=["CPython==3.6.*"],
        py37=["CPython==3.7.*"],
        py38=["CPython==3.8.*"],
    ),
    output_path=parametrize(
        py36="st2-py36.pex",
        py37="st2-py37.pex",
        py38="st2-py38.pex",
    ),
)
Well, I suppose a for loop works:
Copy code
_ics = dict(
    py36=["CPython==3.6.*"],
    py37=["CPython==3.7.*"],
    py38=["CPython==3.8.*"],
)
for ic_name, ic in _ics.items():
    pex_binary(
        name=f"st2-{ic_name}",
        output_path=f"st2-{ic_name}.pex",
        interpreter_constraints=ic,
        ...
    )
It doesn't look as clean as
parametrize
. But it seems to work.
c
see you found https://github.com/pantsbuild/pants/issues/18292, posting here for completeness/posterity
👍 1