MCPcopy
hub / github.com/psf/black / ipynb_diff

Function ipynb_diff

src/black/output.py:42–56  ·  view source on GitHub ↗

Return a unified diff string between each cell in notebooks `a` and `b`.

(a: str, b: str, a_name: str, b_name: str)

Source from the content-addressed store, hash-verified

40
41
42def ipynb_diff(a: str, b: str, a_name: str, b_name: str) -> str:
43 """Return a unified diff string between each cell in notebooks `a` and `b`."""
44 a_nb = json.loads(a)
45 b_nb = json.loads(b)
46 diff_lines = [
47 diff(
48 "".join(a_nb["cells"][cell_number]["source"]) + "\n",
49 "".join(b_nb["cells"][cell_number]["source"]) + "\n",
50 f"{a_name}:cell_{cell_number}",
51 f"{b_name}:cell_{cell_number}",
52 )
53 for cell_number, cell in enumerate(a_nb["cells"])
54 if cell["cell_type"] == "code"
55 ]
56 return "".join(diff_lines)
57
58
59_line_pattern = re.compile(r"(.*?(?:\r\n|\n|\r|$))")

Callers 1

format_file_in_placeFunction · 0.90

Calls 2

diffFunction · 0.85
loadsMethod · 0.80

Tested by

no test coverage detected