Skip to content

Commit 33b6b71

Browse files
committed
updated isort to latest version #174
1 parent 2804801 commit 33b6b71

6 files changed

Lines changed: 173 additions & 119 deletions

File tree

pythonFiles/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.2.2"
28+
__version__ = "4.2.5"

pythonFiles/isort/__main__

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from isort.main import main
2+
3+
main()

pythonFiles/isort/isort.py

Lines changed: 136 additions & 106 deletions
Large diffs are not rendered by default.

pythonFiles/isort/main.py

100644100755
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ def iter_source_code(paths, config, skipped):
6161
"""Iterate over all Python source files defined in paths."""
6262
for path in paths:
6363
if os.path.isdir(path):
64-
if should_skip(path, config):
64+
if should_skip(path, config, os.getcwd()):
6565
skipped.append(path)
6666
continue
6767

6868
for dirpath, dirnames, filenames in os.walk(path, topdown=True):
6969
for dirname in list(dirnames):
70-
if should_skip(dirname, config):
70+
if should_skip(dirname, config, dirpath):
7171
skipped.append(dirname)
7272
dirnames.remove(dirname)
7373
for filename in filenames:
7474
if filename.endswith('.py'):
75-
if should_skip(filename, config):
75+
if should_skip(filename, config, dirpath):
7676
skipped.append(filename)
7777
else:
7878
yield os.path.join(dirpath, filename)
@@ -162,6 +162,8 @@ def create_parser():
162162
help='Force sortImports to recognize a module as being part of a third party library.')
163163
parser.add_argument('-p', '--project', dest='known_first_party', action='append',
164164
help='Force sortImports to recognize a module as being part of the current python project.')
165+
parser.add_argument('--virtual-env', dest='virtual_env',
166+
help='Virtual environment to use for determining whether a package is third-party')
165167
parser.add_argument('-m', '--multi_line', dest='multi_line_output', type=int, choices=[0, 1, 2, 3, 4, 5],
166168
help='Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging, 4-vert-grid, '
167169
'5-vert-grid-grouped).')
@@ -181,10 +183,14 @@ def create_parser():
181183
parser.add_argument('-c', '--check-only', action='store_true', default=False, dest="check",
182184
help='Checks the file for unsorted / unformatted imports and prints them to the '
183185
'command line without modifying the file.')
186+
parser.add_argument('-ws', '--enforce-white-space', action='store_true', default=False, dest="enforce_white_space",
187+
help='Tells isort to enforce white space difference when --check-only is being used.')
184188
parser.add_argument('-sl', '--force-single-line-imports', dest='force_single_line', action='store_true',
185189
help='Forces all from imports to appear on their own line')
186190
parser.add_argument('--force_single_line_imports', dest='force_single_line', action='store_true',
187191
help=argparse.SUPPRESS)
192+
parser.add_argument('-ds', '--no-sections', help='Put all imports into the same section bucket', dest='no_sections',
193+
action='store_true')
188194
parser.add_argument('-sd', '--section-default', dest='default_section',
189195
help='Sets the default section for imports (by default FIRSTPARTY) options: ' +
190196
str(DEFAULT_SECTIONS))
@@ -197,6 +203,8 @@ def create_parser():
197203
help='Recursively look for Python files of which to sort imports')
198204
parser.add_argument('-ot', '--order-by-type', dest='order_by_type',
199205
action='store_true', help='Order imports by type in addition to alphabetically')
206+
parser.add_argument('-dt', '--dont-order-by-type', dest='dont_order_by_type',
207+
action='store_true', help='Only order imports alphabetically, do not attempt type ordering')
200208
parser.add_argument('-ac', '--atomic', dest='atomic', action='store_true',
201209
help="Ensures the output doesn't save if the resulting file contains syntax errors.")
202210
parser.add_argument('-cs', '--combine-star', dest='combine_star', action='store_true',
@@ -218,13 +226,18 @@ def create_parser():
218226
help="Specifies how long lines that are wrapped should be, if not set line_length is used.")
219227
parser.add_argument('-fgw', '--force-grid-wrap', action='store_true', dest="force_grid_wrap",
220228
help='Force from imports to be grid wrapped regardless of line length')
229+
parser.add_argument('-fass', '--force-alphabetical-sort-within-sections', action='store_true',
230+
dest="force_alphabetical_sort", help='Force all imports to be sorted alphabetically within a '
231+
'section')
221232
parser.add_argument('-fas', '--force-alphabetical-sort', action='store_true', dest="force_alphabetical_sort",
222233
help='Force all imports to be sorted as a single section')
223234
parser.add_argument('-fss', '--force-sort-within-sections', action='store_true', dest="force_sort_within_sections",
224-
help='Force imports to be sorted by module, independant of import_type')
225-
235+
help='Force imports to be sorted by module, independent of import_type')
236+
parser.add_argument('-lbt', '--lines-between-types', dest='lines_between_types', type=int)
226237

227238
arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value)
239+
if 'dont_order_by_type' in arguments:
240+
arguments['order_by_type'] = False
228241
return arguments
229242

230243

@@ -234,6 +247,10 @@ def main():
234247
print(INTRO)
235248
return
236249

250+
if 'settings_path' in arguments:
251+
sp = arguments['settings_path']
252+
arguments['settings_path'] = os.path.abspath(sp) if os.path.isdir(sp) else os.path.dirname(os.path.abspath(sp))
253+
237254
file_names = arguments.pop('files', [])
238255
if file_names == ['-']:
239256
SortImports(file_contents=sys.stdin.read(), write_to_stdout=True, **arguments)

pythonFiles/isort/pie_slice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
88
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9-
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copie_slice of the Software, and
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
1010
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1111
12-
The above copyright notice and this permission notice shall be included in all copie_slice or
12+
The above copyright notice and this permission notice shall be included in all copies or
1313
substantial portions of the Software.
1414
1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED

pythonFiles/isort/settings.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
'line_length': 79,
4949
'wrap_length': 0,
5050
'sections': DEFAULT_SECTIONS,
51+
'no_sections': False,
5152
'known_future_library': ['__future__'],
5253
'known_standard_library': ["abc", "anydbm", "argparse", "array", "asynchat", "asyncore", "atexit", "base64",
5354
"BaseHTTPServer", "bisect", "bz2", "calendar", "cgitb", "cmd", "codecs",
@@ -68,7 +69,7 @@
6869
"timeit", "trace", "traceback", "unittest", "urllib", "urllib2", "urlparse",
6970
"usercustomize", "uuid", "warnings", "weakref", "webbrowser", "whichdb", "xml",
7071
"xmlrpclib", "zipfile", "zipimport", "zlib", 'builtins', '__builtin__', 'thread',
71-
"binascii", "statistics", "unicodedata", "fcntl"],
72+
"binascii", "statistics", "unicodedata", "fcntl", 'pathlib'],
7273
'known_third_party': ['google.appengine.api'],
7374
'known_first_party': [],
7475
'multi_line_output': WrapModes.GRID,
@@ -90,17 +91,20 @@
9091
'atomic': False,
9192
'lines_after_imports': -1,
9293
'lines_between_sections': 1,
94+
'lines_between_types': 0,
9395
'combine_as_imports': False,
9496
'combine_star': False,
9597
'include_trailing_comma': False,
9698
'from_first': False,
9799
'verbose': False,
98100
'quiet': False,
99101
'force_adds': False,
102+
'force_alphabetical_sort_within_sections': False,
100103
'force_alphabetical_sort': False,
101104
'force_grid_wrap': False,
102105
'force_sort_within_sections': False,
103-
'show_diff': False}
106+
'show_diff': False,
107+
'enforce_white_space': False}
104108

105109

106110
@lru_cache()
@@ -171,7 +175,7 @@ def _update_with_config_file(file_path, sections, computed_settings):
171175

172176

173177
def _as_list(value):
174-
return filter(bool, [item.strip() for item in value.split(",")])
178+
return filter(bool, [item.strip() for item in value.replace('\n', ',').split(",")])
175179

176180

177181
@lru_cache()
@@ -199,10 +203,10 @@ def _get_config_data(file_path, sections):
199203
return {}
200204

201205

202-
def should_skip(filename, config):
206+
def should_skip(filename, config, path='/'):
203207
"""Returns True if the file should be skipped based on the passed in settings."""
204208
for skip_path in config['skip']:
205-
if skip_path.endswith(filename):
209+
if os.path.join(path, filename).endswith('/' + skip_path.lstrip('/')):
206210
return True
207211

208212
position = os.path.split(filename)

0 commit comments

Comments
 (0)