mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 02:46:52 +00:00
Fix git hook on python 3
We were expecting strings not bytearrays and so we'll make sure we get strings. And yes, unicode strings work just fine with this on python 2.
This commit is contained in:
parent
e2eb1308b1
commit
d3faf6afab
1 changed files with 8 additions and 0 deletions
|
|
@ -81,6 +81,14 @@ def hg_hook(ui, repo, **kwargs):
|
|||
def run(command):
|
||||
p = Popen(command.split(), stdout=PIPE, stderr=PIPE)
|
||||
(stdout, stderr) = p.communicate()
|
||||
# On python 3, subprocess.Popen returns bytes objects which expect
|
||||
# endswith to be given a bytes object or a tuple of bytes but not native
|
||||
# string objects. This is simply less mysterious than using b'.py' in the
|
||||
# endswith method. That should work but might still fail horribly.
|
||||
if hasattr(stdout, 'decode'):
|
||||
stdout = stdout.decode()
|
||||
if hasattr(stderr, 'decode'):
|
||||
stderr = stderr.decode()
|
||||
return (p.returncode, [line.strip() for line in stdout.splitlines()],
|
||||
[line.strip() for line in stderr.splitlines()])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue