Coverage for class_generator/formatters/file_writer.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.10.1, created at 2025-07-29 12:31 +0300

1"""File writing and formatting utilities for generated code.""" 

2 

3import shlex 

4 

5from pyhelper_utils.shell import run_command 

6 

7 

8def write_and_format_rendered(filepath: str, output: str) -> None: 

9 """ 

10 Write rendered content to file and format it with ruff. 

11  

12 Args: 

13 filepath: Path to write the file to 

14 output: Content to write 

15 """ 

16 with open(filepath, "w") as fd: 

17 fd.write(output) 

18 

19 for op in ("format", "check"): 

20 run_command( 

21 command=shlex.split(f"uvx ruff {op} {filepath}"), 

22 verify_stderr=False, 

23 check=False, 

24 )