Skip to content

Commit e144c1c

Browse files
docs: mention that when piping xargs may end up invoking Pants goal more than once (#20521)
Documenting the implications of using `xargs` when producing structured data out of Pants goals, see #20462 for context. --------- Co-authored-by: Andreas Stenius <[email protected]>
1 parent 600a67b commit e144c1c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

docs/docs/using-pants/advanced-target-selection.mdx

+9-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Whereas `tags` are useful for _decentralized_ allow/block lists, `--spec-files`
145145
To pipe a Pants run, use your shell's `|` pipe operator and `xargs`:
146146

147147
```bash
148-
pants dependents helloworld/util | xargs pants list
148+
pants dependents helloworld/util | xargs pants list
149149
```
150150

151151
You can, of course, pipe multiple times:
@@ -167,6 +167,14 @@ $ pants dependencies helloworld/util > util_dependencies.txt
167167
$ pants --spec-files=util_dependencies.txt lint
168168
```
169169

170+
Using spec files is also more robust because when piping output of a Pants goal to `xargs`, the specified command
171+
may be invoked by `xargs` as many times as necessary to use up the list of input items.
172+
This may break the structured data output, for instance, when you want to `peek` the targets as JSON:
173+
174+
```bash
175+
$ pants list --filter-target-type=resource :: | xargs pants peek
176+
```
177+
170178
If you don't want to save the output to an actual file—such as to not pollute version control—you can use a variable and a named pipe:
171179

172180
```bash

docs/docs/using-pants/project-introspection.mdx

+4
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ pants dependents helloworld/main.py:lib | xargs pants peek --exclude-defaults
250250
]
251251
```
252252

253+
Keep in mind, however, that the `peek` goal may be invoked by `xargs` as many times as necessary to use up the list
254+
of input items. This may break the structured data output, so it may be safer to use the
255+
[`--spec-files`](../../reference/global-options#spec_files) option.
256+
253257
:::
254258

255259
## `paths` - find dependency paths

0 commit comments

Comments
 (0)