From c1d367b89a95277b25c8e3cffc0b82fb4d081fa0 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Mon, 28 Jun 2021 12:18:30 +0300 Subject: Add a diffing function For now the diff function uses the Linux tool "diff" to generate the diff since it is efficient and straightforward. * gn3/computations/diff.py (generate_diff): New function. * tests/unit/computations/test_diff.py: Test cases for ☝🏾. --- gn3/computations/diff.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 gn3/computations/diff.py (limited to 'gn3') diff --git a/gn3/computations/diff.py b/gn3/computations/diff.py new file mode 100644 index 0000000..b5da68a --- /dev/null +++ b/gn3/computations/diff.py @@ -0,0 +1,12 @@ +"""This module contains code that's used for generating diffs""" +from typing import Optional + +from gn3.commands import run_cmd + + +def generate_diff(data: str, edited_data: str) -> Optional[str]: + """Generate the diff between 2 files""" + results = run_cmd(f"diff {data} {edited_data}") + if results.get("code", -1) > 0: + return results.get("output") + return None -- cgit v1.2.3