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

adamant-magazine-16751

03/14/2023, 3:56 PM
Is there a built-in way to change the naming scheme of
tailor
? Or would I need to write a plugin for that?
e.g. append
_src
to every
python_sources
target's name
I think I could create a macro that sets the name, and then use
alias_mapping
👍 1
👆 1
h

happy-kitchen-89482

03/14/2023, 8:10 PM
Let us know if that worked for your needs
a

adamant-magazine-16751

03/14/2023, 8:39 PM
Hmm so I think this isn't really doable this way. The problem I have is that I often find the auto-generated target names (based on the directory) ambiguous. I'd often like to name the final artifact this way, so stuff like
docker_image
but the name is taken by
python_sources
. I rarely use the sources targets in any pants invocations. So I figured I'd like to use the format
<dirname>_src
for sources.
I tried the approach above, but the name is defined implicitly on
python_sources
if not set. Tailor generates
python_sources()
so there's no way to get the name from **kwargs. So I think the only way to achieve this would be to write a plugin. Am I right?
Or actually, I think I need to test it some more
Copy code
def custom_python_sources(**kwargs):
    kwargs["name"] = f"{kwargs['name']}_src"
    python_sources(**kwargs)
this is what I came up with and this is the error I get with
custom_python_sources()
in BUILD
Copy code
21:49:53.58 [ERROR] 1 Exception encountered:

Engine traceback:
  in `list` goal
  in Find targets from input specs
  in Search for addresses in BUILD files - src/b24/celery

MappingError: Failed to parse ./src/b24/celery/BUILD:
'name'