Skip to content

Commit 01b557c

Browse files
committed
Various cleanup.
1 parent bf912cf commit 01b557c

File tree

12 files changed

+85
-37
lines changed

12 files changed

+85
-37
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@
22
sha: 7c003425b35fff516c0ee88f4040c8c208d474bd
33
hooks:
44
- id: trailing-whitespace
5-
files: \.(js|rb|md|py|sh|txt|yaml|yml)$
65
- id: end-of-file-fixer
7-
files: \.(js|rb|md|py|sh|txt|yaml|yml)$
86
- id: check-yaml
9-
files: \.(yaml|yml)$
107
- id: debug-statements
11-
files: \.py$
128
- id: name-tests-test
13-
files: tests/.+\.py$
149
- id: flake8
15-
files: \.py$
16-
args:
17-
- --max-line-length=131
1810
- repo: git@github.com:pre-commit/pre-commit
1911
sha: 96174deac671b451ee2a3fbdc647ad9606415e15
2012
hooks:
2113
- id: validate_config
22-
files: ^\.pre-commit-config.yaml$
2314
- id: validate_manifest
24-
files: ^hooks.yaml$

pre_commit/commands.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
def install(runner):
3131
"""Install the pre-commit hooks."""
32-
pre_commit_file = pkg_resources.resource_filename('pre_commit', 'resources/pre-commit.sh')
32+
pre_commit_file = pkg_resources.resource_filename(
33+
'pre_commit', 'resources/pre-commit.sh',
34+
)
3335
with open(runner.pre_commit_path, 'w') as pre_commit_file_obj:
3436
pre_commit_file_obj.write(open(pre_commit_file).read())
3537

pre_commit/git.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def is_in_merge_conflict():
2929
def parse_merge_msg_for_conflicts(merge_msg):
3030
# Conflicted files start with tabs
3131
return [
32-
line.strip() for line in merge_msg.splitlines() if line.startswith('\t')
32+
line.strip()
33+
for line in merge_msg.splitlines()
34+
if line.startswith('\t')
3335
]
3436

3537

pre_commit/languages/all.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99
# # Use None for no environment
1010
# ENVIRONMENT_DIR = 'foo_env'
1111
#
12-
# def install_environment(repo_cmd_runner):
12+
# def install_environment(repo_cmd_runner, version='default'):
1313
# """Installs a repository in the given repository. Note that the current
1414
# working directory will already be inside the repository.
1515
#
1616
# Args:
1717
# repo_cmd_runner - `PrefixedCommandRunner` bound to the repository.
18+
# version - A version specified in the hook configuration or
19+
# 'default'.
1820
# """
1921
#
2022
# def run_hook(repo_cmd_runner, hook, file_args):
21-
# """Runs a hook and returns the returncode and output of running that hook.
23+
# """Runs a hook and returns the returncode and output of running that
24+
# hook.
2225
#
2326
# Args:
2427
# repo_cmd_runner - `PrefixedCommandRunner` bound to the repository.

pre_commit/output.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def get_hook_message(
2626
>>> print_hook_message('start', end_len=6)
2727
start...............................................................
2828
29-
# Print `start` followed by dots with the end message colored if coloring is
30-
# specified and a newline afterwards
29+
# Print `start` followed by dots with the end message colored if coloring
30+
# is specified and a newline afterwards
3131
>>> print_hook_message(
3232
'start',
3333
end_msg='end',

pre_commit/prefixed_command_runner.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ class PrefixedCommandRunner(object):
4242
4343
will run ['/tmp/foo/foo.sh', 'bar', 'baz']
4444
"""
45-
def __init__(self, prefix_dir, popen=subprocess.Popen, makedirs=os.makedirs):
45+
def __init__(
46+
self,
47+
prefix_dir,
48+
popen=subprocess.Popen,
49+
makedirs=os.makedirs
50+
):
4651
self.prefix_dir = prefix_dir.rstrip(os.sep) + os.sep
4752
self.__popen = popen
4853
self.__makedirs = makedirs

pre_commit/run.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ def run(argv):
3535
'--no-stash', default=False, action='store_true',
3636
help='Use this option to prevent auto stashing of unstaged files.',
3737
)
38-
run_parser.add_argument('--verbose', '-v', action='store_true', default=False)
38+
run_parser.add_argument(
39+
'--verbose', '-v', action='store_true', default=False,
40+
)
3941

40-
help = subparsers.add_parser('help', help='Show help for a specific command.')
42+
help = subparsers.add_parser(
43+
'help', help='Show help for a specific command.'
44+
)
4145
help.add_argument('help_cmd', nargs='?', help='Command to show help for.')
4246

4347
# Argparse doesn't really provide a way to use a `default` subparser

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
setup(
66
name='pre_commit',
7-
description='A framework for managing and maintaining multi-language pre-commit hooks.',
7+
description=(
8+
'A framework for managing and maintaining multi-language pre-commit '
9+
'hooks.'
10+
),
811
url='https://github.com/pre-commit/pre-commit',
912
version='0.0.0',
1013

tests/clientlib/validate_base_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def test_raises_for_invalid_yaml_file(noop_validator):
4444

4545
def test_raises_for_failing_schema(array_validator):
4646
with pytest.raises(ValueError):
47-
array_validator(get_resource_path('valid_yaml_but_invalid_manifest.yaml'))
47+
array_validator(
48+
get_resource_path('valid_yaml_but_invalid_manifest.yaml')
49+
)
4850

4951

5052
def test_passes_array_schema(array_validator):

tests/commands_test.py

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def test_install_pre_commit(empty_git_dir):
3131
assert ret == 0
3232
assert os.path.exists(runner.pre_commit_path)
3333
pre_commit_contents = open(runner.pre_commit_path).read()
34-
pre_commit_sh = pkg_resources.resource_filename('pre_commit', 'resources/pre-commit.sh')
34+
pre_commit_sh = pkg_resources.resource_filename(
35+
'pre_commit', 'resources/pre-commit.sh',
36+
)
3537
expected_contents = open(pre_commit_sh).read()
3638
assert pre_commit_contents == expected_contents
3739
stat_result = os.stat(runner.pre_commit_path)
@@ -132,7 +134,9 @@ def test_removes_defaults(out_of_date_repo, runner_with_mocked_store):
132134
assert 'expected_return_value' not in ret['hooks'][0]
133135

134136

135-
def test_autoupdate_out_of_date_repo(out_of_date_repo, mock_out_store_directory):
137+
def test_autoupdate_out_of_date_repo(
138+
out_of_date_repo, mock_out_store_directory
139+
):
136140
before = open(C.CONFIG_FILE).read()
137141
runner = Runner(out_of_date_repo.python_hooks_repo)
138142
ret = commands.autoupdate(runner)
@@ -152,7 +156,10 @@ def hook_disappearing_repo(python_hooks_repo):
152156
config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA)
153157
validate_config_extra(config_wrapped)
154158
config = config_wrapped[0]
155-
shutil.copy(get_resource_path('manifest_without_foo.yaml'), C.MANIFEST_FILE)
159+
shutil.copy(
160+
get_resource_path('manifest_without_foo.yaml'),
161+
C.MANIFEST_FILE,
162+
)
156163
local['git']['add', '.']()
157164
local['git']['commit', '-m', 'Remove foo']()
158165

@@ -167,14 +174,18 @@ def hook_disappearing_repo(python_hooks_repo):
167174
)
168175

169176

170-
def test_hook_disppearing_repo_raises(hook_disappearing_repo, runner_with_mocked_store):
177+
def test_hook_disppearing_repo_raises(
178+
hook_disappearing_repo, runner_with_mocked_store
179+
):
171180
with pytest.raises(commands.RepositoryCannotBeUpdatedError):
172181
commands._update_repository(
173182
hook_disappearing_repo.repo_config, runner_with_mocked_store,
174183
)
175184

176185

177-
def test_autoupdate_hook_disappearing_repo(hook_disappearing_repo, mock_out_store_directory):
186+
def test_autoupdate_hook_disappearing_repo(
187+
hook_disappearing_repo, mock_out_store_directory
188+
):
178189
before = open(C.CONFIG_FILE).read()
179190
runner = Runner(hook_disappearing_repo.python_hooks_repo)
180191
ret = commands.autoupdate(runner)
@@ -206,7 +217,13 @@ def get_write_mock_output(write_mock):
206217
return ''.join(call[0][0] for call in write_mock.call_args_list)
207218

208219

209-
def _get_opts(all_files=False, color=False, verbose=False, hook=None, no_stash=False):
220+
def _get_opts(
221+
all_files=False,
222+
color=False,
223+
verbose=False,
224+
hook=None,
225+
no_stash=False,
226+
):
210227
return auto_namedtuple(
211228
all_files=all_files,
212229
color=color,
@@ -234,7 +251,9 @@ def _test_run(repo, options, expected_outputs, expected_ret, stage):
234251
assert expected_output_part in printed
235252

236253

237-
def test_run_all_hooks_failing(repo_with_failing_hook, mock_out_store_directory):
254+
def test_run_all_hooks_failing(
255+
repo_with_failing_hook, mock_out_store_directory
256+
):
238257
_test_run(
239258
repo_with_failing_hook,
240259
{},
@@ -262,7 +281,14 @@ def test_run_all_hooks_failing(repo_with_failing_hook, mock_out_store_directory)
262281
({}, ('Bash hook', '(no files to check)', 'Skipped'), 0, False),
263282
)
264283
)
265-
def test_run(repo_with_passing_hook, options, outputs, expected_ret, stage, mock_out_store_directory):
284+
def test_run(
285+
repo_with_passing_hook,
286+
options,
287+
outputs,
288+
expected_ret,
289+
stage,
290+
mock_out_store_directory,
291+
):
266292
_test_run(repo_with_passing_hook, options, outputs, expected_ret, stage)
267293

268294

@@ -275,7 +301,13 @@ def test_run(repo_with_passing_hook, options, outputs, expected_ret, stage, mock
275301
(False, False, True),
276302
),
277303
)
278-
def test_no_stash(repo_with_passing_hook, no_stash, all_files, expect_stash, mock_out_store_directory):
304+
def test_no_stash(
305+
repo_with_passing_hook,
306+
no_stash,
307+
all_files,
308+
expect_stash,
309+
mock_out_store_directory,
310+
):
279311
stage_a_file()
280312
# Make unstaged changes
281313
with open('foo.py', 'w') as foo_file:
@@ -347,11 +379,15 @@ def test_skip_hook(repo_with_passing_hook, mock_out_store_directory):
347379
assert msg in printed
348380

349381

350-
def test_hook_id_not_in_non_verbose_output(repo_with_passing_hook, mock_out_store_directory):
382+
def test_hook_id_not_in_non_verbose_output(
383+
repo_with_passing_hook, mock_out_store_directory
384+
):
351385
ret, printed = _do_run(repo_with_passing_hook, _get_opts(verbose=False))
352386
assert '[bash_hook]' not in printed
353387

354388

355-
def test_hook_id_in_verbose_output(repo_with_passing_hook, mock_out_store_directory):
389+
def test_hook_id_in_verbose_output(
390+
repo_with_passing_hook, mock_out_store_directory
391+
):
356392
ret, printed = _do_run(repo_with_passing_hook, _get_opts(verbose=True))
357393
assert '[bash_hook] Bash hook' in printed

0 commit comments

Comments
 (0)