summaryrefslogtreecommitdiff
path: root/isort
diff options
context:
space:
mode:
authorPeter Grayson <pete@jpgrayson.net>2019-03-01 16:00:08 -0500
committerTimothy Crosley <timothy.crosley@gmail.com>2019-03-02 18:03:21 -0800
commit7c6948397c1b36015e15cfcf26d241f0adcbc50b (patch)
tree09caf7f8736f4062bbb3851f9c95703023834328 /isort
parentbde366e6ce5d2e0d5a34812c9e700510f6172ba5 (diff)
downloadisort-7c6948397c1b36015e15cfcf26d241f0adcbc50b.tar.gz
Merge in fix for #417
Diffstat (limited to 'isort')
-rw-r--r--isort/isort.py11
-rw-r--r--isort/main.py2
-rw-r--r--isort/settings.py1
3 files changed, 7 insertions, 7 deletions
diff --git a/isort/isort.py b/isort/isort.py
index e0995754..2db8cef0 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -255,13 +255,10 @@ class SortImports(object):
@staticmethod
def _module_key(module_name, config, sub_imports=False, ignore_case=False, section_name=None):
- dots = 0
- while module_name.startswith('.'):
- dots += 1
- module_name = module_name[1:]
-
- if dots:
- module_name = '{} {}'.format(('.' * dots), module_name)
+ match = re.match(r'^(\.+)\s*(.*)', module_name)
+ if match:
+ sep = ' ' if config['reverse_relative'] else '_'
+ module_name = sep.join(match.groups())
prefix = ""
if ignore_case:
diff --git a/isort/main.py b/isort/main.py
index 8e38d0e6..616dc2f0 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -254,6 +254,8 @@ def parse_args(argv=None):
parser.add_argument('-r', dest='ambiguous_r_flag', action='store_true')
parser.add_argument('-rm', '--remove-import', dest='remove_imports', action='append',
help='Removes the specified import from all files.')
+ parser.add_argument('-rr', '--reverse-relative', dest='reverse_relative', action='store_true',
+ help='Reverse order of relative imports.')
parser.add_argument('-rc', '--recursive', dest='recursive', action='store_true',
help='Recursively look for Python files of which to sort imports')
parser.add_argument('-s', '--skip', help='Files that sort imports should skip over. If you want to skip multiple '
diff --git a/isort/settings.py b/isort/settings.py
index 8222a9e3..e46dbbb5 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -129,6 +129,7 @@ default = {'force_to_top': [],
'length_sort': False,
'add_imports': [],
'remove_imports': [],
+ 'reverse_relative': False,
'force_single_line': False,
'default_section': 'FIRSTPARTY',
'import_heading_future': '',