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 5 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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: required
dist: trusty
language: python
python:
- 2.7
# - 2.7
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hustlijian It's not acceptable to get rid of the Python 2.7 support.

- 3.4
- 3.5
- 3.6
Expand All @@ -13,6 +13,7 @@ cache: pip
install:
- pip install .[dev,test] coveralls
- bash scripts/install-linters.sh
- pip install -r requirements-dev.txt
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be necessary as the pip command above is also installing dev and test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, I see colorama will installed: travis-jobs

# command to run tests
before_script:
- export PATH=$PATH:/tmp/pmd-bin/bin:/usr/local/bin
Expand Down
2 changes: 2 additions & 0 deletions gitlint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

import docopt
import termcolor
import colorama
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer colorama to be a dependency only for windows systems.

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
6 changes: 2 additions & 4 deletions gitlint/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ 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 +104,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
18 changes: 2 additions & 16 deletions gitlint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# This can be just pathlib when 2.7 and 3.4 support is dropped.
import pathlib2 as pathlib
from shutil import which
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which does not.exist in python 2.7



def filter_lines(lines, filter_regex, groups=None):
Expand All @@ -43,22 +44,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 @@ -75,6 +60,7 @@ 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 = filename.lstrip(":\\") # for windows
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't a drive letter appears before :\?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed by filename = os.path.abspath(filename)[1:]

home_folder = os.path.expanduser('~')
base_cache_dir = os.path.join(home_folder, '.git-lint', 'cache')

Expand Down
7 changes: 7 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
termcolor
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Termcolor and colorama are not dev dependencies. But as said above, colorama should only be required for windows.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be removed an instead add the dependencies to the setup file. But colorama should only be required for windows.

See https://hynek.me/articles/conditional-python-dependencies/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i will change them to use setup.py, declaring-platform-specific-dependencies

colorama
nose
docopt
pyfakefs
pyyaml
pathlib2
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))