From 6c2758ebda79bd01c6772a6e8eadbe710ba2213a Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Wed, 15 Jun 2022 15:35:29 -0500 Subject: [PATCH] chore: add comparison to default settings --- .pre-commit-config.yaml | 2 +- Makefile | 10 ++++- docs/rich-diff.md | 67 +++++++++++++++++++++++++++++++++ scripts/code_svg_format_diff.py | 54 ++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 docs/rich-diff.md create mode 100755 scripts/code_svg_format_diff.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index da16308..3b38bb5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: rev: v4.1.0 hooks: - id: trailing-whitespace - exclude: ".svg$" + exclude: "(.*svg$|docs/rich-diff.md)" - id: end-of-file-fixer - id: check-added-large-files - repo: https://github.com/pycqa/isort diff --git a/Makefile b/Makefile index 4f0b63a..7653155 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SRC_FILES = $(wildcard yartsu/*) -.PHONY: list lint build svg-docs theme-docs docs typing format dist check-tag +.PHONY: list lint build typing format dist check-tag lint: format typing @@ -37,11 +37,16 @@ build/yartsu: $(SRC_FILES) install-bin: build/yartsu cp ./build/yartsu ~/bin -docs: svg-docs theme-docs demo-docs +.PHONY: svg-docs theme-docs diff-docs demo-docs docs + +docs: svg-docs theme-docs demo-docs diff-docs theme-docs: ./scripts/theme-showcase-gen +diff-docs: + ./scripts/code_svg_format_diff.py > docs/rich-diff.md + svg-docs: lolcat -F .5 -S 9 -f assets/logo.txt | yartsu -o assets/logo.svg yartsu -o assets/yartsu.svg -t "yartsu --help" -- yartsu -h @@ -53,6 +58,7 @@ demo-docs: console.print('\n:snake: [b i]Emoji\'s!'); \ console.print(' [cyan]Nerd Fonts!');" \ | yartsu -w 25 -o assets/demo.svg + clean: rm -rf build dist diff --git a/docs/rich-diff.md b/docs/rich-diff.md new file mode 100644 index 0000000..6eb2e35 --- /dev/null +++ b/docs/rich-diff.md @@ -0,0 +1,67 @@ + +# Deviation From Rich + +## Versions + +- Rich: 12.4.4 +- Yartsu: 22.6b2.dev2+gabdbc1d + +## Diff + +```diff +--- ++++ +@@ -1,47 +1,39 @@ + + + +- + + + + + {lines} + +- + {chrome} + + {backgrounds} + +``` + +AUTO-GENERATED by code_svg_format_diff.py diff --git a/scripts/code_svg_format_diff.py b/scripts/code_svg_format_diff.py new file mode 100755 index 0000000..cda092d --- /dev/null +++ b/scripts/code_svg_format_diff.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +from importlib.metadata import version + +from rich._export_format import CONSOLE_SVG_FORMAT as DEFAULT + +from yartsu._export_format import CONSOLE_SVG_FORMAT as MODIFIED + +MARKDOWN_DOC = """ +# Deviation From Rich + +## Versions + +- Rich: {rich_version} +- Yartsu: {yartsu_version} + +## Diff + +```diff +{diff} +``` + +AUTO-GENERATED by code_svg_format_diff.py""" + + +def unidiff_output(expected, actual): + """ + Helper function. Returns a string containing the unified diff of two multiline strings. + """ + # see https://stackoverflow.com/questions/845276/how-to-print-the-comparison-of-two-multiline-strings-in-unified-diff-format + + import difflib + + expected = expected.splitlines(1) + actual = actual.splitlines(1) + + diff = difflib.unified_diff(expected, actual) + + return "".join(diff) + + +def main(): + + print( + MARKDOWN_DOC.format( + rich_version=version("rich"), + yartsu_version=version("yartsu"), + diff=unidiff_output(DEFAULT, MODIFIED), + ) + ) + + +if __name__ == "__main__": + main()