Better project structure

This commit is contained in:
Anthony Sottile 2014-04-12 07:28:25 -07:00
parent f31f092f9b
commit 1746a97e24
52 changed files with 221 additions and 189 deletions

View file

@ -1,4 +1,3 @@
from __future__ import print_function
import argparse

View file

@ -1,4 +1,3 @@
import re
import sys
@ -6,7 +5,8 @@ from pre_commit.clientlib.validate_base import get_run_function
from pre_commit.clientlib.validate_base import get_validator
class InvalidConfigError(ValueError): pass
class InvalidConfigError(ValueError):
pass
CONFIG_JSON_SCHEMA = {

View file

@ -1,4 +1,3 @@
import sys
from pre_commit.clientlib.validate_base import get_run_function
@ -6,7 +5,8 @@ from pre_commit.clientlib.validate_base import get_validator
from pre_commit.languages.all import all_languages
class InvalidManifestError(ValueError): pass
class InvalidManifestError(ValueError):
pass
MANIFEST_JSON_SCHEMA = {

View file

@ -1,4 +1,3 @@
import sys
RED = '\033[41m'
@ -8,18 +7,19 @@ TURQUOISE = '\033[46;30m'
NORMAL = '\033[0m'
class InvalidColorSetting(ValueError): pass
class InvalidColorSetting(ValueError):
pass
def format_color(text, color, use_color):
def format_color(text, color, use_color_setting):
"""Format text with color.
Args:
text - Text to be formatted with color if `use_color`
color - The color start string
use_color - Whether or not to color
use_color_setting - Whether or not to color
"""
if not use_color:
if not use_color_setting:
return text
else:
return u'{0}{1}{2}'.format(color, text, NORMAL)

View file

@ -1,4 +1,3 @@
from __future__ import print_function
import os
@ -42,7 +41,8 @@ def uninstall(runner):
return 0
class RepositoryCannotBeUpdatedError(RuntimeError): pass
class RepositoryCannotBeUpdatedError(RuntimeError):
pass
def _update_repository(repo_config):
@ -95,8 +95,8 @@ def autoupdate(runner):
print('Updating {0}...'.format(repo_config['repo']), end='')
try:
new_repo_config = _update_repository(repo_config)
except RepositoryCannotBeUpdatedError as e:
print(e.args[0])
except RepositoryCannotBeUpdatedError as error:
print(error.args[0])
output_configs.append(repo_config)
retv = 1
continue

View file

@ -1,4 +1,3 @@
CONFIG_FILE = '.pre-commit-config.yaml'
HOOKS_WORKSPACE = '.pre-commit-files'

View file

@ -43,14 +43,15 @@ def get_files_matching(all_file_list_strategy):
def wrapper(include_expr, exclude_expr):
include_regex = re.compile(include_expr)
exclude_regex = re.compile(exclude_expr)
return set(filter(os.path.exists, (
return set(
filename
for filename in all_file_list_strategy()
if (
include_regex.search(filename) and
not exclude_regex.search(filename)
not exclude_regex.search(filename) and
os.path.exists(filename)
)
)))
)
return wrapper

View file

@ -1,4 +1,3 @@
import contextlib
import os.path
from plumbum import local

View file

@ -1,4 +1,3 @@
import copy
import jsonschema
import jsonschema.validators
@ -21,7 +20,6 @@ def extend_validator_cls(validator_cls, modify):
)
def default_values(properties, instance):
for property, subschema in properties.iteritems():
if 'default' in subschema:

View file

@ -1,4 +1,3 @@
from pre_commit.languages import node
from pre_commit.languages import python
from pre_commit.languages import ruby

View file

@ -1,4 +1,3 @@
import contextlib
from pre_commit.languages import helpers

View file

@ -1,4 +1,3 @@
import contextlib
from pre_commit.languages import helpers
@ -11,7 +10,7 @@ ENVIRONMENT_DIR = 'rvm_env'
class RubyEnv(helpers.Environment):
@property
def env_prefix(self):
return '. {{prefix}}{0}/bin/activate &&'.format(ENVIRONMENT_DIR)
raise NotImplementedError
@contextlib.contextmanager

View file

@ -1,4 +1,3 @@
ENVIRONMENT_DIR = None

View file

@ -1,4 +1,3 @@
ENVIRONMENT_DIR = None

View file

@ -1,4 +1,3 @@
from __future__ import print_function
import logging

View file

@ -1,4 +1,3 @@
import os
import os.path
import subprocess

View file

@ -1,4 +1,3 @@
import contextlib
import logging
from plumbum import local

View file

@ -1,4 +1,3 @@
from __future__ import print_function
import argparse
@ -56,7 +55,6 @@ def _run_single_hook(runner, repository, hook_id, args):
print_color = color.GREEN
pass_fail = 'Passed'
print(color.format_color(pass_fail, print_color, args.color))
if output and (retcode or args.verbose):
@ -111,14 +109,14 @@ def run(argv):
subparsers.add_parser('autoupdate', help='Auto-update hooks config.')
run = subparsers.add_parser('run', help='Run hooks.')
run.add_argument('hook', nargs='?', help='A single hook-id to run'),
run.add_argument(
run_parser = subparsers.add_parser('run', help='Run hooks.')
run_parser.add_argument('hook', nargs='?', help='A single hook-id to run')
run_parser.add_argument(
'--all-files', '-a', action='store_true', default=False,
help='Run on all the files in the repo.',
)
run.add_argument('--verbose', '-v', action='store_true', default=False)
run.add_argument(
run_parser.add_argument('--verbose', '-v', action='store_true', default=False)
run_parser.add_argument(
'--color', default='auto', type=color.use_color,
help='Whether to use color in output. Defaults to `auto`',
)

View file

@ -1,4 +1,3 @@
import os
import os.path
@ -40,7 +39,7 @@ class Runner(object):
def repositories(self):
"""Returns a tuple of the configured repositories."""
config = load_config(self.config_file_path)
return tuple(map(Repository, config))
return tuple(Repository(x) for x in config)
@cached_property
def pre_commit_path(self):

View file

@ -1,4 +1,3 @@
import contextlib
import logging
import time

View file

@ -1,4 +1,3 @@
import contextlib
import functools
import os

View file

@ -1,4 +1,3 @@
import yaml
from pre_commit.ordereddict import OrderedDict
@ -6,23 +5,27 @@ from pre_commit.ordereddict import OrderedDict
# Adapted from http://stackoverflow.com/a/21912744/812183
def ordered_load(s):
class OrderedLoader(yaml.loader.Loader): pass
def ordered_load(stream):
class OrderedLoader(yaml.loader.Loader):
pass
def constructor(loader, node):
return OrderedDict(loader.construct_pairs(node))
OrderedLoader.add_constructor(
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
constructor,
)
return yaml.load(s, Loader=OrderedLoader)
return yaml.load(stream, Loader=OrderedLoader)
def ordered_dump(s, **kwargs):
class OrderedDumper(yaml.dumper.SafeDumper): pass
def ordered_dump(obj, **kwargs):
class OrderedDumper(yaml.dumper.SafeDumper):
pass
def dict_representer(dumper, data):
return dumper.represent_mapping(
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
data.items(),
)
OrderedDumper.add_representer(OrderedDict, dict_representer)
return yaml.dump(s, Dumper=OrderedDumper, **kwargs)
return yaml.dump(obj, Dumper=OrderedDumper, **kwargs)