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

mysterious-motherboard-97366

06/07/2022, 7:30 AM
I want to parametrize
resolve
for all
python_sources
targets. Is it possible to configure
./pants tailor
to do that when adding more targets? I tried to make a macro, for use with https://www.pantsbuild.org/docs/reference-tailor#section-alias-mapping, but I got an error:
Exception: Error parsing prelude file pants-plugins/macros.py: name 'parametrize' is not defined
My underlying motivation is very similar to https://pantsbuild.slack.com/archives/C046T6T9U/p1651762568623679?thread_ts=1651755337.307249&cid=C046T6T9U but for torch instead of jax.
h

happy-kitchen-89482

06/07/2022, 8:37 AM
You should be able to do it with a macro. Here's an example of how to do this for interpreter_constraints, the same principle should apply: https://github.com/benjyw/black/blob/pantsify3/pants_macros.py
Can you share your macro code?
b

bitter-ability-32190

06/07/2022, 9:58 AM
Are the torch packages like mxnet, in that they have different package names, but same module name? If so, I cheated and still only use one resolve
m

mysterious-motherboard-97366

06/07/2022, 6:35 PM
Are the torch packages like mxnet, in that they have different package names, but same module name?
They have different versions (for example, 1.10.2 vs 1.10.2+cpu). Only one of the variants is on PyPI, the others require extra indices to access.
Can you share your macro code?
This is what I tried for the macro:
Copy code
def python_sources_parametrized(resolve=parametrize("python-default", "torch-cpu"), **kwargs):
    kwargs["resolve"] = parametrize("python-default", "torch-cpu")
    python_sources(resolve=parametrize("python-default", "torch-cpu"), **kwargs)
Would you suggest creating multiple targets instead (i.e. calling
python_sources
twice)? I noticed that https://www.pantsbuild.org/docs/macros says “A macro can create multiple targets—although often it’s better to use `parametrize`”
b

bitter-ability-32190

06/07/2022, 6:45 PM
They have different versions
That stinks. My hacks won't work then
h

happy-kitchen-89482

06/07/2022, 7:39 PM
Ah, yeah, I think you can just create multiple targets. That doc means "it's often better to use parametrize than to use a macro"...
2 Views