#!/usr/bin/env python3"""Run sibling hash partitions in one lease, retaining compiled artifacts."""from pathlib importPathimport reimport subprocessimport sysdef main(arguments):if (len(arguments) < 8or arguments[:6] != ['nextest', 'run', '--profile', 'fast', '--no-fail-fast', '--partition']): print('paired shards require a fast, non-fail-fast hash partition', file=sys.stderr)return2 part = re.fullmatch(r'hash:([1-9][0-9]*)/([1-9][0-9]*)', arguments[6])ifnot part:return2 number, total = map(int, part.groups())if number > total:return2 wrapper = Path(__file__).with_name('cargo-test-with-one-retry.sh') status = 0 passed = False empty = Falsefor index in (2 * number - 1, 2 * number): command = [*arguments[:6], f'hash:{index}/{2 * total}', *arguments[7:]] print('[cargo-paired-shard] ' + ' '.join(command), flush=True) result = subprocess.run(['bash', str(wrapper), *command]).returncode# Complete both original partitions after a real failure. The retry# wrapper still retries only a missing binary, never a failed case.if result == 4: empty = Trueelif result andnot status: status = resultelif result == 0: passed = Truereturn status or (4if empty andnot passed else0)if __name__ == '__main__': sys.exit(main(sys.argv[1:]))