mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-08 12:34:17 +00:00
Update project setup.
This commit is contained in:
parent
13b4ca54cf
commit
b80ca9e84a
23 changed files with 186 additions and 112 deletions
36
.coveragerc
36
.coveragerc
|
|
@ -1,19 +1,29 @@
|
||||||
|
[run]
|
||||||
|
branch = True
|
||||||
|
timid = True
|
||||||
|
source =
|
||||||
|
.
|
||||||
|
omit =
|
||||||
|
.tox/*
|
||||||
|
/usr/*
|
||||||
|
*/tmp*
|
||||||
|
setup.py
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
exclude_lines =
|
exclude_lines =
|
||||||
# Don't complain about defensive assertions
|
# Have to re-enable the standard pragma
|
||||||
raise NotImplementedError
|
\#\s*pragma: no cover
|
||||||
raise AssertionError
|
|
||||||
|
|
||||||
# Don't complain about non-runnable code
|
# Don't complain if tests don't hit defensive assertion code:
|
||||||
if __name__ == .__main__.:
|
^\s*raise AssertionError\b
|
||||||
|
^\s*raise NotImplementedError\b
|
||||||
|
^\s*return NotImplemented\b
|
||||||
|
^\s*raise$
|
||||||
|
|
||||||
omit =
|
# Don't complain if non-runnable code isn't run:
|
||||||
/usr/*
|
^if __name__ == ['"]__main__['"]:$
|
||||||
py_env/*
|
|
||||||
*/__init__.py
|
|
||||||
|
|
||||||
# Ignore test coverage
|
[html]
|
||||||
tests/*
|
directory = coverage-html
|
||||||
|
|
||||||
# Don't complain about our pre-commit file
|
# vim:ft=dosini
|
||||||
pre-commit.py
|
|
||||||
|
|
|
||||||
20
.gitignore
vendored
20
.gitignore
vendored
|
|
@ -1,12 +1,14 @@
|
||||||
*.pyc
|
|
||||||
.pydevproject
|
|
||||||
.project
|
|
||||||
.coverage
|
|
||||||
/py_env
|
|
||||||
*.db
|
|
||||||
.idea
|
|
||||||
build
|
|
||||||
dist
|
|
||||||
*.egg-info
|
*.egg-info
|
||||||
*.iml
|
*.iml
|
||||||
|
*.py[co]
|
||||||
|
.*.sw[a-z]
|
||||||
|
.coverage
|
||||||
|
.idea
|
||||||
.pre-commit-files
|
.pre-commit-files
|
||||||
|
.project
|
||||||
|
.pydevproject
|
||||||
|
.tox
|
||||||
|
.venv.touch
|
||||||
|
/venv*
|
||||||
|
coverage-html
|
||||||
|
dist
|
||||||
|
|
|
||||||
14
.travis.yml
14
.travis.yml
|
|
@ -1,8 +1,8 @@
|
||||||
language: python
|
language: python
|
||||||
|
env: # These should match the tox env list
|
||||||
python:
|
- TOXENV=py26
|
||||||
- 2.6
|
- TOXENV=py27
|
||||||
- 2.7
|
- TOXENV=py33
|
||||||
|
- TOXENV=pypy
|
||||||
install: pip install virtualenv
|
install: pip install tox --use-mirrors
|
||||||
script: make coverage
|
script: tox
|
||||||
|
|
|
||||||
48
Makefile
48
Makefile
|
|
@ -1,41 +1,27 @@
|
||||||
|
|
||||||
TEST_TARGETS =
|
REBUILD_FLAG =
|
||||||
ITEST_TARGETS = -m integration
|
|
||||||
UTEST_TARGETS = -m "not(integration)"
|
|
||||||
|
|
||||||
DEBUG=
|
.PHONY: all
|
||||||
|
all: venv test
|
||||||
|
|
||||||
all: _tests
|
.PHONY: venv
|
||||||
|
venv: .venv.touch
|
||||||
|
tox -e venv $(REBUILD_FLAG)
|
||||||
|
|
||||||
integration:
|
.PHONY: tests test
|
||||||
$(eval TEST_TARGETS := $(ITEST_TARGETS))
|
|
||||||
|
|
||||||
unit:
|
|
||||||
$(eval TEST_TARGETS := $(UTEST_TARGETS))
|
|
||||||
|
|
||||||
utests: test
|
|
||||||
utest: test
|
|
||||||
tests: test
|
tests: test
|
||||||
test: unit _tests
|
test: .venv.touch
|
||||||
itests: itest
|
tox $(REBUILD_FLAG)
|
||||||
itest: integration _tests
|
|
||||||
|
|
||||||
_tests: py_env
|
|
||||||
bash -c 'source py_env/bin/activate && py.test tests $(TEST_TARGETS) $(DEBUG)'
|
|
||||||
|
|
||||||
ucoverage: unit coverage
|
.venv.touch: setup.py requirements.txt requirements_dev.txt
|
||||||
icoverage: integration coverage
|
$(eval REBUILD_FLAG := --recreate)
|
||||||
|
touch .venv.touch
|
||||||
|
|
||||||
coverage: py_env
|
|
||||||
bash -c 'source py_env/bin/activate && \
|
|
||||||
coverage erase && \
|
|
||||||
coverage run `which py.test` tests $(TEST_TARGETS) && \
|
|
||||||
coverage report -m'
|
|
||||||
|
|
||||||
py_env: requirements.txt setup.py
|
|
||||||
rm -rf py_env
|
|
||||||
virtualenv py_env
|
|
||||||
bash -c 'source py_env/bin/activate && pip install -r requirements.txt'
|
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf py_env
|
find . -iname '*.pyc' | xargs rm -f
|
||||||
|
rm -rf .tox
|
||||||
|
rm -rf ./venv-*
|
||||||
|
rm -f .venv.touch
|
||||||
|
|
|
||||||
24
UNLICENSE
Normal file
24
UNLICENSE
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <http://unlicense.org/>
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -17,7 +18,7 @@ def check_yaml(argv):
|
||||||
try:
|
try:
|
||||||
yaml.load(open(filename))
|
yaml.load(open(filename))
|
||||||
except yaml.YAMLError as e:
|
except yaml.YAMLError as e:
|
||||||
print e
|
print(e)
|
||||||
retval = 1
|
retval = 1
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import ast
|
import ast
|
||||||
|
|
@ -39,7 +40,14 @@ def check_file_for_debug_statements(filename):
|
||||||
visitor.visit(ast_obj)
|
visitor.visit(ast_obj)
|
||||||
if visitor.debug_import_statements:
|
if visitor.debug_import_statements:
|
||||||
for debug_statement in visitor.debug_import_statements:
|
for debug_statement in visitor.debug_import_statements:
|
||||||
print '{0}:{2}:{3} - {1} imported'.format(filename, *debug_statement)
|
print(
|
||||||
|
'{0}:{1}:{2} - {3} imported'.format(
|
||||||
|
filename,
|
||||||
|
debug_statement.line,
|
||||||
|
debug_statement.col,
|
||||||
|
debug_statement.name,
|
||||||
|
)
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
|
@ -18,11 +17,11 @@ def fix_file(file_obj):
|
||||||
return 0
|
return 0
|
||||||
last_character = file_obj.read(1)
|
last_character = file_obj.read(1)
|
||||||
# last_character will be '' for an empty file
|
# last_character will be '' for an empty file
|
||||||
if last_character != '\n' and last_character != '':
|
if last_character != b'\n' and last_character != b'':
|
||||||
file_obj.write('\n')
|
file_obj.write(b'\n')
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
while last_character == '\n':
|
while last_character == b'\n':
|
||||||
# Deal with the beginning of the file
|
# Deal with the beginning of the file
|
||||||
if file_obj.tell() == 1:
|
if file_obj.tell() == 1:
|
||||||
# If we've reached the beginning of the file and it is all
|
# If we've reached the beginning of the file and it is all
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -22,4 +21,4 @@ def validate_files(argv):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(entry())
|
sys.exit(validate_files())
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -12,13 +13,13 @@ def fix_trailing_whitespace(argv):
|
||||||
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
bad_whitespace_files = filter(bool, local['grep'][
|
bad_whitespace_files = local['grep'][
|
||||||
('-l', '[[:space:]]$') + tuple(args.filenames)
|
('-l', '[[:space:]]$') + tuple(args.filenames)
|
||||||
](retcode=None).splitlines())
|
](retcode=None).strip().splitlines()
|
||||||
|
|
||||||
if bad_whitespace_files:
|
if bad_whitespace_files:
|
||||||
for bad_whitespace_file in bad_whitespace_files:
|
for bad_whitespace_file in bad_whitespace_files:
|
||||||
print 'Fixing {0}'.format(bad_whitespace_file)
|
print('Fixing {0}'.format(bad_whitespace_file))
|
||||||
local['sed']['-i', '-e', 's/[[:space:]]*$//', bad_whitespace_file]()
|
local['sed']['-i', '-e', 's/[[:space:]]*$//', bad_whitespace_file]()
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
|
||||||
19
pylintrc
Normal file
19
pylintrc
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
[MESSAGES CONTROL]
|
||||||
|
disable=missing-docstring,abstract-method,redefined-builtin,invalid-name,no-value-for-parameter,redefined-outer-name,no-member,bad-open-mode
|
||||||
|
|
||||||
|
[REPORTS]
|
||||||
|
output-format=colorized
|
||||||
|
reports=no
|
||||||
|
|
||||||
|
[BASIC]
|
||||||
|
const-rgx=(([A-Za-z_][A-Za-z0-9_]*)|(__.*__))$
|
||||||
|
|
||||||
|
[FORMAT]
|
||||||
|
max-line-length=131
|
||||||
|
|
||||||
|
[TYPECHECK]
|
||||||
|
ignored-classes=pytest
|
||||||
|
|
||||||
|
[DESIGN]
|
||||||
|
min-public-methods=0
|
||||||
|
|
||||||
|
|
@ -1,8 +1 @@
|
||||||
-e .
|
.
|
||||||
|
|
||||||
# Testing requirements
|
|
||||||
coverage
|
|
||||||
flake8
|
|
||||||
mock
|
|
||||||
git+git://github.com/pre-commit/pre-commit#egg=pre-commit
|
|
||||||
pytest
|
|
||||||
|
|
|
||||||
8
requirements_dev.txt
Normal file
8
requirements_dev.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
-e .
|
||||||
|
|
||||||
|
coverage
|
||||||
|
flake8
|
||||||
|
mock
|
||||||
|
pylint
|
||||||
|
pytest
|
||||||
|
git+git://github.com/pre-commit/pre-commit#egg=pre_commit
|
||||||
16
setup.py
16
setup.py
|
|
@ -1,9 +1,25 @@
|
||||||
from setuptools import find_packages
|
from setuptools import find_packages
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='pre_commit_hooks',
|
name='pre_commit_hooks',
|
||||||
|
description='Some out-of-the-box hooks for pre-commit.',
|
||||||
|
url='https://github.com/pre-commit/pre-commit-hooks',
|
||||||
version='0.0.0',
|
version='0.0.0',
|
||||||
|
|
||||||
|
author='Anthony Sottile',
|
||||||
|
author_email='asottile@umich.edu',
|
||||||
|
|
||||||
|
platforms='linux',
|
||||||
|
classifiers=[
|
||||||
|
'License :: Public Domain',
|
||||||
|
'Programming Language :: Python :: 2.6',
|
||||||
|
'Programming Language :: Python :: 2.7',
|
||||||
|
'Programming Language :: Python :: 3.3',
|
||||||
|
'Programming Language :: Python :: Implementation :: PyPy',
|
||||||
|
],
|
||||||
|
|
||||||
packages=find_packages('.', exclude=('tests*', 'testing*')),
|
packages=find_packages('.', exclude=('tests*', 'testing*')),
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'argparse',
|
'argparse',
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pre_commit_hooks.check_yaml import check_yaml
|
from pre_commit_hooks.check_yaml import check_yaml
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
|
|
||||||
import __builtin__
|
|
||||||
|
|
||||||
import mock
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
|
||||||
def print_mock():
|
|
||||||
with mock.patch.object(__builtin__, 'print', autospec=True) as mock_print:
|
|
||||||
yield mock_print
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import ast
|
import ast
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
|
import io
|
||||||
import cStringIO
|
|
||||||
import os.path
|
import os.path
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
@ -9,19 +8,19 @@ from pre_commit_hooks.end_of_file_fixer import fix_file
|
||||||
|
|
||||||
# Input, expected return value, expected output
|
# Input, expected return value, expected output
|
||||||
TESTS = (
|
TESTS = (
|
||||||
('foo\n', 0, 'foo\n'),
|
(b'foo\n', 0, b'foo\n'),
|
||||||
('', 0, ''),
|
(b'', 0, b''),
|
||||||
('\n\n', 1, ''),
|
(b'\n\n', 1, b''),
|
||||||
('\n\n\n\n', 1, ''),
|
(b'\n\n\n\n', 1, b''),
|
||||||
('foo', 1, 'foo\n'),
|
(b'foo', 1, b'foo\n'),
|
||||||
('foo\n\n\n', 1, 'foo\n'),
|
(b'foo\n\n\n', 1, b'foo\n'),
|
||||||
('\xe2\x98\x83', 1, '\xe2\x98\x83\n'),
|
(b'\xe2\x98\x83', 1, b'\xe2\x98\x83\n'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('input', 'expected_retval', 'output'), TESTS)
|
@pytest.mark.parametrize(('input', 'expected_retval', 'output'), TESTS)
|
||||||
def test_fix_file(input, expected_retval, output):
|
def test_fix_file(input, expected_retval, output):
|
||||||
file_obj = cStringIO.StringIO()
|
file_obj = io.BytesIO()
|
||||||
file_obj.write(input)
|
file_obj.write(input)
|
||||||
ret = fix_file(file_obj)
|
ret = fix_file(file_obj)
|
||||||
assert file_obj.getvalue() == output
|
assert file_obj.getvalue() == output
|
||||||
|
|
@ -32,11 +31,11 @@ def test_fix_file(input, expected_retval, output):
|
||||||
def test_integration(input, expected_retval, output, tmpdir):
|
def test_integration(input, expected_retval, output, tmpdir):
|
||||||
file_path = os.path.join(tmpdir.strpath, 'file.txt')
|
file_path = os.path.join(tmpdir.strpath, 'file.txt')
|
||||||
|
|
||||||
with open(file_path, 'w') as file_obj:
|
with open(file_path, 'wb') as file_obj:
|
||||||
file_obj.write(input)
|
file_obj.write(input)
|
||||||
|
|
||||||
ret = end_of_file_fixer([file_path])
|
ret = end_of_file_fixer([file_path])
|
||||||
file_output = open(file_path, 'r').read()
|
file_output = open(file_path, 'rb').read()
|
||||||
|
|
||||||
assert file_output == output
|
assert file_output == output
|
||||||
assert ret == expected_retval
|
assert ret == expected_retval
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
|
|
||||||
from pre_commit_hooks.tests_should_end_in_test import validate_files
|
from pre_commit_hooks.tests_should_end_in_test import validate_files
|
||||||
|
|
||||||
|
|
||||||
def test_validate_files_all_pass(print_mock):
|
def test_validate_files_all_pass():
|
||||||
ret = validate_files(['foo_test.py', 'bar_test.py'])
|
ret = validate_files(['foo_test.py', 'bar_test.py'])
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert print_mock.call_count == 0
|
|
||||||
|
|
||||||
|
|
||||||
def test_validate_files_one_fails(print_mock):
|
def test_validate_files_one_fails():
|
||||||
ret = validate_files(['not_test_ending.py', 'foo_test.py'])
|
ret = validate_files(['not_test_ending.py', 'foo_test.py'])
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert print_mock.call_count == 1
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
import sys
|
import sys
|
||||||
|
|
|
||||||
28
tox.ini
Normal file
28
tox.ini
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
[tox]
|
||||||
|
project = pre_commit_hooks
|
||||||
|
# These should match the travis env list
|
||||||
|
envlist = py26,py27,py33,pypy
|
||||||
|
|
||||||
|
[testenv]
|
||||||
|
install_command = pip install --use-wheel {opts} {packages}
|
||||||
|
deps = -rrequirements_dev.txt
|
||||||
|
commands =
|
||||||
|
coverage erase
|
||||||
|
coverage run -m pytest {posargs:tests}
|
||||||
|
coverage report --show-missing --fail-under 82
|
||||||
|
flake8 {[tox]project} testing tests setup.py
|
||||||
|
pylint {[tox]project} testing tests setup.py
|
||||||
|
|
||||||
|
[testenv:venv]
|
||||||
|
envdir = venv-{[tox]project}
|
||||||
|
commands =
|
||||||
|
|
||||||
|
[testenv:docs]
|
||||||
|
deps =
|
||||||
|
{[testenv]deps}
|
||||||
|
sphinx
|
||||||
|
changedir = docs
|
||||||
|
commands = sphinx-build -b html -d build/doctrees source build/html
|
||||||
|
|
||||||
|
[flake8]
|
||||||
|
max-line-length=131
|
||||||
Loading…
Add table
Add a link
Reference in a new issue