mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Remove @entry
This commit is contained in:
parent
9a017dcbe9
commit
32817f3958
6 changed files with 10 additions and 52 deletions
|
|
@ -6,10 +6,10 @@ import jsonschema
|
|||
import jsonschema.exceptions
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.util import entry
|
||||
|
||||
|
||||
def is_regex_valid(regex):
|
||||
|
|
@ -64,8 +64,8 @@ def get_validator(
|
|||
|
||||
|
||||
def get_run_function(filenames_help, validate_strategy, exception_cls):
|
||||
@entry
|
||||
def run(argv):
|
||||
def run(argv=None):
|
||||
argv = argv if argv is not None else sys.argv[1:]
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help=filenames_help)
|
||||
args = parser.parse_args(argv)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
from pre_commit.clientlib.validate_base import get_run_function
|
||||
from pre_commit.clientlib.validate_base import get_validator
|
||||
from pre_commit.clientlib.validate_base import is_regex_valid
|
||||
from pre_commit.errors import FatalError
|
||||
|
||||
|
||||
class InvalidConfigError(ValueError):
|
||||
class InvalidConfigError(FatalError):
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -71,4 +70,4 @@ run = get_run_function('Config filenames.', load_config, InvalidConfigError)
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(run())
|
||||
exit(run())
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
from pre_commit.clientlib.validate_base import get_run_function
|
||||
from pre_commit.clientlib.validate_base import get_validator
|
||||
from pre_commit.clientlib.validate_base import is_regex_valid
|
||||
|
|
@ -74,4 +72,4 @@ run = get_run_function(
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(run())
|
||||
exit(run())
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||
|
||||
import argparse
|
||||
import pkg_resources
|
||||
import sys
|
||||
|
||||
from pre_commit import color
|
||||
from pre_commit.commands.autoupdate import autoupdate
|
||||
|
|
@ -11,11 +12,10 @@ from pre_commit.commands.install_uninstall import uninstall
|
|||
from pre_commit.commands.run import run
|
||||
from pre_commit.error_handler import error_handler
|
||||
from pre_commit.runner import Runner
|
||||
from pre_commit.util import entry
|
||||
|
||||
|
||||
@entry
|
||||
def main(argv):
|
||||
def main(argv=None):
|
||||
argv = argv if argv is not None else sys.argv[1:]
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
# http://stackoverflow.com/a/8521644/812183
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import os
|
|||
import os.path
|
||||
import pkg_resources
|
||||
import shutil
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
|
||||
|
|
@ -29,19 +28,6 @@ def memoize_by_cwd(func):
|
|||
return wrapper
|
||||
|
||||
|
||||
def entry(func):
|
||||
"""Allows a function that has `argv` as an argument to be used as a
|
||||
commandline entry. This will make the function callable using either
|
||||
explicitly passed argv or defaulting to sys.argv[1:]
|
||||
"""
|
||||
@functools.wraps(func)
|
||||
def wrapper(argv=None):
|
||||
if argv is None:
|
||||
argv = sys.argv[1:]
|
||||
return func(argv)
|
||||
return wrapper
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def clean_path_on_failure(path):
|
||||
"""Cleans up the directory on an exceptional failure."""
|
||||
|
|
|
|||
|
|
@ -1,15 +1,12 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import os
|
||||
import os.path
|
||||
import random
|
||||
import sys
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import entry
|
||||
from pre_commit.util import memoize_by_cwd
|
||||
from pre_commit.util import shell_escape
|
||||
from pre_commit.util import tmpdir
|
||||
|
|
@ -46,28 +43,6 @@ def test_memoized_by_cwd_changes_with_different_cwd(memoized_by_cwd):
|
|||
assert ret != ret2
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def entry_func():
|
||||
@entry
|
||||
def func(argv):
|
||||
return argv
|
||||
|
||||
return func
|
||||
|
||||
|
||||
def test_explicitly_passed_argv_are_passed(entry_func):
|
||||
input = object()
|
||||
ret = entry_func(input)
|
||||
assert ret is input
|
||||
|
||||
|
||||
def test_no_arguments_passed_uses_argv(entry_func):
|
||||
argv = [1, 2, 3, 4]
|
||||
with mock.patch.object(sys, 'argv', argv):
|
||||
ret = entry_func()
|
||||
assert ret == argv[1:]
|
||||
|
||||
|
||||
def test_clean_on_failure_noop(in_tmpdir):
|
||||
with clean_path_on_failure('foo'):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue