~amirouche/mutation

7675b24e7cf78da17b4118de8b6f5d28ece7d704 — Amirouche 7 months ago 14d1441
improve diff highlighting.
3 files changed, 45 insertions(+), 46 deletions(-)

M mutation.py
M poetry.lock
M pyproject.toml
M mutation.py => mutation.py +30 -2
@@ 33,6 33,10 @@ from difflib import unified_diff
from pathlib3x import Path
from uuid import UUID

import pygments
import pygments.formatters
import pygments.lexers
from termcolor import colored
import lexode
import parso
import zstandard as zstd


@@ 972,8 976,32 @@ def mutation_show(uid):
    with database_open(".") as db:
        path, diff = lexode.unpack(db[lexode.pack([1, uid])])
    diff = zstd.decompress(diff).decode("utf8")
    for line in diff.split("\n"):
        log.info(line)

    terminal256 = pygments.formatters.get_formatter_by_name('terminal256')
    python = pygments.lexers.get_lexer_by_name('python')

    print(diff)

    for line in diff.split('\n'):
        if line.startswith("+++"):
            delta = colored("+++", "green", attrs=["bold"])
            highlighted = pygments.highlight(line[3:], python, terminal256)
            log.info(delta + highlighted.rstrip())
        elif line.startswith("---"):
            delta = colored("---", "red", attrs=["bold"])
            highlighted = pygments.highlight(line[3:], python, terminal256)
            log.info(delta + highlighted.rstrip())
        elif line.startswith("+"):
            delta = colored("+", "green", attrs=["bold"])
            highlighted = pygments.highlight(line[1:], python, terminal256)
            log.info(delta + highlighted.rstrip())
        elif line.startswith("-"):
            delta = colored("-", "red", attrs=["bold"])
            highlighted = pygments.highlight(line[1:], python, terminal256)
            log.info(delta + highlighted.rstrip())
        else:
            highlighted = pygments.highlight(line, python, terminal256)
            log.info(highlighted.rstrip())


def mutation_apply(uid):

M poetry.lock => poetry.lock +13 -44
@@ 185,28 185,6 @@ apipkg = ">=1.4"
testing = ["pre-commit"]

[[package]]
name = "gitdb"
version = "4.0.5"
description = "Git Object Database"
category = "main"
optional = false
python-versions = ">=3.4"

[package.dependencies]
smmap = ">=3.0.1,<4"

[[package]]
name = "gitpython"
version = "3.1.12"
description = "Python Git Library"
category = "main"
optional = false
python-versions = ">=3.4"

[package.dependencies]
gitdb = ">=4.0.1,<5"

[[package]]
name = "humanize"
version = "3.2.0"
description = "Python humanize utilities"


@@ 473,7 451,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
name = "pygments"
version = "2.7.4"
description = "Pygments is a syntax highlighting package written in Python."
category = "dev"
category = "main"
optional = false
python-versions = ">=3.5"



@@ 596,14 574,6 @@ optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"

[[package]]
name = "smmap"
version = "3.0.5"
description = "A pure Python implementation of a sliding window memory map manager"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"

[[package]]
name = "tbvaccine"
version = "0.3.1"
description = "A utility that cures the horrible traceback displays in Python, making them more readable."


@@ 615,6 585,14 @@ python-versions = "*"
pygments = "*"

[[package]]
name = "termcolor"
version = "1.1.0"
description = "ANSII Color formatting for output in terminal."
category = "main"
optional = false
python-versions = "*"

[[package]]
name = "toml"
version = "0.10.2"
description = "Python Library for Tom's Obvious, Minimal Language"


@@ 712,7 690,7 @@ cffi = ["cffi (>=1.11)"]
[metadata]
lock-version = "1.1"
python-versions = "^3.7"
content-hash = "217757e0499e27be847632b730cf1af5684b3287be8765ffed9c92dac3608b08"
content-hash = "4d65a2aa49bb84f8944ede02862af51a426532ed5275960538aac149d56cd026"

[metadata.files]
aiostream = [


@@ 868,14 846,6 @@ execnet = [
    {file = "execnet-1.7.1-py2.py3-none-any.whl", hash = "sha256:d4efd397930c46415f62f8a31388d6be4f27a91d7550eb79bc64a756e0056547"},
    {file = "execnet-1.7.1.tar.gz", hash = "sha256:cacb9df31c9680ec5f95553976c4da484d407e85e41c83cb812aa014f0eddc50"},
]
gitdb = [
    {file = "gitdb-4.0.5-py3-none-any.whl", hash = "sha256:91f36bfb1ab7949b3b40e23736db18231bf7593edada2ba5c3a174a7b23657ac"},
    {file = "gitdb-4.0.5.tar.gz", hash = "sha256:c9e1f2d0db7ddb9a704c2a0217be31214e91a4fe1dea1efad19ae42ba0c285c9"},
]
gitpython = [
    {file = "GitPython-3.1.12-py3-none-any.whl", hash = "sha256:867ec3dfb126aac0f8296b19fb63b8c4a399f32b4b6fafe84c4b10af5fa9f7b5"},
    {file = "GitPython-3.1.12.tar.gz", hash = "sha256:42dbefd8d9e2576c496ed0059f3103dcef7125b9ce16f9d5f9c834aed44a1dac"},
]
humanize = [
    {file = "humanize-3.2.0-py3-none-any.whl", hash = "sha256:d47d80cd47c1511ed3e49ca5f10c82ed940ea020b45b49ab106ed77fa8bb9d22"},
    {file = "humanize-3.2.0.tar.gz", hash = "sha256:ab69004895689951b79f2ae4fdd6b8127ff0c180aff107856d5d98119a33f026"},


@@ 1053,14 1023,13 @@ six = [
    {file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"},
    {file = "six-1.15.0.tar.gz", hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"},
]
smmap = [
    {file = "smmap-3.0.5-py2.py3-none-any.whl", hash = "sha256:7bfcf367828031dc893530a29cb35eb8c8f2d7c8f2d0989354d75d24c8573714"},
    {file = "smmap-3.0.5.tar.gz", hash = "sha256:84c2751ef3072d4f6b2785ec7ee40244c6f45eb934d9e543e2c51f1bd3d54c50"},
]
tbvaccine = [
    {file = "tbvaccine-0.3.1-py2.py3-none-any.whl", hash = "sha256:3aae41b75e237f2840dde274722b1070ca43d65dd24cf60344bd6d345c77cc3d"},
    {file = "tbvaccine-0.3.1.tar.gz", hash = "sha256:8665d037ac8ad4c97bc44512de91798565b1226f7b2f59669bb7dbe9a1f87718"},
]
termcolor = [
    {file = "termcolor-1.1.0.tar.gz", hash = "sha256:1d6d69ce66211143803fbc56652b41d73b4a400a2891d7bf7a1cdf4c02de613b"},
]
toml = [
    {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
    {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},

M pyproject.toml => pyproject.toml +2 -0
@@ 23,6 23,8 @@ astunparse = "^1.6.3"
tqdm = "^4.56.0"
pytest = "^6.2.1"
pathlib3x = "^1.3.9"
Pygments = "^2.7.4"
termcolor = "^1.1.0"

[tool.poetry.dev-dependencies]
debug = "^0.3.2"