55import sys
66
77from pre_commit import git
8- from pre_commit .clientlib .validate_config import validate_config
9- from pre_commit .repository import Repository
8+ from pre_commit .runner import Runner
109from pre_commit .util import entry
1110
1211
1514NORMAL = '\033 [0m'
1615COLS = int (subprocess .Popen (['tput' , 'cols' ], stdout = subprocess .PIPE ).communicate ()[0 ])
1716
17+ PASS_FAIL_LENGTH = 6
18+
1819
1920def _run_single_hook (repository , hook_id , run_all_the_things = False ):
2021 repository .install ()
@@ -26,6 +27,13 @@ def _run_single_hook(repository, hook_id, run_all_the_things=False):
2627
2728 hook = repository .hooks [hook_id ]
2829
30+ # Print the hook and the dots first in case the hook takes hella long to
31+ # run.
32+ print '{0}{1}' .format (
33+ hook ['name' ],
34+ '.' * (COLS - len (hook ['name' ]) - PASS_FAIL_LENGTH - 6 ),
35+ ),
36+
2937 retcode , stdout , stderr = repository .run_hook (
3038 hook_id ,
3139 map (os .path .abspath , get_filenames (hook ['files' ])),
@@ -43,13 +51,7 @@ def _run_single_hook(repository, hook_id, run_all_the_things=False):
4351 pass_fail = 'Passed'
4452
4553
46- print '{0}{1}{2}{3}{4}' .format (
47- hook ['name' ],
48- '.' * (COLS - len (hook ['name' ]) - len (pass_fail ) - 6 ),
49- color ,
50- pass_fail ,
51- NORMAL ,
52- )
54+ print '{0}{1}{2}' .format (color , pass_fail , NORMAL )
5355
5456 if output :
5557 print
@@ -63,9 +65,8 @@ def run_hooks(run_all_the_things=False):
6365 """Actually run the hooks."""
6466 retval = 0
6567
66- configs = validate_config ([])
67- for config in configs :
68- repo = Repository (config )
68+ runner = Runner .create ()
69+ for repo in runner .repositories :
6970 for hook_id in repo .hooks :
7071 retval |= _run_single_hook (
7172 repo ,
@@ -76,10 +77,9 @@ def run_hooks(run_all_the_things=False):
7677 return retval
7778
7879
79- def run_single_hook (hook_id , configs = None , run_all_the_things = False ):
80- configs = configs or validate_config ([])
81- for config in configs :
82- repo = Repository (config )
80+ def run_single_hook (hook_id , run_all_the_things = False ):
81+ runner = Runner .create ()
82+ for repo in runner .repositories :
8383 if hook_id in repo .hooks :
8484 return _run_single_hook (
8585 repo ,
0 commit comments