diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2017-06-04 12:18:07 -0700 |
---|---|---|
committer | Jon Dufresne <jon.dufresne@gmail.com> | 2017-06-04 12:22:00 -0700 |
commit | e4d4f431bdae72b80ba42f51dda17568d3dbab78 (patch) | |
tree | ad07d36b92e4653233dff74dd47113676c61a9b3 | |
parent | cca333c277e633e5be8f4f2134a8517eb87bd67a (diff) | |
download | isort-e4d4f431bdae72b80ba42f51dda17568d3dbab78.tar.gz |
Revert "Revert "Merge pull request #507 from jdufresne/py26""
This reverts commit 5bb3309ff3652d7cd1144e9c081acbe16a8a345e.
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | README.rst | 2 | ||||
-rw-r--r-- | appveyor.yml | 2 | ||||
-rw-r--r-- | isort/isort.py | 21 | ||||
-rwxr-xr-x | isort/main.py | 2 | ||||
-rw-r--r-- | isort/pie_slice.py | 197 | ||||
-rw-r--r-- | isort/settings.py | 5 | ||||
-rwxr-xr-x | setup.py | 1 | ||||
-rw-r--r-- | test_isort.py | 2 | ||||
-rw-r--r-- | tox.ini | 2 |
10 files changed, 26 insertions, 210 deletions
diff --git a/.travis.yml b/.travis.yml index e79ee219..d44fa31b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,6 @@ matrix: - env: TOXENV=isort-check - python: 3.6 env: TOXENV=lint - - python: 2.6 - env: TOXENV=py26 - python: 2.7 env: TOXENV=py27 - python: 3.3 @@ -29,7 +29,7 @@ isort your python imports for you so you don't have to. isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections. It provides a command line utility, Python library and `plugins for various editors <https://github.com/timothycrosley/isort/wiki/isort-Plugins>`_ to quickly sort all your imports. -It currently cleanly supports Python 2.6 - 3.5 without any dependencies. +It currently cleanly supports Python 2.7 - 3.6 without any dependencies. .. image:: https://raw.github.com/timothycrosley/isort/develop/example.gif :alt: Example Usage diff --git a/appveyor.yml b/appveyor.yml index 003d2e58..3b6746b7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,4 +9,4 @@ install: - pip install tox test_script: - - tox -e isort-check,py26,py27,py33,py34,py35,py36 + - tox -e isort-check,py27,py33,py34,py35,py36 diff --git a/isort/isort.py b/isort/isort.py index 16b40b73..e0cddf76 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -32,7 +32,8 @@ import itertools import os import re import sys -from collections import namedtuple +import sysconfig +from collections import OrderedDict, namedtuple from datetime import datetime from difflib import unified_diff from fnmatch import fnmatch @@ -40,7 +41,7 @@ from glob import glob from . import settings from .natural import nsorted -from .pie_slice import OrderedDict, OrderedSet, input, itemsview +from .pie_slice import OrderedSet, input, itemsview KNOWN_SECTION_MAPPING = { 'STDLIB': 'STANDARD_LIBRARY', @@ -261,7 +262,7 @@ class SortImports(object): virtual_env_src = '{0}/src/'.format(virtual_env) # handle case-insensitive paths on windows - stdlib_lib_prefix = os.path.normcase(get_stdlib_path()) + stdlib_lib_prefix = os.path.normcase(sysconfig.get_paths()['stdlib']) for prefix in paths: module_path = "/".join((prefix, module_name.replace(".", "/"))) @@ -485,7 +486,7 @@ class SortImports(object): lines = import_statement.split("\n") line_count = len(lines) if len(lines) > 1: - minimum_length = min([len(line) for line in lines[:-1]]) + minimum_length = min(len(line) for line in lines[:-1]) else: minimum_length = 0 new_import_statement = import_statement @@ -940,18 +941,6 @@ def coding_check(fname, default='utf-8'): return coding -def get_stdlib_path(): - """Returns the path to the standard lib for the current path installation. - - This function can be dropped and "sysconfig.get_paths()" used directly once Python 2.6 support is dropped. - """ - if sys.version_info >= (2, 7): - import sysconfig - return sysconfig.get_paths()['stdlib'] - else: - return os.path.join(sys.prefix, 'lib') - - def exists_case_sensitive(path): """ Returns if the given path exists and also matches the case on Windows. diff --git a/isort/main.py b/isort/main.py index eae7afa5..fd192338 100755 --- a/isort/main.py +++ b/isort/main.py @@ -236,7 +236,7 @@ def create_parser(): 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) + arguments = {key: value for key, value in itemsview(vars(parser.parse_args())) if value} if 'dont_order_by_type' in arguments: arguments['order_by_type'] = False return arguments diff --git a/isort/pie_slice.py b/isort/pie_slice.py index 0122a484..d2f7b0f0 100644 --- a/isort/pie_slice.py +++ b/isort/pie_slice.py @@ -21,7 +21,6 @@ OTHER DEALINGS IN THE SOFTWARE. """ from __future__ import absolute_import -import abc import collections import sys @@ -45,7 +44,7 @@ native_object = object common = ['native_dict', 'native_round', 'native_filter', 'native_map', 'native_range', 'native_str', 'native_chr', 'native_input', 'PY2', 'PY3', 'u', 'itemsview', 'valuesview', 'keysview', 'execute', 'integer_types', - 'native_next', 'native_object', 'with_metaclass', 'OrderedDict', 'lru_cache'] + 'native_next', 'native_object', 'with_metaclass', 'lru_cache'] def with_metaclass(meta, *bases): @@ -83,32 +82,12 @@ def unmodified_isinstance(*bases): """ class UnmodifiedIsInstance(type): - if sys.version_info[0] == 2 and sys.version_info[1] <= 6: - - @classmethod - def __instancecheck__(cls, instance): - if cls.__name__ in (str(base.__name__) for base in bases): - return isinstance(instance, bases) - - subclass = getattr(instance, '__class__', None) - subtype = type(instance) - instance_type = getattr(abc, '_InstanceType', None) - if not instance_type: - class test_object: - pass - instance_type = type(test_object) - if subtype is instance_type: - subtype = subclass - if subtype is subclass or subclass is None: - return cls.__subclasscheck__(subtype) - return (cls.__subclasscheck__(subclass) or cls.__subclasscheck__(subtype)) - else: - @classmethod - def __instancecheck__(cls, instance): - if cls.__name__ in (str(base.__name__) for base in bases): - return isinstance(instance, bases) + @classmethod + def __instancecheck__(cls, instance): + if cls.__name__ in (str(base.__name__) for base in bases): + return isinstance(instance, bases) - return type.__instancecheck__(cls, instance) + return type.__instancecheck__(cls, instance) return with_metaclass(UnmodifiedIsInstance, *bases) @@ -148,7 +127,7 @@ if PY3: else: from itertools import ifilter as filter # noqa: F401 from itertools import imap as map # noqa: F401 - from itertools import izip as zip + from itertools import izip as zip # noqa: F401 from decimal import Decimal, ROUND_HALF_EVEN str = unicode @@ -278,28 +257,10 @@ else: dct['__str__'] = lambda self: self.__unicode__().encode('utf-8') return type.__new__(cls, name, bases, dct) - if sys.version_info[1] <= 6: - def __instancecheck__(cls, instance): - if cls.__name__ == "object": - return isinstance(instance, native_object) - - subclass = getattr(instance, '__class__', None) - subtype = type(instance) - instance_type = getattr(abc, '_InstanceType', None) - if not instance_type: - class test_object: - pass - instance_type = type(test_object) - if subtype is instance_type: - subtype = subclass - if subtype is subclass or subclass is None: - return cls.__subclasscheck__(subtype) - return (cls.__subclasscheck__(subclass) or cls.__subclasscheck__(subtype)) - else: - def __instancecheck__(cls, instance): - if cls.__name__ == "object": - return isinstance(instance, native_object) - return type.__instancecheck__(cls, instance) + def __instancecheck__(cls, instance): + if cls.__name__ == "object": + return isinstance(instance, native_object) + return type.__instancecheck__(cls, instance) class object(with_metaclass(FixStr, object)): pass @@ -307,138 +268,6 @@ else: __all__ = common + ['round', 'dict', 'apply', 'cmp', 'coerce', 'execfile', 'raw_input', 'unpacks', 'str', 'chr', 'input', 'range', 'filter', 'map', 'zip', 'object'] -if sys.version_info[0] == 2 and sys.version_info[1] < 7: - # OrderedDict - # Copyright (c) 2009 Raymond Hettinger - # - # Permission is hereby granted, free of charge, to any person - # obtaining a copy of this software and associated documentation files - # (the "Software"), to deal in the Software without restriction, - # including without limitation the rights to use, copy, modify, merge, - # publish, distribute, sublicense, and/or sell copies of the Software, - # and to permit persons to whom the Software is furnished to do so, - # subject to the following conditions: - # - # The above copyright notice and this permission notice shall be - # included in all copies or substantial portions of the Software. - # - # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - # OTHER DEALINGS IN THE SOFTWARE. - - from UserDict import DictMixin - - class OrderedDict(dict, DictMixin): - - def __init__(self, *args, **kwds): - if len(args) > 1: - raise TypeError('expected at most 1 arguments, got %d' % len(args)) - try: - self.__end - except AttributeError: - self.clear() - self.update(*args, **kwds) - - def clear(self): - self.__end = end = [] - end += [None, end, end] # sentinel node for doubly linked list - self.__map = {} # key --> [key, prev, next] - dict.clear(self) - - def __setitem__(self, key, value): - if key not in self: - end = self.__end - curr = end[1] - curr[2] = end[1] = self.__map[key] = [key, curr, end] - dict.__setitem__(self, key, value) - - def __delitem__(self, key): - dict.__delitem__(self, key) - 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 popitem(self, last=True): - if not self: - raise KeyError('dictionary is empty') - if last: - key = reversed(self).next() - else: - key = iter(self).next() - value = self.pop(key) - return key, value - - def __reduce__(self): - items = [[k, self[k]] for k in self] - tmp = self.__map, self.__end - del self.__map, self.__end - inst_dict = vars(self).copy() - self.__map, self.__end = tmp - if inst_dict: - return (self.__class__, (items,), inst_dict) - return self.__class__, (items,) - - def keys(self): - return list(self) - - setdefault = DictMixin.setdefault - update = DictMixin.update - pop = DictMixin.pop - values = DictMixin.values - items = DictMixin.items - iterkeys = DictMixin.iterkeys - itervalues = DictMixin.itervalues - iteritems = DictMixin.iteritems - - def __repr__(self): - if not self: - return '%s()' % (self.__class__.__name__,) - return '%s(%r)' % (self.__class__.__name__, self.items()) - - def copy(self): - return self.__class__(self) - - @classmethod - def fromkeys(cls, iterable, value=None): - d = cls() - for key in iterable: - d[key] = value - return d - - def __eq__(self, other): - if isinstance(other, OrderedDict): - if len(self) != len(other): - return False - for p, q in zip(self.items(), other.items()): - if p != q: - return False - return True - return dict.__eq__(self, other) - - def __ne__(self, other): - return not self == other -else: - from collections import OrderedDict - if sys.version_info < (3, 2): try: @@ -469,7 +298,7 @@ if sys.version_info < (3, 2): lock = Lock() if maxsize is None: - CACHE = dict() + CACHE = {} @wraps(user_function) def wrapper(*args, **kwds): @@ -487,7 +316,7 @@ if sys.version_info < (3, 2): misses[0] += 1 return result else: - CACHE = OrderedDict() + CACHE = collections.OrderedDict() @wraps(user_function) def wrapper(*args, **kwds): diff --git a/isort/settings.py b/isort/settings.py index a7dc2c7b..f984a94d 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -25,6 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. from __future__ import absolute_import, division, print_function, unicode_literals import fnmatch +import io import os import posixpath from collections import namedtuple @@ -202,7 +203,7 @@ def _as_list(value): @lru_cache() def _get_config_data(file_path, sections): - with open(file_path, 'rU') as config_file: + with io.open(file_path, 'r') as config_file: if file_path.endswith('.editorconfig'): line = '\n' last_position = config_file.tell() @@ -215,7 +216,7 @@ def _get_config_data(file_path, sections): config = configparser.SafeConfigParser() config.readfp(config_file) - settings = dict() + settings = {} for section in sections: if config.has_section(section): settings.update(dict(config.items(section))) @@ -63,7 +63,6 @@ setup(name='isort', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', diff --git a/test_isort.py b/test_isort.py index cfa6202c..1ac94217 100644 --- a/test_isort.py +++ b/test_isort.py @@ -1004,7 +1004,7 @@ def test_settings_combine_instead_of_overwrite(): set(SortImports().config['known_standard_library'] + ['not_std_library']) assert set(SortImports(not_known_standard_library=['thread']).config['known_standard_library']) == \ - set(item for item in SortImports().config['known_standard_library'] if item != 'thread') + {item for item in SortImports().config['known_standard_library'] if item != 'thread'} def test_combined_from_and_as_imports(): @@ -6,7 +6,7 @@ [tox] envlist = isort-check, - py26, py27, py33, py34, py35, py36, pypy, + py27, py33, py34, py35, py36, pypy, lint [testenv] |