Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

try windows support #134

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
environment:

matrix:

# For Python versions available on Appveyor, see
# http://www.appveyor.com/docs/installed-software#python
# The list here is complete (excluding Python 2.6, which
# isn't covered by this document) at the time of writing.

- PYTHON: "C:\\Python27"
- PYTHON: "C:\\Python34"
- PYTHON: "C:\\Python35"
- PYTHON: "C:\\Python27-x64"
DISTUTILS_USE_SDK: "1"
- PYTHON: "C:\\Python34-x64"
DISTUTILS_USE_SDK: "1"
- PYTHON: "C:\\Python35-x64"
- PYTHON: "C:\\Python36-x64"

install:
- "%PYTHON%\\python.exe -m pip install .[dev,test] coveralls"

build: off

test_script:
# Put your test command here.
# If you don't need to build C extensions on 64-bit Python 3.3 or 3.4,
# you can remove "build.cmd" from the front of the command, as it's
# only needed to support those cases.
# Note that you must use the environment variable %PYTHON% to refer to
# the interpreter you're using - Appveyor does not do anything special
# to put the Python version you want to use on PATH.
- nosetests

#after_test:
# This step builds your wheels.
# Again, you only need build.cmd if you're building C extensions for
# 64-bit Python 3.3/3.4. And you need to use %PYTHON% to get the correct
# interpreter

#artifacts:
# bdist_wheel puts your built wheel in the dist directory

#on_success:
# You can use this step to upload your artifacts to a public website.
# See Appveyor's documentation for more details. Or you can simply
# access your wheels from the Appveyor "artifacts" tab for your build.
3 changes: 3 additions & 0 deletions gitlint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@

import docopt
import termcolor
if sys.platform == "win32":
import colorama
colorama.init()
import yaml

import gitlint.git as git
Expand Down
7 changes: 3 additions & 4 deletions gitlint/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def modified_files(root, tracked_only=False, commit=None):
status_lines = subprocess.check_output([
'git', 'status', '--porcelain', '--untracked-files=all',
'--ignore-submodules=all'
]).decode('utf-8').split(os.linesep)
]).decode('utf-8').splitlines()

modes = ['M ', ' M', 'A ', 'AM', 'MM']
if not tracked_only:
Expand All @@ -93,7 +93,7 @@ def _modified_files_with_commit(root, commit):
status_lines = subprocess.check_output([
'git', 'diff-tree', '-r', '--root', '--no-commit-id', '--name-status',
commit
]).decode('utf-8').split(os.linesep)
]).decode('utf-8').splitlines()

modified_file_status = utils.filter_lines(
status_lines,
Expand Down Expand Up @@ -132,8 +132,7 @@ def modified_lines(filename, extra_data, commit=None):

# Split as bytes, as the output may have some non unicode characters.
blame_lines = subprocess.check_output(
['git', 'blame', '--porcelain', filename]).split(
os.linesep.encode('utf-8'))
['git', 'blame', '--porcelain', filename]).splitlines()
modified_line_numbers = utils.filter_lines(
blame_lines, commit + br' (?P<line>\d+) (\d+)', groups=('line', ))

Expand Down
7 changes: 3 additions & 4 deletions gitlint/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def modified_files(root, tracked_only=False, commit=None):
command.append('--change=%s' % commit)

# Convert to unicode and split
status_lines = subprocess.check_output(command).decode('utf-8').split(
os.linesep)
status_lines = subprocess.check_output(command).decode(
'utf-8').splitlines()

modes = ['M', 'A']
if not tracked_only:
Expand Down Expand Up @@ -105,8 +105,7 @@ def modified_lines(filename, extra_data, commit=None):
command.append(filename)

# Split as bytes, as the output may have some non unicode characters.
diff_lines = subprocess.check_output(command).split(
os.linesep.encode('utf-8'))
diff_lines = subprocess.check_output(command).splitlines()
diff_line_numbers = utils.filter_lines(
diff_lines,
br'@@ -\d+,\d+ \+(?P<start_line>\d+),(?P<lines>\d+) @@',
Expand Down
2 changes: 1 addition & 1 deletion gitlint/linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def lint_command(name, program, arguments, filter_regex, filename, lines):
output = output.decode('utf-8')
utils.save_output_in_cache(name, filename, output)

output_lines = output.split(os.linesep)
output_lines = output.splitlines()

if lines is None:
lines_regex = r'\d+'
Expand Down
31 changes: 13 additions & 18 deletions gitlint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@
import io
import os
import re
import sys

# This can be just pathlib when 2.7 and 3.4 support is dropped.
import pathlib2 as pathlib
if sys.version_info <= (3, 5):
import pathlib2 as pathlib
else:
import pathlib

try:
from shutil import which
except ImportError:
from backports.shutil_which import which


def filter_lines(lines, filter_regex, groups=None):
Expand All @@ -43,22 +52,6 @@ def filter_lines(lines, filter_regex, groups=None):
yield tuple(matched_groups.get(group) for group in groups)


# TODO(skreft): add test
def which(program):
"""Returns a list of paths where the program is found."""
if (os.path.isabs(program) and os.path.isfile(program)
and os.access(program, os.X_OK)):
return [program]

candidates = []
locations = os.environ.get("PATH").split(os.pathsep)
for location in locations:
candidate = os.path.join(location, program)
if os.path.isfile(candidate) and os.access(candidate, os.X_OK):
candidates.append(candidate)
return candidates


def programs_not_in_path(programs):
"""Returns all the programs that are not found in the PATH."""
return [program for program in programs if not which(program)]
Expand All @@ -74,7 +67,9 @@ def _open_for_write(filename):

def _get_cache_filename(name, filename):
"""Returns the cache location for filename and linter name."""
filename = os.path.abspath(filename)[1:]
filename = os.path.abspath(filename)
filename = os.path.splitdrive(filename)[1]
filename = filename.lstrip(os.path.sep)
home_folder = os.path.expanduser('~')
base_cache_dir = os.path.join(home_folder, '.git-lint', 'cache')

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
install_requires=[
'docopt',
'pyyaml',
'pathlib2',
'pathlib2;python_version<="3.4"',
'termcolor',
'colorama;platform_system=="Windows"',
'backports.shutil_which;python_version<"3.4"',
# Packages specific to linters. They are optional, but to ease the use
# we prefer to put them here.
'docutils',
Expand Down
2 changes: 1 addition & 1 deletion test/unittest/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,4 @@ def test_which_absolute_path(self):
self.fs.create_file(filename)
os.chmod(filename, 0o755)

self.assertEqual([filename], utils.which(filename))
self.assertEqual(filename, utils.which(filename))