summaryrefslogtreecommitdiff
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
parenta856e15f8351387b37c2be663b654c6667ff3d78 (diff)
downloadisort-91ae94e477d066f133a889d13f3bd25363785258.tar.gz
Merge in improvement for safe skips
-rw-r--r--.env8
-rw-r--r--.gitignore2
-rw-r--r--CHANGELOG.md6
-rw-r--r--isort/isort.py3
-rw-r--r--isort/main.py6
-rw-r--r--isort/settings.py16
-rw-r--r--test_isort.py7
7 files changed, 29 insertions, 19 deletions
diff --git a/.env b/.env
index eb0a224c..c1f8e396 100644
--- a/.env
+++ b/.env
@@ -12,7 +12,7 @@ fi
export PROJECT_NAME=$OPEN_PROJECT_NAME
export PROJECT_DIR="$PWD"
-if [ ! -d "venv" ]; then
+if [ ! -d ".venv" ]; then
if ! hash pyvenv 2>/dev/null; then
function pyvenv()
{
@@ -31,13 +31,13 @@ if [ ! -d "venv" ]; then
fi
echo "Making venv for $PROJECT_NAME"
- pyvenv venv
- . venv/bin/activate
+ pyvenv .venv
+ . .venv/bin/activate
python setup.py install
pip install -r requirements.txt
fi
-. venv/bin/activate
+. .venv/bin/activate
# Let's make sure this is a hubflow enabled repo
yes | git hf init >/dev/null 2>/dev/null
diff --git a/.gitignore b/.gitignore
index 11a657c4..bc60d34a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -65,7 +65,7 @@ atlassian-ide-plugin.xml
pip-selfcheck.json
# Python3 Venv Files
-venv/
+.venv/
pyvenv.cfg
# mypy
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a19bee52..d4b66cae 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,5 @@
Changelog
=========
-
### 5.0.0 UNRELEASED
**Breaking changes:**
- isort now requires Python 3.4+ to run but continues to support formatting
@@ -12,6 +11,11 @@ Internal:
Planned:
- profile support for common project types (black, django, google, etc)
+### 4.3.11 - March 3, 2019 - hot fix release
+- Fixed issue #876: confused by symlinks pointing to virtualenv gives FIRSTPARTY not THIRDPARTY
+- Fixed issue #873: current version skips every file on travis
+- Additional caching to reduce performance regression introduced in 4.3.5
+
### 4.3.10 - March 2, 2019 - hot fix release
- Fixed Windows incompatibilities (Issue #835)
- Fixed relative import sorting bug (Issue #417)
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('\\', '/')):
diff --git a/test_isort.py b/test_isort.py
index f1f6bbe0..999f1a1e 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2745,6 +2745,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)],
@@ -2752,10 +2753,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