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

fresh-cat-90827

02/03/2023, 5:03 PM
oh just realized it's not possible to extend target's fields with whatever has been set by default? ๐Ÿงต
โœ… 1
Copy code
# in the parent directory
__defaults__(extend=True, all=dict(tags=["global-tag"]))
Copy code
# in the child directory
python_sources(
    name="lib",
    tags=["local-tag"],
)
when doing
./pants peek
, I can see that
python_sources
only has
["local-tag"]
, not
["global-tag", "local-tag"]
one may want. I am aware of the options syntax
--scope-listopt="+[3,4]"
, but you can't use this on targets, can you? Is there a way to extend fields preserving whatever the default has been assigned by the parent(s)?
c

curved-television-6568

02/03/2023, 6:10 PM
Using
__defaults__
there is no merging going on, but you may preserve rather than replace defaults, using the
extend=True
keyword. See near the end of this section: https://www.pantsbuild.org/docs/targets#field-default-values Using only targets, you can use
Copy code
python_sources(sources=["custom.py", *python_sources.sources.default
From: https://github.com/pantsbuild/pants/pull/17649 N.b. Weโ€™ve not yet updated the docs with that last one.. ๐Ÿ˜ฌ In summary, Iโ€™ve not yet come up with a solution for what you want here.. ๐Ÿ˜•
I realize that it would be cool if
python_sources.tags.default
reflected the current state of
__defaults__
too..
as that would allow you to get what you want ๐Ÿ™‚
f

fresh-cat-90827

02/03/2023, 6:20 PM
oh cool, thanks, Andreas. It feels somewhat like a basic feature that many people would want. I shall probably raise an issue explaining what one may want and possible use cases.
๐Ÿ‘ 1
c

curved-television-6568

02/04/2023, 2:40 PM
2 Views