mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2025-08-15 01:54:44 +08:00
Remove dependency on plumbum
This commit is contained in:
@ -2,10 +2,26 @@ from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from plumbum import local
|
||||
import subprocess
|
||||
|
||||
|
||||
class CalledProcessError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def added_files():
|
||||
return set(local['git'](
|
||||
'diff', '--staged', '--name-only', '--diff-filter', 'A',
|
||||
return set(cmd_output(
|
||||
'git', 'diff', '--staged', '--name-only', '--diff-filter', 'A',
|
||||
).splitlines())
|
||||
|
||||
|
||||
def cmd_output(*cmd, **kwargs):
|
||||
retcode = kwargs.pop('retcode', 0)
|
||||
popen_kwargs = {'stdout': subprocess.PIPE, 'stderr': subprocess.PIPE}
|
||||
popen_kwargs.update(kwargs)
|
||||
proc = subprocess.Popen(cmd, **popen_kwargs)
|
||||
stdout, stderr = proc.communicate()
|
||||
stdout, stderr = stdout.decode('UTF-8'), stderr.decode('UTF-8')
|
||||
if retcode is not None and proc.returncode != retcode:
|
||||
raise CalledProcessError(cmd, retcode, proc.returncode, stdout, stderr)
|
||||
return stdout
|
||||
|
Reference in New Issue
Block a user