https://pantsbuild.org/ logo
#general
Title
# general
c

curved-manchester-66006

01/04/2023, 4:59 AM
I have a set of code that should support python3.7 and resolver
foo
, or python3.10 and resolver
bar
. (Said resolvers already have
[python.resolves_to_interpreter_constraints]
)I then have a set of tests I want to parameterize to verify both cases actually work. In other words I want to run with (resolve=foo, interpreter_constraints=python3.7) and (resolve=bar, interpreter_constraints=python3.10) but not (foo && python3.10) or (bar && python3.7). I tired to do something like:
Copy code
__defaults__(all=dict(
    resolve=parametrize("foo", "bar"),
    interpreter_constraints=parametrize(py3_7=["CPython>=3.7.1,<3.8"], py3_10=["CPython==3.10.*"])
But that generates the full matrix and pants yells with a
InvalidFieldException
about
interpreter_constraints
subsets. Is there a way to pair the parametrize or otherwise generate less than the full set of permutations? I read https://github.com/pantsbuild/pants/issues/14863 and https://pantsbuild.slack.com/archives/C046T6T9U/p1671723858955379 and I'm not sure if I should take the current state of constraints+resolves as "confusing but works" or "can't do what I want yet" (Thank you everyone for answering so many questions!)
Ⓜ️ 1
Design breadcrumb for anyone else who ends up here: https://docs.google.com/document/d/1mzZWnXiE6OkgMH_Dm7WeA3ck9veusQmr_c6GWPb_tsQ/edit# As far as I know "Configuration" as described in that doc does not exist today.
And to answer my own question a bit more, I think the answer to day is macros <https://www.pantsbuild.org/docs/macros> ex:
Copy code
def python_mwaa_and_py310_sources(**kwargs):
    kwargs.pop("interpreter_constraints", None)
    kwargs.pop("resolve", None)

    name = kwargs.pop("name", '')
    if name:
        name = name + '_'

    python_sources(
        name=f"{name}mwaa",
        resolve="mwaa_pyop",
        interpreter_constraints=["CPython>=3.7.1,<3.8"],
        **kwargs,
    )
 
    python_sources(
        name=f"{name}py310",
        resolve="default",
        interpreter_constraints=["CPython==3.10.*"],
        **kwargs,
    )
3 Views