Skip to content

Commit

Permalink
Update isort to latest version (4.2.15) (#1135)
Browse files Browse the repository at this point in the history
Fixes #1134 - "Sort Imports messing up some standard library modules"
  • Loading branch information
porglezomp authored and DonJayamanne committed Aug 3, 2017
1 parent fa16982 commit 3b6b6e3
Show file tree
Hide file tree
Showing 7 changed files with 328 additions and 154 deletions.
2 changes: 1 addition & 1 deletion pythonFiles/isort/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
from . import settings
from .isort import SortImports

__version__ = "4.2.5"
__version__ = "4.2.15"
File renamed without changes.
251 changes: 162 additions & 89 deletions pythonFiles/isort/isort.py

Large diffs are not rendered by default.

47 changes: 24 additions & 23 deletions pythonFiles/isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
from isort import SortImports, __version__
from isort.settings import DEFAULT_SECTIONS, default, from_path, should_skip

from .pie_slice import *
from .pie_slice import itemsview


INTRO = """
/#######################################################################\\
INTRO = r"""
/#######################################################################\
`sMMy`
.yyyy- `
Expand Down Expand Up @@ -130,7 +130,7 @@ def run(self):
if incorrectly_sorted:
wrong_sorted_files = True
except IOError as e:
print("WARNING: Unable to parse file {0} due to {1}".format(file_name, e))
print("WARNING: Unable to parse file {0} due to {1}".format(python_file, e))
if wrong_sorted_files:
exit(1)

Expand Down Expand Up @@ -164,37 +164,35 @@ def create_parser():
help='Force sortImports to recognize a module as being part of the current python project.')
parser.add_argument('--virtual-env', dest='virtual_env',
help='Virtual environment to use for determining whether a package is third-party')
parser.add_argument('-m', '--multi_line', dest='multi_line_output', type=int, choices=[0, 1, 2, 3, 4, 5],
parser.add_argument('-m', '--multi-line', dest='multi_line_output', type=int, choices=[0, 1, 2, 3, 4, 5],
help='Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging, 4-vert-grid, '
'5-vert-grid-grouped).')
parser.add_argument('-i', '--indent', help='String to place for indents defaults to " " (4 spaces).',
dest='indent', type=str)
parser.add_argument('-a', '--add_import', dest='add_imports', action='append',
parser.add_argument('-a', '--add-import', dest='add_imports', action='append',
help='Adds the specified import line to all files, '
'automatically determining correct placement.')
parser.add_argument('-af', '--force_adds', dest='force_adds', action='store_true',
parser.add_argument('-af', '--force-adds', dest='force_adds', action='store_true',
help='Forces import adds even if the original file is empty.')
parser.add_argument('-r', '--remove_import', dest='remove_imports', action='append',
parser.add_argument('-r', '--remove-import', dest='remove_imports', action='append',
help='Removes the specified import from all files.')
parser.add_argument('-ls', '--length_sort', help='Sort imports by their string length.',
dest='length_sort', action='store_true', default=False)
parser.add_argument('-ls', '--length-sort', help='Sort imports by their string length.',
dest='length_sort', action='store_true')
parser.add_argument('-d', '--stdout', help='Force resulting output to stdout, instead of in-place.',
dest='write_to_stdout', action='store_true')
parser.add_argument('-c', '--check-only', action='store_true', default=False, dest="check",
parser.add_argument('-c', '--check-only', action='store_true', dest="check",
help='Checks the file for unsorted / unformatted imports and prints them to the '
'command line without modifying the file.')
parser.add_argument('-ws', '--enforce-white-space', action='store_true', default=False, dest="enforce_white_space",
help='Tells isort to enforce white space difference when --check-only is being used.')
parser.add_argument('-ws', '--ignore-whitespace', action='store_true', dest="ignore_whitespace",
help='Tells isort to ignore whitespace differences when --check-only is being used.')
parser.add_argument('-sl', '--force-single-line-imports', dest='force_single_line', action='store_true',
help='Forces all from imports to appear on their own line')
parser.add_argument('--force_single_line_imports', dest='force_single_line', action='store_true',
help=argparse.SUPPRESS)
parser.add_argument('-ds', '--no-sections', help='Put all imports into the same section bucket', dest='no_sections',
action='store_true')
parser.add_argument('-sd', '--section-default', dest='default_section',
help='Sets the default section for imports (by default FIRSTPARTY) options: ' +
str(DEFAULT_SECTIONS))
parser.add_argument('-df', '--diff', dest='show_diff', default=False, action='store_true',
parser.add_argument('-df', '--diff', dest='show_diff', action='store_true',
help="Prints a diff of all the changes isort would make to a file, instead of "
"changing it in place")
parser.add_argument('-e', '--balanced', dest='balanced_wrapping', action='store_true',
Expand All @@ -218,22 +216,25 @@ def create_parser():
help='Shows verbose output, such as when files are skipped or when a check is successful.')
parser.add_argument('-q', '--quiet', action='store_true', dest="quiet",
help='Shows extra quiet output, only errors are outputted.')
parser.add_argument('-sp', '--settings-path', dest="settings_path",
parser.add_argument('-sp', '--settings-path', dest="settings_path",
help='Explicitly set the settings path instead of auto determining based on file location.')
parser.add_argument('-ff', '--from-first', dest='from_first',
help="Switches the typical ordering preference, showing from imports first then straight ones.")
parser.add_argument('-wl', '--wrap-length', dest='wrap_length',
help="Specifies how long lines that are wrapped should be, if not set line_length is used.")
parser.add_argument('-fgw', '--force-grid-wrap', action='store_true', dest="force_grid_wrap",
help='Force from imports to be grid wrapped regardless of line length')
parser.add_argument('-fass', '--force-alphabetical-sort-within-sections', action='store_true',
parser.add_argument('-fgw', '--force-grid-wrap', nargs='?', const=2, type=int, dest="force_grid_wrap",
help='Force number of from imports (defaults to 2) to be grid wrapped regardless of line '
'length')
parser.add_argument('-fass', '--force-alphabetical-sort-within-sections', action='store_true',
dest="force_alphabetical_sort", help='Force all imports to be sorted alphabetically within a '
'section')
parser.add_argument('-fas', '--force-alphabetical-sort', action='store_true', dest="force_alphabetical_sort",
parser.add_argument('-fas', '--force-alphabetical-sort', action='store_true', dest="force_alphabetical_sort",
help='Force all imports to be sorted as a single section')
parser.add_argument('-fss', '--force-sort-within-sections', action='store_true', dest="force_sort_within_sections",
parser.add_argument('-fss', '--force-sort-within-sections', action='store_true', dest="force_sort_within_sections",
help='Force imports to be sorted by module, independent of import_type')
parser.add_argument('-lbt', '--lines-between-types', dest='lines_between_types', type=int)
parser.add_argument('-up', '--use-parentheses', dest='use_parentheses', action='store_true',
help='Use parenthesis for line continuation on lenght limit instead of slashes.')

arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value)
if 'dont_order_by_type' in arguments:
Expand Down Expand Up @@ -267,7 +268,7 @@ def main():
if arguments.get('recursive', False):
file_names = iter_source_code(file_names, config, skipped)
num_skipped = 0
if config.get('verbose', False) or config.get('show_logo', False):
if config['verbose'] or config.get('show_logo', False):
print(INTRO)
for file_name in file_names:
try:
Expand Down
2 changes: 1 addition & 1 deletion pythonFiles/isort/natural.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _atoi(text):


def _natural_keys(text):
return [_atoi(c) for c in re.split('(\d+)', text)]
return [_atoi(c) for c in re.split(r'(\d+)', text)]


def nsorted(to_sort, key=None):
Expand Down
68 changes: 67 additions & 1 deletion pythonFiles/isort/pie_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from __future__ import absolute_import

import abc
import collections
import functools
import sys
from numbers import Integral
Expand Down Expand Up @@ -67,6 +68,7 @@ class Form(with_metaclass(FormType, BaseForm)):
class metaclass(meta):
__call__ = type.__call__
__init__ = type.__init__

def __new__(cls, name, this_bases, d):
if this_bases is None:
return type.__new__(cls, name, (), d)
Expand Down Expand Up @@ -118,6 +120,7 @@ def __instancecheck__(cls, instance):
import builtins
from urllib import parse

input = input
integer_types = (int, )

def u(string):
Expand Down Expand Up @@ -428,7 +431,7 @@ def __eq__(self, other):
if isinstance(other, OrderedDict):
if len(self) != len(other):
return False
for p, q in zip(self.items(), other.items()):
for p, q in zip(self.items(), other.items()):
if p != q:
return False
return True
Expand Down Expand Up @@ -526,3 +529,66 @@ def cache_clear():

else:
from functools import lru_cache


class OrderedSet(collections.MutableSet):

def __init__(self, iterable=None):
self.end = end = []
end += [None, end, end]
self.map = {}
if iterable is not None:
self |= iterable

def __len__(self):
return len(self.map)

def __contains__(self, key):
return key in self.map

def add(self, key):
if key not in self.map:
end = self.end
curr = end[1]
curr[2] = end[1] = self.map[key] = [key, curr, end]

def discard(self, key):
if key in self.map:
key, prev, next = self.map.pop(key)
prev[2] = next
next[1] = prev

def __iter__(self):
end = self.end
curr = end[2]
while curr is not end:
yield curr[0]
curr = curr[2]

def __reversed__(self):
end = self.end
curr = end[1]
while curr is not end:
yield curr[0]
curr = curr[1]

def pop(self, last=True):
if not self:
raise KeyError('set is empty')
key = self.end[1][0] if last else self.end[2][0]
self.discard(key)
return key

def __repr__(self):
if not self:
return '%s()' % (self.__class__.__name__,)
return '%s(%r)' % (self.__class__.__name__, list(self))

def __eq__(self, other):
if isinstance(other, OrderedSet):
return len(self) == len(other) and list(self) == list(other)
return set(self) == set(other)

def update(self, other):
for item in other:
self.add(item)
Loading

0 comments on commit 3b6b6e3

Please sign in to comment.