Allow arbitrary bytes in output. Resolves #245 · precommit/pre-commit@66b1d39 · GitHub
Skip to content

Commit 66b1d39

Browse files
committed
Allow arbitrary bytes in output. Resolves pre-commit#245
1 parent 826aa4c commit 66b1d39

11 files changed

Lines changed: 104 additions & 50 deletions

File tree

pre_commit/commands/run.py

Lines changed: 2 additions & 1 deletion

pre_commit/languages/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def run_hook(env, hook, file_args):
2222
' '.join(['xargs', '-0', '-s4000', hook['entry']] + quoted_args),
2323
stdin=file_args_to_stdin(file_args),
2424
retcode=None,
25+
encoding=None,
2526
)
2627

2728

pre_commit/languages/pcre.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ def run_hook(repo_cmd_runner, hook, file_args):
2424
],
2525
stdin=file_args_to_stdin(file_args),
2626
retcode=None,
27+
encoding=None,
2728
)

pre_commit/languages/script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ def run_hook(repo_cmd_runner, hook, file_args):
1717
# TODO: this is duplicated in pre_commit/languages/helpers.py
1818
stdin=file_args_to_stdin(file_args),
1919
retcode=None,
20+
encoding=None,
2021
)

pre_commit/languages/system.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ def run_hook(repo_cmd_runner, hook, file_args):
1818
['xargs', '-0'] + shlex.split(hook['entry']) + hook['args'],
1919
stdin=file_args_to_stdin(file_args),
2020
retcode=None,
21+
encoding=None,
2122
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- id: python3-hook
2+
name: Python 3 Hook
3+
entry: python3-hook
4+
language: python
5+
language_version: python3.3
6+
files: \.py$

testing/resources/arbitrary_bytes_repo/python3_hook/__init__.py

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import print_function
3+
from __future__ import unicode_literals
4+
5+
import sys
6+
7+
8+
def func():
9+
# Intentionally write mixed encoding to the output. This should not crash
10+
# pre-commit and should write bytes to the output.
11+
sys.stdout.buffer.write('☃'.encode('UTF-8') + '²'.encode('latin1') + b'\n')
12+
# Return 1 to trigger printing
13+
return 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from setuptools import find_packages
2+
from setuptools import setup
3+
4+
setup(
5+
name='python3_hook',
6+
version='0.0.0',
7+
packages=find_packages('.'),
8+
entry_points={
9+
'console_scripts': ['python3-hook = python3_hook.main:func'],
10+
},
11+
)

tests/commands/run_test.py

Lines changed: 43 additions & 27 deletions

0 commit comments

Comments
 (0)