Coverage for  / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / codegen / emit / diff.py: 80%

5 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-10-25 05:45 +0800

1# Copyright 2026 Huawei Technologies Co., Ltd 

2# Licensed under the Apache License, Version 2.0 

3# ============================================================================ 

4"""Generate a unified diff between the original and generated modeling files. 

5 

6Kept separate from ``emit.modeling`` so the diff writer can be reused by a 

7CLI / review tool without pulling in the file-format logic. 

8""" 

9from __future__ import annotations 

10 

11import difflib 

12 

13 

14def unified_diff( 

15 original: str, 

16 generated: str, 

17 fromfile: str, 

18 tofile: str, 

19) -> str: 

20 """Return a unified diff from ``original`` to ``generated``. 

21 

22 Both inputs are the full source text. ``fromfile``/``tofile`` become the 

23 diff headers (e.g. ``modeling_deepseek_v3.py`` and 

24 ``modeling_deepseek_v3_gen_npu.py``). An empty result means the two files 

25 are identical. 

26 """ 

27 return "".join( 

28 difflib.unified_diff( 

29 original.splitlines(keepends=True), 

30 generated.splitlines(keepends=True), 

31 fromfile=fromfile, 

32 tofile=tofile, 

33 ) 

34 ) 

35 

36 

37__all__ = ["unified_diff"]