MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / write_combined_req_files

Function write_combined_req_files

tools/generate_sbom_requirements.py:36–60  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

34
35
36def 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
63def main() -> None:

Callers 1

mainFunction · 0.85

Calls 3

openMethod · 0.45
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected