Skip to content

Commit 026c3d2

Browse files
Merge branch 'release/4.1.1'
2 parents 8ab7ce4 + 319d278 commit 026c3d2

File tree

8 files changed

+31
-8
lines changed

8 files changed

+31
-8
lines changed

ACKNOWLEDGEMENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Code Contributors
5252
- Benjamin ABEL (@benjaminabel)
5353
- Dan Baragan (@danbaragan)
5454
- Rob Cowie (@robcowie)
55+
- Amit Shah (@Amwam)
5556

5657
Documenters
5758
===================

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ Changelog
1717
- Fixed issue #310: Ensure comments don't get duplicated when reformatting imports
1818
- Fixed issue #289: Sections order not being respected
1919
- Fixed issue #296: Made it more clear how to set arguments more then once
20+
21+
### 4.1.1
22+
- Added support for partial file match skips (thanks to @Amwam)
23+
- Added support for --quiet option to only show errors when running isort
24+
- Fixed issue #316: isort added new lines incorrectly when a top-of line comment is present

isort/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
from . import settings
2626
from .isort import SortImports
2727

28-
__version__ = "4.1.0"
28+
__version__ = "4.1.1"

isort/isort.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ def _strip_top_comments(lines):
198198

199199
def _should_skip(self, filename):
200200
"""Returns True if the file should be skipped based on the loaded settings."""
201-
if filename in self.config['skip']:
202-
return True
201+
for skip_path in self.config['skip']:
202+
if skip_path.endswith(filename):
203+
return True
203204

204205
position = os.path.split(filename)
205206
while position[1]:
@@ -795,6 +796,8 @@ def _parse(self):
795796
last = self.out_lines[-1].rstrip()
796797
else:
797798
last = ""
799+
if self.index - 1 == self.import_index:
800+
self.import_index -= len(self.comments['above']['from'].get(import_from, []))
798801

799802
if root.get(import_from, False):
800803
root[import_from].update(imports)
@@ -816,6 +819,8 @@ def _parse(self):
816819
last = self.out_lines[-1].rstrip()
817820
else:
818821
last = ""
822+
if self.index - 1 == self.import_index:
823+
self.import_index -= len(self.comments['above']['straight'].get(module, []))
819824
self.imports[self.place_module(module)][import_type].add(module)
820825

821826

isort/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ def create_parser():
193193
parser.add_argument('-v', '--version', action='version', version='isort {0}'.format(__version__))
194194
parser.add_argument('-vb', '--verbose', action='store_true', dest="verbose",
195195
help='Shows verbose output, such as when files are skipped or when a check is successful.')
196+
parser.add_argument('-q', '--quiet', action='store_true', dest="quiet",
197+
help='Shows extra quiet output, only errors are outputted.')
196198
parser.add_argument('-sp', '--settings-path', dest="settings_path",
197199
help='Explicitly set the settings path instead of auto determining based on file location.')
198200
parser.add_argument('-ff', '--from-first', dest='from_first',
@@ -219,7 +221,8 @@ def main():
219221
if arguments.get('recursive', False):
220222
file_names = iter_source_code(file_names)
221223
num_skipped = 0
222-
print(INTRO)
224+
if not arguments.get('quiet', False):
225+
print(INTRO)
223226
for file_name in file_names:
224227
try:
225228
sort_attempt = SortImports(file_name, **arguments)
@@ -233,7 +236,7 @@ def main():
233236
if wrong_sorted_files:
234237
exit(1)
235238

236-
if num_skipped:
239+
if num_skipped and not arguments.get('quiet', False):
237240
print("Skipped {0} files".format(num_skipped))
238241

239242
if __name__ == "__main__":

isort/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
'combine_star': False,
9393
'include_trailing_comma': False,
9494
'from_first': False,
95-
'verbose': False}
95+
'verbose': False,
96+
'quiet': False}
9697

9798

9899
@lru_cache()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ def run(self):
3939
readme = f.read()
4040

4141
setup(name='isort',
42-
version='4.1.0',
42+
version='4.1.1',
4343
description='A Python utility / library to sort Python imports.',
4444
long_description=readme,
4545
author='Timothy Crosley',
4646
author_email='[email protected]',
4747
url='https://github.com/timothycrosley/isort',
48-
download_url='https://github.com/timothycrosley/isort/archive/4.1.0.tar.gz',
48+
download_url='https://github.com/timothycrosley/isort/archive/4.1.1.tar.gz',
4949
license="MIT",
5050
entry_points={
5151
'console_scripts': [

test_isort.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,3 +1507,11 @@ def test_basic_comment():
15071507
'# Foo\n'
15081508
'import os\n')
15091509
assert SortImports(file_contents=test_input).output == test_input
1510+
1511+
1512+
def test_shouldnt_add_lines():
1513+
"""Ensure that isort doesn't add a blank line when a top of import comment is present, issue #316"""
1514+
test_input = ('"""Text"""\n'
1515+
'# This is a comment\n'
1516+
'import pkg_resources\n')
1517+
assert SortImports(file_contents=test_input).output == test_input

0 commit comments

Comments
 (0)