Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--diff works incorrectly with files that have CRLF line endings #1348

Closed
Jackenmen opened this issue Jul 26, 2020 · 3 comments
Closed

--diff works incorrectly with files that have CRLF line endings #1348

Jackenmen opened this issue Jul 26, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@Jackenmen
Copy link

Reproduction:

  1. Make a file test.py and save it with Windows line endings (CRLF):
import b
import a


def func():
    x = 1
    y = 2
    z = 3
    c = 4
    return (
        x
        + y
        + z
        + c
    )
  1. Run isort --diff test.py
  2. Get enormously large diff:
--- test.py:before   2020-07-26 02:27:24.604716
+++ test.py:after    2020-07-26 02:27:25.901148
@@ -1,15 +1,15 @@
-import b
-import a
-
-
-def func():
-    x = 1
-    y = 2
-    z = 3
-    c = 4
-    return (
-        x
-        + y
-        + z
-        + c
-    )
+import a
+import b
+
+
+def func():
+    x = 1
+    y = 2
+    z = 3
+    c = 4
+    return (
+        x
+        + y
+        + z
+        + c
+    )

For comparison, saving the file with Unix line endings (LF), gives this diff:

--- test.py:before   2020-07-26 02:29:00.588261
+++ test.py:after    2020-07-26 02:29:24.989417
@@ -1,5 +1,5 @@
+import a
 import b
-import a


 def func():
@timothycrosley
Copy link
Member

Hi @jack1142,

Thanks for raising this issue! Can you confirm what version of isort you are running (you can use isort --version).

Additional optional information to help reproduction:

  • Output of isort . --show-config
  • How you run isort (cmd line options, WSL, command prompt, etc)

Thanks!

~Timothy

@Jackenmen
Copy link
Author

Jackenmen commented Jul 26, 2020

isort version: 5.1.4

Output of `isort . --show-config`
{
    "_known_patterns": null,
    "_section_comments": null,
    "py_version": "py3",
    "force_to_top": [],
    "skip": [
        "buck-out",
        ".tox",
        ".git",
        ".venv",
        ".eggs",
        ".mypy_cache",
        "_build",
        ".hg",
        "build",
        "dist",
        ".stubs/discord"
    ],
    "skip_glob": [],
    "line_length": 88,
    "wrap_length": 0,
    "line_ending": "",
    "sections": [
        "FUTURE",
        "STDLIB",
        "THIRDPARTY",
        "FIRSTPARTY",
        "LOCALFOLDER"
    ],
    "no_sections": false,
    "known_future_library": [
        "__future__"
    ],
    "known_third_party": [
        "google.appengine.api"
    ],
    "known_first_party": [],
    "known_standard_library": [
        "tarfile",
        "py_compile",
        "configparser",
        "fpectl",
        "http",
        "pwd",
        "bdb",
        "base64",
        "syslog",
        "binascii",
        "code",
        "shutil",
        "socketserver",
        "traceback",
        "token",
        "json",
        "stat",
        "pkgutil",
        "filecmp",
        "ensurepip",
        "faulthandler",
        "timeit",
        "xml",
        "formatter",
        "ssl",
        "pipes",
        "sre_parse",
        "getopt",
        "sysconfig",
        "_thread",
        "hmac",
        "select",
        "struct",
        "plistlib",
        "sqlite3",
        "copyreg",
        "difflib",
        "doctest",
        "readline",
        "pydoc",
        "_dummy_thread",
        "fnmatch",
        "profile",
        "selectors",
        "unittest",
        "builtins",
        "inspect",
        "spwd",
        "binhex",
        "numbers",
        "os",
        "tkinter",
        "collections",
        "msilib",
        "gettext",
        "fractions",
        "cgi",
        "curses",
        "signal",
        "warnings",
        "atexit",
        "nntplib",
        "shelve",
        "pdb",
        "unicodedata",
        "subprocess",
        "urllib",
        "secrets",
        "ftplib",
        "email",
        "imghdr",
        "zlib",
        "abc",
        "ntpath",
        "stringprep",
        "uuid",
        "errno",
        "contextlib",
        "gc",
        "tempfile",
        "trace",
        "modulefinder",
        "wave",
        "string",
        "cgitb",
        "fcntl",
        "cProfile",
        "asyncore",
        "mimetypes",
        "crypt",
        "fileinput",
        "pty",
        "mmap",
        "mailcap",
        "lzma",
        "codecs",
        "getpass",
        "statistics",
        "platform",
        "grp",
        "re",
        "queue",
        "rlcompleter",
        "typing",
        "imaplib",
        "argparse",
        "tokenize",
        "types",
        "mailbox",
        "tracemalloc",
        "venv",
        "wsgiref",
        "dis",
        "sys",
        "heapq",
        "uu",
        "time",
        "ctypes",
        "keyword",
        "pstats",
        "netrc",
        "xdrlib",
        "hashlib",
        "asynchat",
        "webbrowser",
        "compileall",
        "dataclasses",
        "symtable",
        "test",
        "weakref",
        "sre_compile",
        "operator",
        "sre_constants",
        "pprint",
        "decimal",
        "calendar",
        "smtpd",
        "winreg",
        "multiprocessing",
        "poplib",
        "chunk",
        "winsound",
        "site",
        "colorsys",
        "tty",
        "imp",
        "io",
        "termios",
        "zipapp",
        "enum",
        "textwrap",
        "sndhdr",
        "threading",
        "audioop",
        "asyncio",
        "glob",
        "linecache",
        "sre",
        "aifc",
        "dbm",
        "posixpath",
        "msvcrt",
        "html",
        "ipaddress",
        "quopri",
        "array",
        "bz2",
        "pickle",
        "smtplib",
        "sched",
        "sunau",
        "concurrent",
        "logging",
        "contextvars",
        "pathlib",
        "dummy_threading",
        "locale",
        "telnetlib",
        "symbol",
        "turtle",
        "pickletools",
        "math",
        "functools",
        "bisect",
        "posix",
        "importlib",
        "reprlib",
        "xmlrpc",
        "zipfile",
        "runpy",
        "random",
        "ossaudiodev",
        "csv",
        "cmath",
        "shlex",
        "nis",
        "turtledemo",
        "itertools",
        "marshal",
        "ast",
        "gzip",
        "socket",
        "codeop",
        "datetime",
        "resource",
        "copy",
        "zipimport",
        "pyclbr",
        "distutils",
        "macpath",
        "cmd",
        "lib2to3",
        "tabnanny",
        "encodings",
        "parser",
        "optparse"
    ],
    "extra_standard_library": [],
    "known_other": {},
    "multi_line_output": "VERTICAL_HANGING_INDENT",
    "forced_separate": [],
    "indent": "    ",
    "comment_prefix": "  #",
    "length_sort": false,
    "length_sort_sections": [],
    "add_imports": [],
    "remove_imports": [],
    "reverse_relative": false,
    "force_single_line": false,
    "single_line_exclusions": [],
    "default_section": "THIRDPARTY",
    "import_headings": {},
    "balanced_wrapping": false,
    "use_parentheses": true,
    "order_by_type": true,
    "atomic": false,
    "lines_after_imports": -1,
    "lines_between_sections": 1,
    "lines_between_types": 0,
    "combine_as_imports": false,
    "combine_star": false,
    "include_trailing_comma": true,
    "from_first": false,
    "verbose": false,
    "quiet": false,
    "force_adds": false,
    "force_alphabetical_sort_within_sections": false,
    "force_alphabetical_sort": false,
    "force_grid_wrap": 0,
    "force_sort_within_sections": false,
    "lexicographical": false,
    "ignore_whitespace": false,
    "no_lines_before": [],
    "no_inline_sort": false,
    "ignore_comments": false,
    "case_sensitive": false,
    "sources": [
        {
            "py_version": "py3",
            "force_to_top": [],
            "skip": [
                "buck-out",
                ".tox",
                ".git",
                ".pants.d",
                ".venv",
                "venv",
                ".eggs",
                "node_modules",
                ".nox",
                ".mypy_cache",
                "_build",
                ".hg",
                "build",
                "dist"
            ],
            "skip_glob": [],
            "line_length": 79,
            "wrap_length": 0,
            "line_ending": "",
            "sections": [
                "FUTURE",
                "STDLIB",
                "THIRDPARTY",
                "FIRSTPARTY",
                "LOCALFOLDER"
            ],
            "no_sections": false,
            "known_future_library": [
                "__future__"
            ],
            "known_third_party": [
                "google.appengine.api"
            ],
            "known_first_party": [],
            "known_standard_library": [
                "tarfile",
                "py_compile",
                "configparser",
                "fpectl",
                "http",
                "pwd",
                "bdb",
                "base64",
                "syslog",
                "binascii",
                "code",
                "shutil",
                "socketserver",
                "traceback",
                "token",
                "json",
                "stat",
                "pkgutil",
                "filecmp",
                "ensurepip",
                "faulthandler",
                "timeit",
                "xml",
                "formatter",
                "ssl",
                "pipes",
                "sre_parse",
                "getopt",
                "sysconfig",
                "_thread",
                "hmac",
                "select",
                "struct",
                "plistlib",
                "sqlite3",
                "copyreg",
                "difflib",
                "doctest",
                "readline",
                "pydoc",
                "_dummy_thread",
                "fnmatch",
                "profile",
                "selectors",
                "unittest",
                "builtins",
                "inspect",
                "spwd",
                "binhex",
                "numbers",
                "os",
                "tkinter",
                "collections",
                "msilib",
                "gettext",
                "fractions",
                "cgi",
                "curses",
                "signal",
                "warnings",
                "atexit",
                "nntplib",
                "shelve",
                "pdb",
                "unicodedata",
                "subprocess",
                "urllib",
                "secrets",
                "ftplib",
                "email",
                "imghdr",
                "zlib",
                "abc",
                "ntpath",
                "stringprep",
                "uuid",
                "errno",
                "contextlib",
                "gc",
                "tempfile",
                "trace",
                "modulefinder",
                "wave",
                "string",
                "cgitb",
                "fcntl",
                "cProfile",
                "asyncore",
                "mimetypes",
                "crypt",
                "fileinput",
                "pty",
                "mmap",
                "mailcap",
                "lzma",
                "codecs",
                "getpass",
                "statistics",
                "platform",
                "grp",
                "re",
                "queue",
                "rlcompleter",
                "typing",
                "imaplib",
                "argparse",
                "tokenize",
                "types",
                "mailbox",
                "tracemalloc",
                "venv",
                "wsgiref",
                "dis",
                "sys",
                "heapq",
                "uu",
                "time",
                "ctypes",
                "keyword",
                "pstats",
                "netrc",
                "xdrlib",
                "hashlib",
                "asynchat",
                "webbrowser",
                "compileall",
                "dataclasses",
                "symtable",
                "test",
                "weakref",
                "sre_compile",
                "operator",
                "sre_constants",
                "pprint",
                "decimal",
                "calendar",
                "smtpd",
                "winreg",
                "multiprocessing",
                "poplib",
                "chunk",
                "winsound",
                "site",
                "colorsys",
                "tty",
                "imp",
                "io",
                "termios",
                "zipapp",
                "enum",
                "textwrap",
                "sndhdr",
                "threading",
                "audioop",
                "asyncio",
                "glob",
                "linecache",
                "sre",
                "aifc",
                "dbm",
                "posixpath",
                "msvcrt",
                "html",
                "ipaddress",
                "quopri",
                "array",
                "bz2",
                "pickle",
                "smtplib",
                "sched",
                "sunau",
                "concurrent",
                "logging",
                "contextvars",
                "pathlib",
                "dummy_threading",
                "locale",
                "telnetlib",
                "symbol",
                "turtle",
                "pickletools",
                "math",
                "functools",
                "bisect",
                "posix",
                "importlib",
                "reprlib",
                "xmlrpc",
                "zipfile",
                "runpy",
                "random",
                "ossaudiodev",
                "csv",
                "cmath",
                "shlex",
                "nis",
                "turtledemo",
                "itertools",
                "marshal",
                "ast",
                "gzip",
                "socket",
                "codeop",
                "datetime",
                "resource",
                "copy",
                "zipimport",
                "pyclbr",
                "distutils",
                "macpath",
                "cmd",
                "lib2to3",
                "tabnanny",
                "encodings",
                "parser",
                "optparse"
            ],
            "extra_standard_library": [],
            "known_other": {},
            "multi_line_output": "GRID",
            "forced_separate": [],
            "indent": "    ",
            "comment_prefix": "  #",
            "length_sort": false,
            "length_sort_sections": [],
            "add_imports": [],
            "remove_imports": [],
            "reverse_relative": false,
            "force_single_line": false,
            "single_line_exclusions": [],
            "default_section": "THIRDPARTY",
            "import_headings": {},
            "balanced_wrapping": false,
            "use_parentheses": false,
            "order_by_type": true,
            "atomic": false,
            "lines_after_imports": -1,
            "lines_between_sections": 1,
            "lines_between_types": 0,
            "combine_as_imports": false,
            "combine_star": false,
            "include_trailing_comma": false,
            "from_first": false,
            "verbose": false,
            "quiet": false,
            "force_adds": false,
            "force_alphabetical_sort_within_sections": false,
            "force_alphabetical_sort": false,
            "force_grid_wrap": 0,
            "force_sort_within_sections": false,
            "lexicographical": false,
            "ignore_whitespace": false,
            "no_lines_before": [],
            "no_inline_sort": false,
            "ignore_comments": false,
            "case_sensitive": false,
            "sources": [],
            "virtual_env": "",
            "conda_env": "",
            "ensure_newline_before_comments": false,
            "directory": "",
            "profile": "",
            "honor_noqa": false,
            "src_paths": [],
            "old_finders": false,
            "remove_redundant_aliases": false,
            "float_to_top": false,
            "source": "defaults"
        },
        {
            "multi_line_output": 3,
            "include_trailing_comma": true,
            "force_grid_wrap": 0,
            "use_parentheses": true,
            "ensure_newline_before_comments": true,
            "line_length": 88,
            "source": "black profile"
        },
        {
            "profile": "black",
            "skip": [
                "buck-out",
                ".tox",
                ".git",
                ".venv",
                ".eggs",
                ".mypy_cache",
                "_build",
                ".hg",
                "build",
                "dist",
                ".stubs/discord"
            ],
            "source": "C:\\Users\\Jakub\\OneDrive\\Dokumenty\\JackCogs\\pyproject.toml"
        }
    ],
    "virtual_env": "",
    "conda_env": "",
    "ensure_newline_before_comments": true,
    "directory": "C:\\Users\\Jakub\\OneDrive\\Dokumenty\\JackCogs",
    "profile": "black",
    "honor_noqa": false,
    "src_paths": [
        "C:\\Users\\Jakub\\OneDrive\\Dokumenty\\JackCogs",
        "C:\\Users\\Jakub\\OneDrive\\Dokumenty\\JackCogs\\src"
    ],
    "old_finders": false,
    "remove_redundant_aliases": false,
    "float_to_top": false
}

Ran from cmd (as regular user, without any additional flags)
the isort command that I used is in reproduction steps in the issue description

Let me know if you need anything else.

@timothycrosley timothycrosley added the bug Something isn't working label Jul 26, 2020
@timothycrosley
Copy link
Member

A fix for this issue was just deployed with version 5.2.0 of isort.

Thanks!

~Timothy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants