Skip to content
This repository has been archived by the owner on Mar 30, 2018. It is now read-only.

Commit

Permalink
Remove external dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
myint committed Dec 1, 2013
1 parent a1d9c82 commit ea01d52
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
13 changes: 5 additions & 8 deletions isort/isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import codecs
import copy
import io
import itertools
import os
import os.path
Expand All @@ -37,9 +38,6 @@
from sys import path as PYTHONPATH
from sys import stderr, stdout

from natsort import natsorted
from pies.overrides import *

from . import settings

SECTION_NAMES = ("FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER")
Expand Down Expand Up @@ -67,9 +65,8 @@ def __init__(self, file_path=None, file_contents=None, write_to_stdout=False, ch
file_contents = None
else:
self.file_path = file_path
with open(file_path) as file_to_import_sort:
with io.open(file_path, encoding='utf-8') as file_to_import_sort:
file_contents = file_to_import_sort.read()
file_contents = PY2 and file_contents.decode('utf8') or file_contents

if file_contents is None or ("isort:" + "skip_file") in file_contents:
return
Expand Down Expand Up @@ -196,7 +193,7 @@ def _add_formatted_imports(self):
output = []
for section in itertools.chain(SECTIONS, self.config['forced_separate']):
straight_modules = list(self.imports[section]['straight'])
straight_modules = natsorted(straight_modules, key=lambda key: self._module_key(key, self.config))
straight_modules = sorted(straight_modules, key=lambda key: self._module_key(key, self.config))

for module in straight_modules:
if module in self.config['remove_imports']:
Expand All @@ -208,14 +205,14 @@ def _add_formatted_imports(self):
output.append("import {0}".format(module))

from_modules = list(self.imports[section]['from'].keys())
from_modules = natsorted(from_modules, key=lambda key: self._module_key(key, self.config))
from_modules = sorted(from_modules, key=lambda key: self._module_key(key, self.config))
for module in from_modules:
if module in self.config['remove_imports']:
continue

import_start = "from {0} import ".format(module)
from_imports = list(self.imports[section]['from'][module])
from_imports = natsorted(from_imports, key=lambda key: self._module_key(key, self.config))
from_imports = sorted(from_imports, key=lambda key: self._module_key(key, self.config))
if self.config['remove_imports']:
from_imports = [line for line in from_imports if not "{0}.{1}".format(module, line) in
self.config['remove_imports']]
Expand Down
2 changes: 0 additions & 2 deletions isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import os
from collections import namedtuple

from pies.overrides import *

MAX_CONFIG_SEARCH_DEPTH = 20 # The number '..' directories isort will look for config file within

WrapModes = ('GRID', 'VERTICAL', 'HANGING_INDENT', 'VERTICAL_HANGING_INDENT', 'VERTICAL_GRID', 'VERTICAL_GRID_GROUPED')
Expand Down
5 changes: 2 additions & 3 deletions scripts/isort
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import argparse

from pies.overrides import *
import sys

from isort import __version__, SortImports, SECTION_NAMES

Expand Down Expand Up @@ -47,7 +46,7 @@ parser.add_argument('-df', '--diff', dest='show_diff', default=False, action='st
help="Prints a diff of all the changes isort would make to a file, instead of changing it in place")
parser.add_argument('-v', '--version', action='version', version='isort {0}'.format(__version__))

arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value)
arguments = dict((key, value) for (key, value) in vars(parser.parse_args()).items() if value)
file_names = arguments.pop('files', [])

if file_names == ['-']:
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,5 @@ def run(self):
license="MIT",
scripts=['scripts/isort'],
packages=['isort'],
requires=['pies', 'natsort'],
install_requires=['pies>=2.0.0', 'natsort>=3.0.0'],
cmdclass={'test': PyTest},
**PyTest.extra_kwargs)

0 comments on commit ea01d52

Please sign in to comment.