pants icon indicating copy to clipboard operation
pants copied to clipboard

Visibility rules with tags not working with overrides

Open isra17 opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

Given the following target generator:

# foo/bar/BUILD
python_sources(overrides={"biz.py": dict(tags=["core"])})

and the following visibility rule:

("*", "[//**](core)")

It appears that the visibility rule won't ever match foo/bar/biz.py. Adding tags=["core"] to the generator fixes it.

Diving in Pants source, it seems like the visibility engine is working with TargetAdaptor which represent the generator python_sources and not the final python_source with the override applied.

I'm not that familiar with Pants source and it look like the visibility engine is hooking deep in the dependency engine. Is there strong limitation of why it is not handling the generated targets?

I suppose it could be hacked around by checking the overrides tags if getting the generated target is not possible.

Describe the solution you'd like

I think it would be fair to assume that rules are being run against the generated targets and not the generator.

Do you have any pointer for this? I could try to work out something. I'm trying to setup something so I can rely heavily on tags to define my dependency rules (Make it so that core target can depends on other core targets, etc.)

isra17 avatar Mar 29 '24 19:03 isra17

The issue is that the visibility rules are checked during target instantiation (i.e. when creating the target from the TargetAdaptor) so we'd end up in a loop if we were to rely on the real targets. A possible work-around could be to examine the overrides field to dig out the tags field to apply it more fine-grained.

Do you need this level separation?

This could likely be better clarified in the docs, too..

kaos avatar Apr 08 '24 08:04 kaos