in dags/map_reproducibility/utils/file_comparison.py [0:0]
def show_diff(file1_path, file2_path):
"""
Show line differences between two files.
Args:
file1_path (Path): Path to the first file
file2_path (Path): Path to the second file
"""
try:
with open(file1_path, "r") as file1, open(file2_path, "r") as file2:
file1_lines = file1.readlines()
file2_lines = file2.readlines()
diff = list(
difflib.unified_diff(
file1_lines,
file2_lines,
fromfile=str(file1_path),
tofile=str(file2_path),
lineterm="",
)
)
if diff:
print("\n Differences:")
# Only show first 10 diff lines to avoid overwhelming output
for line in diff[:10]:
print(f" {line}")
if len(diff) > 10:
print(f" ... and {len(diff)-10} more lines")
print()
except UnicodeDecodeError:
print(" Cannot display diff (binary file or encoding issue)")
except Exception as e:
print(f" Error displaying diff: {e}")