summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-03-05 23:39:34 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-03-05 23:39:34 -0800
commit0ef06b14f27fb67a7e39ad1ef6368d7592a05b99 (patch)
treed2e4ee305a81dae34aca386339a7564d8b9bf9bc
parent2eb32642ab649ebec9e02b0bab587f0a888914b4 (diff)
downloadisort-0ef06b14f27fb67a7e39ad1ef6368d7592a05b99.tar.gz
Add test for pants
-rw-r--r--isort/settings.py11
-rw-r--r--test_isort.py7
2 files changed, 13 insertions, 5 deletions
diff --git a/isort/settings.py b/isort/settings.py
index ea22a74a..56ee223c 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -58,7 +58,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|.pants.d|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]+)/"
)
WrapModes = ('GRID', 'VERTICAL', 'HANGING_INDENT', 'VERTICAL_HANGING_INDENT', 'VERTICAL_GRID', 'VERTICAL_GRID_GROUPED',
@@ -324,8 +325,12 @@ def should_skip(filename, config, path=''):
if normalized_path[1:2] == ':':
normalized_path = normalized_path[2:]
- if config['safety_excludes'] and safety_exclude_re.search('/' + filename.replace('\\', '/') + '/'):
- 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('\\', '/')):
diff --git a/test_isort.py b/test_isort.py
index aa122b09..6f2feeb8 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2742,6 +2742,7 @@ def test_safety_excludes(tmpdir, enabled):
tmpdir.join("victim.py").write("# ...")
tmpdir.mkdir(".tox").join("verysafe.py").write("# ...")
tmpdir.mkdir("lib").mkdir("python3.7").join("importantsystemlibrary.py").write("# ...")
+ tmpdir.mkdir(".pants.d").join("pants.py").write("import os")
config = dict(settings.default.copy(), safety_excludes=enabled)
skipped = []
codes = [str(tmpdir)],
@@ -2749,10 +2750,12 @@ def test_safety_excludes(tmpdir, enabled):
file_names = set(os.path.relpath(f, str(tmpdir)) for f in main.iter_source_code([str(tmpdir)], config, skipped))
if enabled:
assert file_names == {'victim.py'}
- assert len(skipped) == 2
+ assert len(skipped) == 3
else:
assert file_names == {os.sep.join(('.tox', 'verysafe.py')),
- os.sep.join(('lib', 'python3.7', 'importantsystemlibrary.py')), 'victim.py'}
+ os.sep.join(('lib', 'python3.7', 'importantsystemlibrary.py')),
+ os.sep.join(('.pants.d', 'pants.py')),
+ 'victim.py'}
assert not skipped