Hi all,
I’m a bit stymied by an issue I’m encountering that seems to do with the ST3 version of python or environment, because it doesn’t happen when trying the same function in the Python 3 REPL. I’m doing some work with git and passing it a diff file to stage. Here’s the relevant code:
new_diff = "\n".join("\n".join(hunk) for i, hunk in enumerate(chunk(lines(diff))) if i in choices)
if final_line and new_diff.splitlines()-1] != final_line:
new_diff += (u"\n" + final_line)
p = subprocess.Popen('git', 'apply', '--cached', '--recount', '--allow-overlap'], stderr=subprocess.STDOUT, stdin=subprocess.PIPE, universal_newlines=True)
p.communicate(input=new_diff)
In the REPL, that does what is intended - it stages a git commit with the diff file that I pass. In Sublime Text 3, the same code fails with the following error:
UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in position 106: ordinal not in range(128)
So something in Sublime Text is assuming that one of my unicode strings is ascii—which is surprising to me, since Python 3 is unicode throughout. I would pass the diff as utf-8 encoded bytes, but subprocess needs a str, not bytes. Does anyone have a suggestion to deal with this issue?