diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2014-04-27 17:59:37 -0400 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2014-04-27 17:59:37 -0400 |
commit | e74a45c0c4bec1d7b063fa4d39dd973eabc17056 (patch) | |
tree | 2c870920c8581bd8fb9234273af8065c7bd38e5e | |
parent | 2f35f0600594701ab9051a31f3b99572c28d24e6 (diff) | |
download | isort-feature/magic-import-support.tar.gz |
Build importmagic index on first use of isortfeature/magic-import-support
-rw-r--r-- | isort/isort.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/isort/isort.py b/isort/isort.py index 0df821fd..fa8a955d 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -38,11 +38,11 @@ from sys import stderr, stdout from natsort import natsorted from pies.overrides import * -from . import settings +from . import _importmagic, settings SECTION_NAMES = ("FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER") SECTIONS = namedtuple('Sections', SECTION_NAMES)(*range(len(SECTION_NAMES))) - +_IMPORT_MAGIC_INDEX = None class SortImports(object): incorrectly_sorted = False @@ -65,6 +65,13 @@ class SortImports(object): else: self.config[key] = value + + if _importmagic.installed and self.config['magic_add'] or self.config['magic_remove']: + global _IMPORT_MAGIC_INDEX + if not _IMPORT_MAGIC_INDEX: + _IMPORT_MAGIC_INDEX = _importmagic.index.SymbolIndex() + _IMPORT_MAGIC_INDEX.build_index(PYTHONPATH) + indent = str(self.config['indent']) if indent.isdigit(): indent = " " * int(indent) |