Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
language: python
python:
- "2.7"
install: pip install nose2
- "3.5"

env:
- TOXENV=py27
- TOXENV=py32
- TOXENV=py33
- TOXENV=py34
- TOXENV=py35

install:
- pip install tox

before_script:
- git config --global user.email "you@example.com"
- git config --global user.name "Your Name"
script: nose2

script: tox
24 changes: 13 additions & 11 deletions git_pylint_commit_hook/commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import sys
import subprocess
import collections
import ConfigParser

import configparser

ExecutionResult = collections.namedtuple(
'ExecutionResult',
'status, stdout, stderr'
)

def _futurize_str(obj):
if isinstance(obj, bytes):
obj = obj.decode('utf-8')
return obj


def _execute(cmd):
process = subprocess.Popen(
Expand Down Expand Up @@ -40,7 +44,7 @@ def _get_list_of_committed_files():
output = subprocess.check_output(
diff_index_cmd.split()
)
for result in output.split('\n'):
for result in _futurize_str(output).split('\n'):
if result != '':
result = result.split()
if result[4] in ['A', 'M']:
Expand Down Expand Up @@ -75,7 +79,7 @@ def _parse_score(pylint_output):

"""
for line in pylint_output.splitlines():
match = re.match(_SCORE_REGEXP, line)
match = re.match(_SCORE_REGEXP, _futurize_str(line))
if match:
return float(match.group(1))
return 0.0
Expand Down Expand Up @@ -109,16 +113,16 @@ def check_repo(
if _is_python_file(filename):
python_files.append((filename, None))
except IOError:
print 'File not found (probably deleted): {}\t\tSKIPPED'.format(
filename)
print('File not found (probably deleted): {}\t\tSKIPPED'.format(
filename))

# Don't do anything if there are no Python files
if len(python_files) == 0:
sys.exit(0)

# Load any pre-commit-hooks options from a .pylintrc file (if there is one)
if os.path.exists(pylintrc):
conf = ConfigParser.SafeConfigParser()
conf = configparser.SafeConfigParser()
conf.read(pylintrc)
if conf.has_option('pre-commit-hook', 'command'):
pylint = conf.get('pre-commit-hook', 'command')
Expand Down Expand Up @@ -147,21 +151,19 @@ def check_repo(
sys.stdout.flush()
try:
command = [pylint]

if pylint_params:
command += pylint_params.split()
if '--rcfile' not in pylint_params:
command.append('--rcfile={}'.format(pylintrc))
else:
command.append('--rcfile={}'.format(pylintrc))


command.append(python_file)

proc = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

out, _ = proc.communicate()
except OSError:
print("\nAn error occurred. Is pylint installed?")
Expand All @@ -185,7 +187,7 @@ def check_repo(
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, _ = proc.communicate()
print out
print(_futurize_str(out))


# Bump parsed files
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
zip_safe=False,
install_requires=[
'pylint',
'future'
],
classifiers=[
'Development Status :: 4 - Beta',
Expand Down
10 changes: 10 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tox]
envlist = py27, py34

[testenv]
passenv = HOME
deps=nose2
commands=
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
nose2