You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/docs/using-pants/key-concepts/targets-and-build-files.mdx
+44
Original file line number
Diff line number
Diff line change
@@ -166,6 +166,50 @@ You can use the prefix `!!` to transitively exclude a dependency, meaning that e
166
166
Transitive excludes can only be used in target types that conventionally are not depended upon by other targets, such as `pex_binary`, `python_distribution`, and `python_test` / `python_tests`. This is meant to limit confusion, as using `!!` in something like a `python_source` / `python_sources` target could result in surprising behavior for everything that depends on it. (Pants will print a helpful error when using `!!` when it's not legal.)
167
167
:::
168
168
169
+
## Using the generic `target`
170
+
171
+
[`target`](../../..reference/targets/target) is a generic target with no specific type.
172
+
It can be used as a generic collection of targets to group related, but distinct targets into one single target.
173
+
174
+
### Referring to a group of targets
175
+
176
+
You could use the generic `target` when you need to group multiple targets to refer to them as a unit
As mentioned above in [BUILD files](./targets-and-build-files.mdx#build-files), most target fields have sensible defaults. And it's easy to override those values on a specific target. But applying the same non-default value on many targets can get unwieldy, error-prone and hard to maintain. Enter `__defaults__`.
Copy file name to clipboardexpand all lines: docs/docs/writing-plugins/the-rules-api/rules-and-the-target-api.mdx
+25-1
Original file line number
Diff line number
Diff line change
@@ -235,7 +235,7 @@ class MyTarget(Target):
235
235
Then, to resolve the addresses, you can use `UnparsedAddressInputs`:
236
236
237
237
```python
238
-
from pants.engine.addresses importAddress, Addresses, UnparsedAddressInputs
238
+
from pants.engine.addresses import Addresses, UnparsedAddressInputs
239
239
from pants.engine.target import Targets
240
240
from pants.engine.rules import Get, rule
241
241
@@ -291,6 +291,30 @@ async def demo(...) -> Foo:
291
291
292
292
`SourceFilesRequest` expects an iterable of `SourcesField` objects. `SourceFiles` has a field `snapshot: Snapshot` with the merged snapshot of all resolved input sources fields.
293
293
294
+
To convert a list of target addresses to existing source file names, you can request `HydratedSources` for every input target:
295
+
296
+
```python
297
+
from itertools import chain
298
+
from pants.engine.addresses import Addresses
299
+
from pants.engine.collection import DeduplicatedCollection
300
+
from pants.engine.rules import Get, MultiGet, rule
301
+
from pants.engine.target import (HydratedSources, HydrateSourcesRequest, SourcesField, UnexpandedTargets)
all_sources =await MultiGet(Get(HydratedSources, HydrateSourcesRequest(tgt.get(SourcesField))) for tgt in targets)
312
+
return ProjectSources(chain.from_iterable(sources.snapshot.files for sources in all_sources))
313
+
```
314
+
315
+
This is often useful when you need to pass target addresses to commands that are not Pants goals and would not
316
+
be able to interpret them properly.
317
+
294
318
### Enabling codegen
295
319
296
320
If you want your plugin to work with code generation, you must set the argument `enable_codegen=True`, along with `for_sources_types` with the types of `SourcesField` you're expecting.
0 commit comments