Various cleanup.

This commit is contained in:
Anthony Sottile 2014-06-06 07:38:25 -07:00
parent bf912cfebb
commit 01b557c497
12 changed files with 85 additions and 37 deletions

View file

@ -29,7 +29,9 @@ logger = logging.getLogger('pre_commit')
def install(runner):
"""Install the pre-commit hooks."""
pre_commit_file = pkg_resources.resource_filename('pre_commit', 'resources/pre-commit.sh')
pre_commit_file = pkg_resources.resource_filename(
'pre_commit', 'resources/pre-commit.sh',
)
with open(runner.pre_commit_path, 'w') as pre_commit_file_obj:
pre_commit_file_obj.write(open(pre_commit_file).read())

View file

@ -29,7 +29,9 @@ def is_in_merge_conflict():
def parse_merge_msg_for_conflicts(merge_msg):
# Conflicted files start with tabs
return [
line.strip() for line in merge_msg.splitlines() if line.startswith('\t')
line.strip()
for line in merge_msg.splitlines()
if line.startswith('\t')
]

View file

@ -9,16 +9,19 @@ from pre_commit.languages import system
# # Use None for no environment
# ENVIRONMENT_DIR = 'foo_env'
#
# def install_environment(repo_cmd_runner):
# def install_environment(repo_cmd_runner, version='default'):
# """Installs a repository in the given repository. Note that the current
# working directory will already be inside the repository.
#
# Args:
# repo_cmd_runner - `PrefixedCommandRunner` bound to the repository.
# version - A version specified in the hook configuration or
# 'default'.
# """
#
# def run_hook(repo_cmd_runner, hook, file_args):
# """Runs a hook and returns the returncode and output of running that hook.
# """Runs a hook and returns the returncode and output of running that
# hook.
#
# Args:
# repo_cmd_runner - `PrefixedCommandRunner` bound to the repository.

View file

@ -26,8 +26,8 @@ def get_hook_message(
>>> print_hook_message('start', end_len=6)
start...............................................................
# Print `start` followed by dots with the end message colored if coloring is
# specified and a newline afterwards
# Print `start` followed by dots with the end message colored if coloring
# is specified and a newline afterwards
>>> print_hook_message(
'start',
end_msg='end',

View file

@ -42,7 +42,12 @@ class PrefixedCommandRunner(object):
will run ['/tmp/foo/foo.sh', 'bar', 'baz']
"""
def __init__(self, prefix_dir, popen=subprocess.Popen, makedirs=os.makedirs):
def __init__(
self,
prefix_dir,
popen=subprocess.Popen,
makedirs=os.makedirs
):
self.prefix_dir = prefix_dir.rstrip(os.sep) + os.sep
self.__popen = popen
self.__makedirs = makedirs

View file

@ -35,9 +35,13 @@ def run(argv):
'--no-stash', default=False, action='store_true',
help='Use this option to prevent auto stashing of unstaged files.',
)
run_parser.add_argument('--verbose', '-v', action='store_true', default=False)
run_parser.add_argument(
'--verbose', '-v', action='store_true', default=False,
)
help = subparsers.add_parser('help', help='Show help for a specific command.')
help = subparsers.add_parser(
'help', help='Show help for a specific command.'
)
help.add_argument('help_cmd', nargs='?', help='Command to show help for.')
# Argparse doesn't really provide a way to use a `default` subparser