icdiff
icdiff copied to clipboard
APIs?
Sorry, haven't noticed this: #105
I reopen this because I found the APIs are not so convenient to be integrated. For example, if I want to compare two files in my program, I have to modify the sys.argv to get default options:
def _getIcOptions():
origargv = [arg for arg in sys.argv]
options = icdiff.get_options()[0]
sys.argv = origargv
return options
def ndiff(a, b, linejunk=None, charjunk=difflib.IS_CHARACTER_JUNK):
options = _getIcOptions()
cd = icdiff.ConsoleDiff(
cols = int(options.cols),
show_all_spaces = options.show_all_spaces,
highlight = options.highlight,
line_numbers = options.line_numbers,
tabsize = int(options.tabsize)
)
with warnings.catch_warnings():
warnings.simplefilter('ignore')
for line in cd.make_table(
a, b, 'First', 'Second',
context=(not options.whole_file),
numlines=int(options.unified)):
line = "%s\n" % line
yield line.encode(options.output_encoding)
Can you just use the difflib api? What sort of program do you have that you want to invoke icdiff via api?
(In general, icdiff is trying to be a tool for users to invoke directly)
@jeffkaufman I understand. But the reason (the beauty of line-by-line comparison and colorized output) why I replaced diff with icdiff is also the reason I want to replace difflib with "icdifflib". Let's say a simple scenario would be enhancing messages of unittest, which originally uses difflib.
Thinking about this, it's fine with me if someone wants to make a PR to add API support.