Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32817f3

Browse files
committed
Remove @entry
1 parent 9a017dc commit 32817f3

6 files changed

Lines changed: 10 additions & 52 deletions

File tree

pre_commit/clientlib/validate_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import jsonschema.exceptions
77
import os.path
88
import re
9+
import sys
910
import yaml
1011

1112
from pre_commit.jsonschema_extensions import apply_defaults
12-
from pre_commit.util import entry
1313

1414

1515
def is_regex_valid(regex):
@@ -64,8 +64,8 @@ def validate(filename, load_strategy=yaml.load):
6464

6565

6666
def get_run_function(filenames_help, validate_strategy, exception_cls):
67-
@entry
68-
def run(argv):
67+
def run(argv=None):
68+
argv = argv if argv is not None else sys.argv[1:]
6969
parser = argparse.ArgumentParser()
7070
parser.add_argument('filenames', nargs='*', help=filenames_help)
7171
args = parser.parse_args(argv)

pre_commit/clientlib/validate_config.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from __future__ import unicode_literals
22

3-
import sys
4-
53
from pre_commit.clientlib.validate_base import get_run_function
64
from pre_commit.clientlib.validate_base import get_validator
75
from pre_commit.clientlib.validate_base import is_regex_valid
6+
from pre_commit.errors import FatalError
87

98

10-
class InvalidConfigError(ValueError):
9+
class InvalidConfigError(FatalError):
1110
pass
1211

1312

@@ -71,4 +70,4 @@ def validate_config_extra(config):
7170

7271

7372
if __name__ == '__main__':
74-
sys.exit(run())
73+
exit(run())

pre_commit/clientlib/validate_manifest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import unicode_literals
22

3-
import sys
4-
53
from pre_commit.clientlib.validate_base import get_run_function
64
from pre_commit.clientlib.validate_base import get_validator
75
from pre_commit.clientlib.validate_base import is_regex_valid
@@ -74,4 +72,4 @@ def additional_manifest_check(obj):
7472

7573

7674
if __name__ == '__main__':
77-
sys.exit(run())
75+
exit(run())

pre_commit/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import argparse
44
import pkg_resources
5+
import sys
56

67
from pre_commit import color
78
from pre_commit.commands.autoupdate import autoupdate
@@ -11,11 +12,10 @@
1112
from pre_commit.commands.run import run
1213
from pre_commit.error_handler import error_handler
1314
from pre_commit.runner import Runner
14-
from pre_commit.util import entry
1515

1616

17-
@entry
18-
def main(argv):
17+
def main(argv=None):
18+
argv = argv if argv is not None else sys.argv[1:]
1919
parser = argparse.ArgumentParser()
2020

2121
# http://stackoverflow.com/a/8521644/812183

pre_commit/util.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import os.path
88
import pkg_resources
99
import shutil
10-
import sys
1110
import tarfile
1211
import tempfile
1312

@@ -29,19 +28,6 @@ def wrapper(*args):
2928
return wrapper
3029

3130

32-
def entry(func):
33-
"""Allows a function that has `argv` as an argument to be used as a
34-
commandline entry. This will make the function callable using either
35-
explicitly passed argv or defaulting to sys.argv[1:]
36-
"""
37-
@functools.wraps(func)
38-
def wrapper(argv=None):
39-
if argv is None:
40-
argv = sys.argv[1:]
41-
return func(argv)
42-
return wrapper
43-
44-
4531
@contextlib.contextmanager
4632
def clean_path_on_failure(path):
4733
"""Cleans up the directory on an exceptional failure."""

tests/util_test.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
from __future__ import unicode_literals
22

3-
import mock
43
import pytest
54
import os
65
import os.path
76
import random
8-
import sys
97
from plumbum import local
108

119
from pre_commit.util import clean_path_on_failure
12-
from pre_commit.util import entry
1310
from pre_commit.util import memoize_by_cwd
1411
from pre_commit.util import shell_escape
1512
from pre_commit.util import tmpdir
@@ -46,28 +43,6 @@ def test_memoized_by_cwd_changes_with_different_cwd(memoized_by_cwd):
4643
assert ret != ret2
4744

4845

49-
@pytest.fixture
50-
def entry_func():
51-
@entry
52-
def func(argv):
53-
return argv
54-
55-
return func
56-
57-
58-
def test_explicitly_passed_argv_are_passed(entry_func):
59-
input = object()
60-
ret = entry_func(input)
61-
assert ret is input
62-
63-
64-
def test_no_arguments_passed_uses_argv(entry_func):
65-
argv = [1, 2, 3, 4]
66-
with mock.patch.object(sys, 'argv', argv):
67-
ret = entry_func()
68-
assert ret == argv[1:]
69-
70-
7146
def test_clean_on_failure_noop(in_tmpdir):
7247
with clean_path_on_failure('foo'):
7348
pass

0 commit comments

Comments
 (0)