Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIs? #131

Open
pwwang opened this issue Apr 25, 2018 · 5 comments
Open

APIs? #131

pwwang opened this issue Apr 25, 2018 · 5 comments

Comments

@pwwang
Copy link

pwwang commented Apr 25, 2018

icdiff is great!
But do we have any plans to expose the APIs like difflib?

@pwwang
Copy link
Author

pwwang commented Apr 25, 2018

Sorry, haven't noticed this: #105

@pwwang pwwang closed this as completed Apr 25, 2018
@pwwang
Copy link
Author

pwwang commented May 1, 2018

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)

@pwwang pwwang reopened this May 1, 2018
@jeffkaufman
Copy link
Owner

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)

@pwwang
Copy link
Author

pwwang commented May 1, 2018

@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.

@jeffkaufman
Copy link
Owner

Thinking about this, it's fine with me if someone wants to make a PR to add API support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants