summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2014-01-29 00:18:42 -0500
committerTimothy Crosley <timothy.crosley@gmail.com>2014-01-29 00:18:42 -0500
commite3acd00d0aecc797c5cf6f914f3be539db93a96a (patch)
treee7a81c0ad5c71ad2da1adcd7c5b3e9595b06744f
parent95e18ca1471c30f94fce31a12af0251b6ed66437 (diff)
downloadisort-e3acd00d0aecc797c5cf6f914f3be539db93a96a.tar.gz
Add support for skippind entire directories
-rw-r--r--.editorconfig2
-rw-r--r--isort/isort.py17
2 files changed, 14 insertions, 5 deletions
diff --git a/.editorconfig b/.editorconfig
index 0bc2e349..c306348f 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,5 +7,5 @@ indent_size = 4
known_first_party = isort
known_third_party = kate
ignore_frosted_errors = E103
-skip = __init__.py,runtests.py
+skip = __init__.py,runtests.py,build
balanced_wrapping = true
diff --git a/isort/isort.py b/isort/isort.py
index ac6ef59f..6489bb26 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -75,9 +75,7 @@ class SortImports(object):
self.file_path = file_path or ""
if file_path:
file_path = os.path.abspath(file_path)
- if "/" in file_name:
- file_name = file_name[file_name.rfind('/') + 1:]
- if file_name in self.config['skip']:
+ if self._should_skip(file_path):
print("WARNING: {0} was skipped as it's listed in 'skip' setting".format(file_path), file=stderr)
file_contents = None
else:
@@ -133,8 +131,19 @@ class SortImports(object):
with codecs.open(self.file_path, encoding='utf-8', mode='w') as output_file:
output_file.write(self.output)
+ def _should_skip(self, filename):
+ """Returns True if the file should be skipped based on the loaded settings."""
+ if filename in self.config['skip']:
+ return True
+
+ position = os.path.split(filename)
+ while position[1]:
+ if position[1] in self.config['skip']:
+ return True
+ position = os.path.split(position[0])
+
def place_module(self, moduleName):
- """ Tries to determine if a module is a python std import, third party import, or project code:
+ """Tries to determine if a module is a python std import, third party import, or project code:
if it can't determine - it assumes it is project code