summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2020-10-12 23:37:53 -0700
committerTimothy Crosley <timothy.crosley@gmail.com>2020-10-12 23:37:53 -0700
commit70de1f0b489dd523a2bdb16c7e954a3ab6205644 (patch)
treed2b82541d7636649b8cd5168ac9bb73f010b38fd
parentb1423cdba7858445f3ad3a82b6c88f5136f14be9 (diff)
parent6bb47b7acc1554ecb59d2855e9110c447162f674 (diff)
downloadisort-70de1f0b489dd523a2bdb16c7e954a3ab6205644.tar.gz
Merge branch 'master' of https://github.com/timothycrosley/isort into develop
-rw-r--r--CHANGELOG.md3
-rw-r--r--isort/_version.py2
-rw-r--r--isort/parse.py35
-rw-r--r--pyproject.toml2
-rw-r--r--tests/unit/test_regressions.py27
5 files changed, 59 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c8231bd0..a94901a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ Changelog
NOTE: isort follows the [semver](https://semver.org/) versioning standard.
Find out more about isort's release policy [here](https://pycqa.github.io/isort/docs/major_releases/release_policy/).
+### 5.6.4 October 12, 2020
+ - Fixed #1556: Empty line added between imports that should be skipped.
+
### 5.6.3 October 11, 2020
- Improved packaging of test files alongside source distribution (see: https://github.com/PyCQA/isort/pull/1555).
diff --git a/isort/_version.py b/isort/_version.py
index 06497b9f..f0b716b2 100644
--- a/isort/_version.py
+++ b/isort/_version.py
@@ -1 +1 @@
-__version__ = "5.6.3"
+__version__ = "5.6.4"
diff --git a/isort/parse.py b/isort/parse.py
index 96468f09..fe3dd157 100644
--- a/isort/parse.py
+++ b/isort/parse.py
@@ -218,17 +218,36 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte
import_index = index - 1
while import_index and not in_lines[import_index - 1]:
import_index -= 1
- elif "isort:skip" in line or "isort: skip" in line:
- commentless = line.split("#", 1)[0]
+ else:
+ commentless = line.split("#", 1)[0].strip()
if (
- "(" in commentless
- and not commentless.rstrip().endswith(")")
- and import_index < line_count
+ ("isort:skip" in line or "isort: skip" in line)
+ and "(" in commentless
+ and ")" not in commentless
):
import_index = index
- while import_index < line_count and not commentless.rstrip().endswith(")"):
- commentless = in_lines[import_index].split("#", 1)[0]
- import_index += 1
+
+ starting_line = line
+ while "isort:skip" in starting_line or "isort: skip" in starting_line:
+ commentless = starting_line.split("#", 1)[0]
+ if (
+ "(" in commentless
+ and not commentless.rstrip().endswith(")")
+ and import_index < line_count
+ ):
+
+ while import_index < line_count and not commentless.rstrip().endswith(
+ ")"
+ ):
+ commentless = in_lines[import_index].split("#", 1)[0]
+ import_index += 1
+ else:
+ import_index += 1
+
+ if import_index >= line_count:
+ break
+ else:
+ starting_line = in_lines[import_index]
line, *end_of_line_comment = line.split("#", 1)
if ";" in line:
diff --git a/pyproject.toml b/pyproject.toml
index a91cea2a..7047b0ad 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,7 +3,7 @@ line-length = 100
[tool.poetry]
name = "isort"
-version = "5.6.3"
+version = "5.6.4"
description = "A Python utility / library to sort Python imports."
authors = ["Timothy Crosley <timothy.crosley@gmail.com>"]
license = "MIT"
diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py
index 873cc2f7..c25ed19c 100644
--- a/tests/unit/test_regressions.py
+++ b/tests/unit/test_regressions.py
@@ -1424,6 +1424,33 @@ import os
)
+def test_isort_shouldnt_split_skip_issue_1556():
+ assert isort.check_code(
+ """
+from tools.dependency_pruning.prune_dependencies import ( # isort:skip
+ prune_dependencies,
+)
+from tools.developer_pruning.prune_developers import ( # isort:skip
+ prune_developers,
+)
+""",
+ show_diff=True,
+ profile="black",
+ float_to_top=True,
+ )
+ assert isort.check_code(
+ """
+from tools.dependency_pruning.prune_dependencies import ( # isort:skip
+ prune_dependencies,
+)
+from tools.developer_pruning.prune_developers import x # isort:skip
+""",
+ show_diff=True,
+ profile="black",
+ float_to_top=True,
+ )
+
+
def test_isort_losing_imports_vertical_prefix_from_module_import_wrap_mode_issue_1542():
"""Ensure isort doesnt lose imports when a comment is combined with an import and
wrap mode VERTICAL_PREFIX_FROM_MODULE_IMPORT is used.