mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Compute win32 python2 length according to encoded size
This commit is contained in:
parent
3d573d8736
commit
ead906aed0
2 changed files with 43 additions and 25 deletions
|
|
@ -3,6 +3,8 @@ from __future__ import unicode_literals
|
|||
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
from pre_commit import parse_shebang
|
||||
from pre_commit.util import cmd_output
|
||||
|
||||
|
|
@ -19,9 +21,13 @@ def _command_length(*cmd):
|
|||
# win32 uses the amount of characters, more details at:
|
||||
# https://github.com/pre-commit/pre-commit/pull/839
|
||||
if sys.platform == 'win32':
|
||||
return len(full_cmd.encode('utf-16le')) // 2
|
||||
|
||||
return len(full_cmd.encode(sys.getfilesystemencoding()))
|
||||
# the python2.x apis require bytes, we encode as UTF-8
|
||||
if six.PY2:
|
||||
return len(full_cmd.encode('utf-8'))
|
||||
else:
|
||||
return len(full_cmd.encode('utf-16le')) // 2
|
||||
else:
|
||||
return len(full_cmd.encode(sys.getfilesystemencoding()))
|
||||
|
||||
|
||||
class ArgumentTooLongError(RuntimeError):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue