texdiff 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- texdiff/__init__.py +45 -0
- texdiff/align.py +202 -0
- texdiff/api.py +326 -0
- texdiff/check.py +61 -0
- texdiff/cli.py +87 -0
- texdiff/emit.py +1193 -0
- texdiff/flatten.py +185 -0
- texdiff/nodes.py +147 -0
- texdiff/oldlines.py +49 -0
- texdiff/parse.py +524 -0
- texdiff/preamble.py +388 -0
- texdiff/tables.py +540 -0
- texdiff/textdiff.py +157 -0
- texdiff-0.2.0.dist-info/METADATA +112 -0
- texdiff-0.2.0.dist-info/RECORD +19 -0
- texdiff-0.2.0.dist-info/WHEEL +5 -0
- texdiff-0.2.0.dist-info/entry_points.txt +2 -0
- texdiff-0.2.0.dist-info/licenses/LICENSE +21 -0
- texdiff-0.2.0.dist-info/top_level.txt +1 -0
texdiff/cli.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Command line interface: ``texdiff OLD.tex NEW.tex`` → marked-up diff.tex."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from . import __version__
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
12
|
+
parser = argparse.ArgumentParser(
|
|
13
|
+
prog="texdiff",
|
|
14
|
+
description="AST-driven semantic diff for LaTeX documents.",
|
|
15
|
+
)
|
|
16
|
+
parser.add_argument("old", help="old revision .tex file")
|
|
17
|
+
parser.add_argument("new", help="new revision .tex file")
|
|
18
|
+
parser.add_argument("-o", "--output", default="-", help="output path (default: stdout)")
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"--stats",
|
|
21
|
+
action="store_true",
|
|
22
|
+
help="print change statistics to stderr",
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"--check",
|
|
26
|
+
action="store_true",
|
|
27
|
+
help="compile the marked-up diff once and exit non-zero on failure",
|
|
28
|
+
)
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
"--workdir",
|
|
31
|
+
default=None,
|
|
32
|
+
help="scratch directory for --check (default: temp dir)",
|
|
33
|
+
)
|
|
34
|
+
parser.add_argument(
|
|
35
|
+
"--version",
|
|
36
|
+
action="version",
|
|
37
|
+
version=f"%(prog)s {__version__}",
|
|
38
|
+
)
|
|
39
|
+
return parser
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def main(argv: list[str] | None = None) -> int:
|
|
43
|
+
args = build_parser().parse_args(argv)
|
|
44
|
+
|
|
45
|
+
from .api import diff_files
|
|
46
|
+
|
|
47
|
+
if args.check:
|
|
48
|
+
from pathlib import Path
|
|
49
|
+
|
|
50
|
+
from .check import check_compiles
|
|
51
|
+
|
|
52
|
+
workdir = Path(args.workdir) if args.workdir else None
|
|
53
|
+
ok, log = check_compiles(args.old, args.new, work_dir=workdir)
|
|
54
|
+
if not ok:
|
|
55
|
+
print("texdiff --check FAILED: marked-up diff does not compile", file=sys.stderr)
|
|
56
|
+
for line in log.splitlines():
|
|
57
|
+
if line.startswith("!") or "l." in line[:3]:
|
|
58
|
+
print(line, file=sys.stderr)
|
|
59
|
+
return 2
|
|
60
|
+
print("texdiff --check OK: diff compiles", file=sys.stderr)
|
|
61
|
+
if args.output != "-":
|
|
62
|
+
from pathlib import Path
|
|
63
|
+
|
|
64
|
+
result = diff_files(args.old, args.new)
|
|
65
|
+
Path(args.output).write_text(result.marked_up, encoding="utf-8")
|
|
66
|
+
if args.stats:
|
|
67
|
+
result = diff_files(args.old, args.new)
|
|
68
|
+
print(result.stats, file=sys.stderr)
|
|
69
|
+
return 0
|
|
70
|
+
|
|
71
|
+
result = diff_files(args.old, args.new)
|
|
72
|
+
|
|
73
|
+
if args.output == "-":
|
|
74
|
+
sys.stdout.write(result.marked_up)
|
|
75
|
+
else:
|
|
76
|
+
from pathlib import Path
|
|
77
|
+
|
|
78
|
+
Path(args.output).write_text(result.marked_up, encoding="utf-8")
|
|
79
|
+
|
|
80
|
+
if args.stats:
|
|
81
|
+
print(result.stats, file=sys.stderr)
|
|
82
|
+
|
|
83
|
+
return 0
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
raise SystemExit(main())
|