From 90c531ce8a139e93a43ba4b5422c8e0ac57decd2 Mon Sep 17 00:00:00 2001
From: williamfzc <178894043@qq.com>
Date: Sun, 5 Jul 2020 13:45:32 +0800
Subject: [PATCH 1/2] feat: support specific output path
---
diff2HtmlCompare.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/diff2HtmlCompare.py b/diff2HtmlCompare.py
index 644ce93..9cc3bed 100644
--- a/diff2HtmlCompare.py
+++ b/diff2HtmlCompare.py
@@ -414,6 +414,7 @@ def show(outputpath):
help='Restrict code to 80 columns wide. (printer friendly in landscape)')
parser.add_argument('-c', '--syntax-css', action='store', default="vs",
help='Pygments CSS for code syntax highlighting. Can be one of: %s' % str(PYGMENTS_STYLES))
+ parser.add_argument('-o', '--output-path', action='store')
parser.add_argument('-v', '--verbose', action='store_true', help='show verbose output.')
parser.add_argument('file1', help='source file to compare ("before" file).')
parser.add_argument('file2', help='source file to compare ("after" file).')
@@ -423,7 +424,7 @@ def show(outputpath):
if args.syntax_css not in PYGMENTS_STYLES:
raise ValueError("Syntax CSS (-c) must be one of %r." % PYGMENTS_STYLES)
- outputpath = "index.html"
+ outputpath = args.output_path or "index.html"
main(args.file1, args.file2, outputpath, args)
if args.show:
show(outputpath)
From bd542a027280cecfbf5eec9b4808d5205064f7ec Mon Sep 17 00:00:00 2001
From: williamfzc <178894043@qq.com>
Date: Sun, 5 Jul 2020 14:17:18 +0800
Subject: [PATCH 2/2] feat: support calling from cmd
---
MANIFEST.in | 6 ++++++
.../__init__.py | 20 ++++++++++++-------
setup.py | 17 ++++++++++++++++
3 files changed, 36 insertions(+), 7 deletions(-)
create mode 100644 MANIFEST.in
rename diff2HtmlCompare.py => diff2HtmlCompare/__init__.py (97%)
create mode 100644 setup.py
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..5071fa5
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,6 @@
+include LICENSE
+include deps
+recursive-exclude * __pycache__
+recursive-exclude * *.pyc
+recursive-exclude * *.pyo
+prune screenshots
diff --git a/diff2HtmlCompare.py b/diff2HtmlCompare/__init__.py
similarity index 97%
rename from diff2HtmlCompare.py
rename to diff2HtmlCompare/__init__.py
index 9cc3bed..3980cd3 100644
--- a/diff2HtmlCompare.py
+++ b/diff2HtmlCompare/__init__.py
@@ -33,7 +33,7 @@
from pygments.token import *
# Monokai is not quite right yet
-PYGMENTS_STYLES = ["vs", "xcode"]
+PYGMENTS_STYLES = ["vs", "xcode"]
HTML_TEMPLATE = """
@@ -134,7 +134,7 @@ class DefaultLexer(RegexLexer):
class DiffHtmlFormatter(HtmlFormatter):
"""
- Formats a single source file with pygments and adds diff highlights based on the
+ Formats a single source file with pygments and adds diff highlights based on the
diff details given.
"""
isLeft = False
@@ -165,6 +165,7 @@ def getDiffLineNos(self):
else:
no = '' + str(left_no) + ""
else:
+ # add coverage here
if change:
if isinstance(left_no, int) and isinstance(right_no, int):
no = '' + \
@@ -403,17 +404,18 @@ def show(outputpath):
path = os.path.abspath(outputpath)
webbrowser.open('file://' + path)
-if __name__ == "__main__":
+
+def cmd():
description = """Given two source files this application\
-creates an html page which highlights the differences between the two. """
+ creates an html page which highlights the differences between the two. """
parser = argparse.ArgumentParser(description=description)
parser.add_argument('-s', '--show', action='store_true',
help='show html in a browser.')
- parser.add_argument('-p', '--print-width', action='store_true',
- help='Restrict code to 80 columns wide. (printer friendly in landscape)')
+ parser.add_argument('-p', '--print-width', action='store_true',
+ help='Restrict code to 80 columns wide. (printer friendly in landscape)')
parser.add_argument('-c', '--syntax-css', action='store', default="vs",
- help='Pygments CSS for code syntax highlighting. Can be one of: %s' % str(PYGMENTS_STYLES))
+ help='Pygments CSS for code syntax highlighting. Can be one of: %s' % str(PYGMENTS_STYLES))
parser.add_argument('-o', '--output-path', action='store')
parser.add_argument('-v', '--verbose', action='store_true', help='show verbose output.')
parser.add_argument('file1', help='source file to compare ("before" file).')
@@ -428,3 +430,7 @@ def show(outputpath):
main(args.file1, args.file2, outputpath, args)
if args.show:
show(outputpath)
+
+
+if __name__ == "__main__":
+ cmd()
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..391ca79
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,17 @@
+import setuptools
+
+with open("requirements.txt") as f:
+ requirements = [each.strip() for each in f.readlines()]
+
+setuptools.setup(
+ name="diff2HtmlCompare",
+ version="0.1.0",
+ url="https://github.com/wagoodman/diff2HtmlCompare",
+ license="MIT",
+ author="wagoodman",
+ packages=setuptools.find_packages(),
+ install_requires=requirements,
+ entry_points={
+ "console_scripts": ["diff2HtmlCompare = diff2HtmlCompare:cmd"]
+ },
+)