|
35 | 35 | Prints a JSON array of `{"key", "name", "paths", "packages"}` for the workflow's |
36 | 36 | matrix (`paths` and `packages` space-separated, in the same order; `packages` are |
37 | 37 | the members' project names, so a job syncs only what its members declare). |
38 | | -`--changed-file` names a file listing the changed paths; omit it for a full run. |
| 38 | +`--changed-file` names a file listing the changed paths, or `-` to read them from stdin; |
| 39 | +omit it for a full run. |
39 | 40 | `--paths` prints the picked member paths one per line instead, for the local |
40 | 41 | `workspace-pytest` hook, so a commit runs the same members a pull request would. |
41 | 42 | """ |
@@ -209,16 +210,18 @@ def batches(paths: list[str], weights: dict[str, int]) -> list[dict[str, str]]: |
209 | 210 | def main(argv: list[str] | None = None) -> int: |
210 | 211 | parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) |
211 | 212 | parser.add_argument("--root", type=Path, default=Path(".")) |
212 | | - parser.add_argument("--changed-file", type=Path, help="file listing a pull request's changed paths") |
| 213 | + parser.add_argument( |
| 214 | + "--changed-file", type=Path, help="file listing a pull request's changed paths, or - for stdin" |
| 215 | + ) |
213 | 216 | parser.add_argument("--paths", action="store_true", help="print the picked member paths, one per line") |
214 | 217 | args = parser.parse_args(argv) |
215 | 218 | changed = None |
216 | 219 | if args.changed_file: |
217 | | - changed = [ |
218 | | - line.strip() |
219 | | - for line in args.changed_file.read_text(encoding="utf-8").splitlines() |
220 | | - if line.strip() |
221 | | - ] |
| 220 | + if str(args.changed_file) == "-": |
| 221 | + raw_lines = sys.stdin.read().splitlines() |
| 222 | + else: |
| 223 | + raw_lines = args.changed_file.read_text(encoding="utf-8").splitlines() |
| 224 | + changed = [line.strip().replace("\\", "/") for line in raw_lines if line.strip()] |
222 | 225 | paths = select(args.root, changed) |
223 | 226 | if args.paths: |
224 | 227 | for path in paths: |
|
0 commit comments