Skip to content

Commit

Permalink
Merge pull request #160 from timothycrosley/feature/fix-issue-156
Browse files Browse the repository at this point in the history
Feature/fix issue 156
  • Loading branch information
timothycrosley committed May 15, 2014
2 parents 71d46b1 + cf6855b commit be10c4a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
12 changes: 7 additions & 5 deletions isort/isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def __init__(self, file_path=None, file_contents=None, write_to_stdout=False, ch
if file_path:
file_path = os.path.abspath(file_path)
if self._should_skip(file_path):
print("WARNING: {0} was skipped as it's listed in 'skip' setting".format(file_path), file=stderr)
if self.config['verbose']:
print("WARNING: {0} was skipped as it's listed in 'skip' setting".format(file_path))
file_contents = None
else:
self.file_path = file_path
Expand Down Expand Up @@ -132,16 +133,17 @@ def __init__(self, file_path=None, file_contents=None, write_to_stdout=False, ch
try:
compile(self._strip_top_comments(self.in_lines), self.file_path, 'exec', 0, 1)
print("ERROR: {0} isort would have introduced syntax errors, please report to the project!". \
format(self.file_path), file=stderr)
format(self.file_path))
except SyntaxError:
print("ERROR: {0} File contains syntax errors.".format(self.file_path), file=stderr)
print("ERROR: {0} File contains syntax errors.".format(self.file_path))

return
if check:
if self.output == file_contents:
print("SUCCESS: {0} Everything Looks Good!".format(self.file_path))
if self.config['verbose']:
print("SUCCESS: {0} Everything Looks Good!".format(self.file_path))
else:
print("ERROR: {0} Imports are incorrectly sorted.".format(self.file_path), file=stderr)
print("ERROR: {0} Imports are incorrectly sorted.".format(self.file_path))
self.incorrectly_sorted = True
return

Expand Down
2 changes: 2 additions & 0 deletions isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def main():
parser.add_argument('-cs', '--combine-star', dest='combine_star', action='store_true',
help="Ensures that if a star import is present, nothing else is imported from that namespace.")
parser.add_argument('-v', '--version', action='version', version='isort {0}'.format(__version__))
parser.add_argument('-vb', '--verbose', action='store_true', dest="verbose",
help='Shows verbose output, such as when files are skipped or when a check is successful.')

arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value)
file_names = arguments.pop('files', [])
Expand Down
3 changes: 2 additions & 1 deletion isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
'atomic': False,
'lines_after_imports': -1,
'combine_as_imports': False,
'combine_star': False}
'combine_star': False,
'verbose': False}


@lru_cache()
Expand Down
2 changes: 1 addition & 1 deletion test_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def test_check_newline_in_imports(capsys):
' sub3\n)\n')

SortImports(file_contents=test_input, multi_line_output=WrapModes.VERTICAL_HANGING_INDENT, line_length=20,
check=True)
check=True, verbose=True)
out, err = capsys.readouterr()
assert 'SUCCESS' in out

Expand Down

0 comments on commit be10c4a

Please sign in to comment.