Split sources into roughly equal chunks. Args: sources: List of source file paths num_chunks: Number of unity chunks to create Returns: List of lists, where each sublist is a chunk of sources
(sources: list[Path], num_chunks: int)
| 63 | |
| 64 | |
| 65 | def chunk_sources(sources: list[Path], num_chunks: int) -> list[list[Path]]: |
| 66 | """ |
| 67 | Split sources into roughly equal chunks. |
| 68 | |
| 69 | Args: |
| 70 | sources: List of source file paths |
| 71 | num_chunks: Number of unity chunks to create |
| 72 | |
| 73 | Returns: |
| 74 | List of lists, where each sublist is a chunk of sources |
| 75 | """ |
| 76 | if num_chunks <= 0: |
| 77 | raise ValueError(f"num_chunks must be > 0, got {num_chunks}") |
| 78 | |
| 79 | if num_chunks > len(sources): |
| 80 | num_chunks = len(sources) |
| 81 | |
| 82 | chunk_size = (len(sources) + num_chunks - 1) // num_chunks # Ceiling division |
| 83 | |
| 84 | chunks: list[list[Path]] = [] |
| 85 | for i in range(0, len(sources), chunk_size): |
| 86 | chunk = sources[i : i + chunk_size] |
| 87 | if chunk: # Only add non-empty chunks |
| 88 | chunks.append(chunk) |
| 89 | |
| 90 | return chunks |
| 91 | |
| 92 | |
| 93 | def generate_unity_file( |
no test coverage detected