mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 12:30:08 -06:00
Fix python 2.6
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import contextlib
|
||||
import subprocess
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.languages import python
|
||||
from pre_commit.prefixed_command_runner import CalledProcessError
|
||||
|
||||
|
||||
NODE_ENV = 'node_env'
|
||||
@@ -38,7 +38,7 @@ def install_environment(repo_cmd_runner):
|
||||
# Try and use the system level node executable first
|
||||
try:
|
||||
python_env.run('nodeenv -n system {{prefix}}{0}'.format(NODE_ENV))
|
||||
except subprocess.CalledProcessError:
|
||||
except CalledProcessError:
|
||||
# TODO: log failure here
|
||||
# cleanup
|
||||
# TODO: local.path(NODE_ENV).delete()
|
||||
|
||||
@@ -4,6 +4,27 @@ import os.path
|
||||
import subprocess
|
||||
|
||||
|
||||
class CalledProcessError(RuntimeError):
|
||||
def __init__(self, returncode, cmd, expected_returncode, output=None):
|
||||
self.returncode = returncode
|
||||
self.cmd = cmd
|
||||
self.expected_returncode = expected_returncode
|
||||
self.output = output
|
||||
|
||||
def __str__(self):
|
||||
return (
|
||||
'Command: {0!r}\n'
|
||||
'Return code: {1}\n'
|
||||
'Expected return code {2}\n',
|
||||
'Output: {3!r}\n'.format(
|
||||
self.cmd,
|
||||
self.returncode,
|
||||
self.expected_returncode,
|
||||
self.output,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def _replace_cmd(cmd, **kwargs):
|
||||
return [part.format(**kwargs) for part in cmd]
|
||||
|
||||
@@ -40,8 +61,8 @@ class PrefixedCommandRunner(object):
|
||||
returncode = proc.returncode
|
||||
|
||||
if retcode is not None and retcode != returncode:
|
||||
raise subprocess.CalledProcessError(
|
||||
returncode, replaced_cmd, output=(stdout, stderr),
|
||||
raise CalledProcessError(
|
||||
returncode, replaced_cmd, retcode, output=(stdout, stderr),
|
||||
)
|
||||
|
||||
return proc.returncode, stdout, stderr
|
||||
|
||||
@@ -6,6 +6,7 @@ import subprocess
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit.prefixed_command_runner import _replace_cmd
|
||||
from pre_commit.prefixed_command_runner import CalledProcessError
|
||||
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
||||
|
||||
|
||||
@@ -129,7 +130,7 @@ def test_exists_does_exist(tmpdir):
|
||||
|
||||
def test_raises_on_error(popen_mock, makedirs_mock):
|
||||
popen_mock.return_value.returncode = 1
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
with pytest.raises(CalledProcessError):
|
||||
instance = PrefixedCommandRunner(
|
||||
'.', popen=popen_mock, makedirs=makedirs_mock,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user