Skip to content

Commit 560a971

Browse files
Release 1.2.5
2 parents c66885c + bf1bd90 commit 560a971

File tree

6 files changed

+30
-41
lines changed

6 files changed

+30
-41
lines changed

dist/isort-1.2.3.tar.gz

-4 Bytes
Binary file not shown.

dist/isort-1.2.4.tar.gz

5.54 KB
Binary file not shown.

dist/isort-1.2.5.tar.gz

5.86 KB
Binary file not shown.

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__ = "1.2.3"
28+
__version__ = "1.2.5"

isort/isort.py

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929

3030
import copy
3131
import os
32-
from sys import path as PYTHONPATH, stderr
32+
from sys import path as PYTHONPATH
33+
from sys import stderr
3334

34-
from natsort import natsorted
3535
from pies import *
3636

3737
from . import settings
38+
from natsort import natsorted
3839

3940

4041
class Sections(object):
@@ -60,9 +61,11 @@ def __init__(self, file_path=None, file_contents=None, **setting_overrides):
6061
file_name = file_name[file_name.rfind('/') + 1:]
6162
if file_name in self.config['skip']:
6263
print("WARNING: {0} was skipped as it's listed in 'skip' setting".format(file_path), file=stderr)
63-
self.file_path = file_path
64-
with open(file_path) as file:
65-
file_contents = file.read()
64+
file_contents = None
65+
else:
66+
self.file_path = file_path
67+
with open(file_path) as file:
68+
file_contents = file.read()
6669

6770
if file_contents is None:
6871
return
@@ -222,21 +225,22 @@ def _add_formatted_imports(self):
222225
if straight_modules or from_modules:
223226
output.append("")
224227

225-
while output[-1:] == [""]:
228+
while map(unicode.strip, output[-1:]) == [""]:
226229
output.pop()
227230

228-
while self.import_index + 2 < len(self.out_lines) and self.out_lines[self.import_index + 1] == "":
229-
self.out_lines.pop(self.import_index + 1)
231+
self.out_lines[self.import_index:1] = output
230232

231-
if len(self.out_lines) > self.import_index + 1:
232-
next_construct = self.out_lines[self.import_index + 1]
233+
imports_tail = self.import_index + len(output)
234+
while map(unicode.strip, self.out_lines[imports_tail: imports_tail + 1]) == [""]:
235+
self.out_lines.pop(imports_tail)
236+
237+
if len(self.out_lines) > imports_tail:
238+
next_construct = self.out_lines[imports_tail]
233239
if next_construct.startswith("def") or next_construct.startswith("class") or \
234240
next_construct.startswith("@"):
235-
output += ["", ""]
241+
self.out_lines[imports_tail:1] = ["", ""]
236242
else:
237-
output += [""]
238-
239-
self.out_lines[self.import_index:1] = output
243+
self.out_lines[imports_tail:1] = [""]
240244

241245
@staticmethod
242246
def _strip_comments(line):
@@ -280,29 +284,14 @@ def _parse(self):
280284
import_string = import_string.replace("[[i]]", "_import")
281285

282286
imports = import_string.split()
283-
if "as" in imports and import_type != 'from':
284-
while True:
285-
try:
286-
index = imports.index('as')
287-
except:
288-
break
289-
self.as_map[imports[index - 1]] = imports[index + 1]
290-
from_import = imports[index - 1]
291-
module_placment = self.place_module(from_import)
292-
self.imports[module_placment][import_type].update([from_import])
293-
del imports[index -1:index + 2]
294-
elif import_type == 'from' and "as" in imports:
295-
while True:
296-
try:
297-
index = imports.index('as')
298-
except:
299-
break
300-
from_import = imports[0]
301-
self.as_map[from_import] = imports[index + 1]
302-
module_placment = self.place_module(from_import)
303-
imports = ["{0} as {1}".format(imports[index - 1], imports[index + 1])]
304-
self.imports[module_placment][import_type].setdefault(from_import, set()).update(imports)
305-
del imports[index -1:index + 1]
287+
if "as" in imports:
288+
while "as" in imports:
289+
index = imports.index('as')
290+
if import_type == "from":
291+
self.as_map[imports[0] + "." + imports[index -1]] = imports[index + 1]
292+
else:
293+
self.as_map[imports[index -1]] = imports[index + 1]
294+
del imports[index:index + 2]
306295
if import_type == "from":
307296
impot_from = imports.pop(0)
308297
root = self.imports[self.place_module(impot_from)][import_type]

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env python
22

3-
from distutils.core import setup
3+
from setuptools import setup
44

55
setup(name='isort',
6-
version='1.2.3',
6+
version='1.2.5',
77
description='A Python utility / library to sort Python imports.',
88
author='Timothy Crosley',
99
author_email='[email protected]',
1010
url='https://github.com/timothycrosley/isort',
1111
download_url='https://github.com/timothycrosley/isort/blob/master'
12-
'/dist/isort-1.2.3.tar.gz?raw=true',
12+
'/dist/isort-1.2.5.tar.gz?raw=true',
1313
license="MIT",
1414
scripts=['scripts/isort'],
1515
packages=['isort'],

0 commit comments

Comments
 (0)