Concatenate requirement files and write to outname file. Args: root (Path): The root directory of the repository. files (list[Path]): A list of Paths to requirement files to include in the SBOM. outname (str): The name of the output file. Raises: RuntimeErro
(root: Path, files: list[Path], outname: str)
| 34 | |
| 35 | |
| 36 | def write_combined_req_files(root: Path, files: list[Path], outname: str) -> Path: |
| 37 | """Concatenate requirement files and write to outname file. |
| 38 | |
| 39 | Args: |
| 40 | root (Path): The root directory of the repository. |
| 41 | files (list[Path]): A list of Paths to requirement files to include in the SBOM. |
| 42 | outname (str): The name of the output file. |
| 43 | |
| 44 | Raises: |
| 45 | RuntimeError: If writing to the output file fails. |
| 46 | |
| 47 | Returns: |
| 48 | Path: The path to the output file. |
| 49 | """ |
| 50 | outpath = root / outname |
| 51 | try: |
| 52 | with outpath.open("w", encoding="utf-8") as f: |
| 53 | for p in files: |
| 54 | with p.open("r", encoding="utf-8") as r: |
| 55 | content = r.read().rstrip() |
| 56 | if content: |
| 57 | f.write(content + "\n") |
| 58 | return outpath |
| 59 | except Exception as e: |
| 60 | raise RuntimeError(f"Failed to write {outpath}: {e}") from e |
| 61 | |
| 62 | |
| 63 | def main() -> None: |