summaryrefslogtreecommitdiff
path: root/isort
diff options
context:
space:
mode:
authorTimothy Edmund Crosley <timothy.crosley@gmail.com>2019-03-06 00:09:35 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-03-06 00:22:20 -0800
commit91ae94e477d066f133a889d13f3bd25363785258 (patch)
treebc7978a7084e1f34e6366ee6c26037589c2b13e3 /isort
parenta856e15f8351387b37c2be663b654c6667ff3d78 (diff)
downloadisort-91ae94e477d066f133a889d13f3bd25363785258.tar.gz
Merge in improvement for safe skips
Diffstat (limited to 'isort')
-rw-r--r--isort/isort.py3
-rw-r--r--isort/main.py6
-rw-r--r--isort/settings.py16
3 files changed, 14 insertions, 11 deletions
diff --git a/isort/isort.py b/isort/isort.py
index 05227cb9..481d7d14 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -69,6 +69,7 @@ class SortImports(object):
show_diff: bool = False,
settings_path: Optional[str] = None,
ask_to_apply: bool = False,
+ check_skip: bool = True,
**setting_overrides: Any
) -> None:
if not settings_path and file_path:
@@ -89,7 +90,7 @@ class SortImports(object):
self.file_path = file_path or ""
if file_path:
file_path = os.path.abspath(file_path)
- if settings.file_should_be_skipped(file_path, self.config):
+ if check_skip and settings.file_should_be_skipped(file_path, self.config):
self.skipped = True
if self.config['verbose']:
print("WARNING: {0} was skipped as it's listed in 'skip' setting"
diff --git a/isort/main.py b/isort/main.py
index 4d6d5bd1..de30bd25 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -82,7 +82,7 @@ class SortAttempt(object):
def sort_imports(file_name: str, **arguments: Any) -> Optional[SortAttempt]:
try:
- result = SortImports(file_name, **arguments)
+ result = SortImports(file_name, check_skip=False, **arguments)
return SortAttempt(result.incorrectly_sorted, result.skipped)
except IOError as e:
print("WARNING: Unable to parse file {0} due to {1}".format(file_name, e))
@@ -96,10 +96,6 @@ def iter_source_code(paths: Iterable[str], config: MutableMapping[str, Any], ski
for path in paths:
if os.path.isdir(path):
- if file_should_be_skipped(path, config, os.getcwd()):
- skipped.append(path)
- continue
-
for dirpath, dirnames, filenames in os.walk(
path, topdown=True, followlinks=True
):
diff --git a/isort/settings.py b/isort/settings.py
index 68e35a24..b11d2e6b 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -51,7 +51,8 @@ MAX_CONFIG_SEARCH_DEPTH = 25 # The number of parent directories isort will look
DEFAULT_SECTIONS = ('FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER')
safety_exclude_re = re.compile(
- r"/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|lib/python[0-9].[0-9]+)/"
+ r"/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|\.pants\.d"
+ r"|lib/python[0-9].[0-9]+)/"
)
@@ -373,16 +374,21 @@ def _get_config_data(file_path: str, sections: Iterable[str]) -> Dict[str, Any]:
def file_should_be_skipped(
filename: str,
config: Mapping[str, Any],
- path: str = '/'
+ path: str = ''
) -> bool:
- """Returns True if the file should be skipped based on the passed in settings."""
+ """Returns True if the file and/or folder should be skipped based on the passed in settings."""
os_path = os.path.join(path, filename)
+
normalized_path = os_path.replace('\\', '/')
if normalized_path[1:2] == ':':
normalized_path = normalized_path[2:]
- if config['safety_excludes'] and safety_exclude_re.search(normalized_path):
- return True
+ if config['safety_excludes']:
+ check_exclude = '/' + filename.replace('\\', '/') + '/'
+ if path and os.path.basename(path) in ('lib', ):
+ check_exclude = '/' + os.path.basename(path) + check_exclude
+ if safety_exclude_re.search(check_exclude):
+ return True
for skip_path in config['skip']:
if posixpath.abspath(normalized_path) == posixpath.abspath(skip_path.replace('\\', '/')):