diff options
author | Timothy Edmund Crosley <timothy.crosley@gmail.com> | 2019-03-06 00:09:35 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-06 00:09:35 -0800 |
commit | ccca48cbb57d8d591b68afe5435a17f213ba663b (patch) | |
tree | 6cca66411134712787cb84f61ff842129cdd7787 | |
parent | bcec89b0ea45e310a90bc2ca472f4c3a0ba481ce (diff) | |
parent | 61563f3b7183d8e600a9f161e74af9252fb2fdbb (diff) | |
download | isort-ccca48cbb57d8d591b68afe5435a17f213ba663b.tar.gz |
Merge pull request #878 from timothycrosley/feature/fix-issue-873
Feature/fix issue 873
-rw-r--r-- | .env | 8 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | isort/isort.py | 4 | ||||
-rw-r--r-- | isort/main.py | 6 | ||||
-rw-r--r-- | isort/settings.py | 14 | ||||
-rw-r--r-- | test_isort.py | 7 |
7 files changed, 25 insertions, 18 deletions
@@ -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 @@ -65,5 +65,5 @@ atlassian-ide-plugin.xml pip-selfcheck.json # Python3 Venv Files -venv/ +.venv/ pyvenv.cfg diff --git a/CHANGELOG.md b/CHANGELOG.md index fc13703d..05adc187 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ Changelog ========= ### 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) diff --git a/isort/isort.py b/isort/isort.py index 330755bc..f43aefa2 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -47,7 +47,7 @@ class SortImports(object): skipped = False def __init__(self, file_path=None, file_contents=None, write_to_stdout=False, check=False, - show_diff=False, settings_path=None, ask_to_apply=False, **setting_overrides): + show_diff=False, settings_path=None, ask_to_apply=False, check_skip=True, **setting_overrides): if not settings_path and file_path: settings_path = os.path.dirname(os.path.abspath(file_path)) settings_path = settings_path or os.getcwd() @@ -93,7 +93,7 @@ class SortImports(object): self.file_path = file_path or "" if file_path: file_path = os.path.abspath(file_path) - if settings.should_skip(file_path, self.config): + if check_skip and settings.should_skip(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 616dc2f0..b63135e9 100644 --- a/isort/main.py +++ b/isort/main.py @@ -83,7 +83,7 @@ class SortAttempt(object): def sort_imports(file_name, **arguments): 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)) @@ -97,10 +97,6 @@ def iter_source_code(paths, config, skipped): for path in paths: if os.path.isdir(path): - if should_skip(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 e46dbbb5..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|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', @@ -317,14 +318,19 @@ def _get_config_data(file_path, sections): def should_skip(filename, config, path=''): - """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 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 |