Skip to content

Commit

Permalink
Fixed #1277 & #1278: New line detection issues on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 11, 2020
1 parent d36e915 commit 90617aa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Changelog

NOTE: isort follows the [semver](https://semver.org/) versioning standard.

### 5.0.8 July 11, 2020
- Fixed #1277 & #1278: New line detection issues on Windows.

### 5.0.7 July 9, 2020
- Fixed #1306: unexpected --diff behavior.
- Fixed #1279: Fixed NOQA comment regression.
Expand Down
6 changes: 3 additions & 3 deletions isort/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,14 @@ def _sort_imports(
if not line_separator:
line_separator = "\n"
else:
if not line_separator:
line_separator = line[-1]
stripped_line = line.strip()
if stripped_line and not line_separator:
line_separator = line[len(line.rstrip()):]

for file_skip_comment in FILE_SKIP_COMMENTS:
if file_skip_comment in line:
raise FileSkipComment("Passed in content")

stripped_line = line.strip()
if (
(index == 0 or (index in (1, 2) and not contains_imports))
and stripped_line.startswith("#")
Expand Down
21 changes: 21 additions & 0 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,24 @@ def test_add_imports_shouldnt_move_lower_comments_issue_1300():
ANSWER = 42
"""
assert isort.code(test_input, add_imports=["from os import path"]) == test_input


def test_windows_newline_issue_1277():
"""Test to ensure windows new lines are correctly handled within indented scopes.
See: https://github.com/timothycrosley/isort/issues/1277
"""
assert (
isort.code("\ndef main():\r\n import time\r\n\n import sys\r\n") ==
"\ndef main():\r\n import sys\r\n import time\r\n"
)


def test_windows_newline_issue_1278():
"""Test to ensure windows new lines are correctly handled within indented scopes.
See: https://github.com/timothycrosley/isort/issues/1278
"""
assert isort.check_code(
"\ntry:\r\n import datadog_agent\r\n\r\n "
"from ..log import CheckLoggingAdapter, init_logging\r\n\r\n init_logging()\r\n"
"except ImportError:\r\n pass\r\n"
)

0 comments on commit 90617aa

Please sign in to comment.