I want to parametrize `resolve` for all `python_so...
# general
m
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
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
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
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
They have different versions
That stinks. My hacks won't work then
h
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"...