pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.33k stars 638 forks source link

Explicitly declared atom/single-file targets use target addresses rather than file addresses #14419

Open stuhood opened 2 years ago

stuhood commented 2 years ago

An explicitly declared target like:

# in example/BUILD
python_source(name='example', source='file.py')

...will have an Address of example:example, rather than the Address it would have if it had been created by a python_sources generator: example/file.py.

We have affordances in the code to allow looking up this kind of target using a file address, but ideally we would change the actual address of the target. There are open questions about that, particularly around collisions with other targets: removing the requirement that a target be named would go a long way though.

Eric-Arellano commented 2 years ago

I don't agree with this one. It makes addresses even more complex, and introduces a risk for ambiguity.

We generally encourage using target generators, so I expect the surface area of this to be small.

stuhood commented 2 years ago

I don't agree with this one. It makes addresses even more complex, and introduces a risk for ambiguity.

We generally encourage using target generators, so I expect the surface area of this to be small.

I haven't read the update from https://docs.google.com/document/d/1jSCJ3pwvIMg5duafsr8KmiLOO_2ARMaYCSrb8K85JQc/edit# (excited about it: will try to today/tomorrow), but if the name becomes optional, wouldn't this need to have a file address?

Eric-Arellano commented 2 years ago

but if the name becomes optional, wouldn't this need to have a file address?

No, because these are explicitly declared atom targets. Only generated targets can have the name= missing.

That keeps our rules much simpler and predictable:

Reminder that we don't really encourage users to explicitly create atom targets - you had me rewrite the docs to bias towards generators, which I support. And tailor encourages you to use generators.

stuhood commented 2 years ago

That keeps our rules much simpler and predictable:

  • any explicitly declared atom target must have a name, e.g. python_requirement and python_source. No need to teach that sometimes you can, sometimes you can't.

  • so, if name= is missing, you know it's a target generator

That doesn't seem simpler than explaining that:

cognifloyd commented 1 year ago

This also applies to target generators if the glob matches only one file.

I've done some dependencies --transitive + grep stuff where I filtered out anything with : because I only wanted the list of files. I had to stop filtering : once I realized that some targets were getting excluded.