summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Edmund Crosley <timothy.crosley@gmail.com>2015-08-21 18:24:09 -0700
committerTimothy Edmund Crosley <timothy.crosley@gmail.com>2015-08-21 18:24:09 -0700
commit8a99dc85fe2f1f1fb831b44dafb8512e74f4680a (patch)
tree20af2bc37c9f7e0420d8e2bd7c0ecae5bc5cfb75
parentd41448e16dba92076b728a0072349d7a8d017924 (diff)
parent05adfd26ae02fb32783ca2dea3b265ce4831a80e (diff)
downloadisort-8a99dc85fe2f1f1fb831b44dafb8512e74f4680a.tar.gz
Merge pull request #306 from dchanm/globbing
Add globbing support, fixes timothycrosley/isort#292
-rw-r--r--isort/isort.py12
-rwxr-xr-xisort/main.py1
-rw-r--r--isort/settings.py1
3 files changed, 12 insertions, 2 deletions
diff --git a/isort/isort.py b/isort/isort.py
index 65ce7399..d7cb9b36 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -28,6 +28,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
import codecs
import copy
+import fnmatch
import io
import itertools
import os
@@ -94,10 +95,11 @@ class SortImports(object):
self.file_path = file_path or ""
if file_path and not file_contents:
file_path = os.path.abspath(file_path)
- if self._should_skip(file_path):
+ if self._should_skip(file_path) or self._should_skip_glob(file_path):
self.skipped = True
if self.config['verbose']:
- print("WARNING: {0} was skipped as it's listed in 'skip' setting".format(file_path))
+ print("WARNING: {0} was skipped as it's listed in 'skip' setting"
+ " or matches a glob in 'skip_glob' setting".format(file_path))
file_contents = None
else:
self.file_path = file_path
@@ -205,6 +207,12 @@ class SortImports(object):
return True
position = os.path.split(position[0])
+ def _should_skip_glob(self, filename):
+ for glob in self.config['skip_glob']:
+ if fnmatch.fnmatch(filename, glob):
+ return True
+ return False
+
def place_module(self, moduleName):
"""Tries to determine if a module is a python std import, third party import, or project code:
diff --git a/isort/main.py b/isort/main.py
index 47a0c3e4..b1790177 100755
--- a/isort/main.py
+++ b/isort/main.py
@@ -135,6 +135,7 @@ def create_parser():
parser.add_argument('-s', '--skip', help='Files that sort imports should skip over.', dest='skip', action='append')
parser.add_argument('-ns', '--dont-skip', help='Files that sort imports should never skip over.',
dest='not_skip', action='append')
+ parser.add_argument('-sg', '--skip-glob', help='Files that sort imports should skip over.', dest='skip_glob', action='append')
parser.add_argument('-t', '--top', help='Force specific imports to the top of their appropriate section.',
dest='force_to_top', action='append')
parser.add_argument('-f', '--future', dest='known_future_library', action='append',
diff --git a/isort/settings.py b/isort/settings.py
index 6a96ee11..c9bed194 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -43,6 +43,7 @@ WrapModes = namedtuple('WrapModes', WrapModes)(*range(len(WrapModes)))
# Note that none of these lists must be complete as they are simply fallbacks for when included auto-detection fails.
default = {'force_to_top': [],
'skip': ['__init__.py', ],
+ 'skip_glob': [],
'line_length': 79,
'wrap_length': 0,
'sections': DEFAULT_SECTIONS,