line-ending detection doesn't work on Windows and --help explain how to use --line-ending
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7k
- Forks
- 687
- Avg merge
- 4h 56m
- Merged PRs (30d)
- 2
Description
When passing a file with Unix-style LF line endings to isort, it always converts it to CRLF on Windows.
C:\> isort --version
_ _
(_) ___ ___ _ __| |_
| |/ _/ / _ \/ '__ _/
| |\__ \/\_\/| | | |_
|_|\___/\___/\_/ \_/
isort your imports, so you don't have to.
VERSION 7.0.0
C:\> cat C:\scratch\aletest.py | file -
/dev/stdin: Python script, ASCII text executable, with very long lines (965)
C:\> isort - < C:\scratch\aletest.py | file -
/dev/stdin: Python script, ASCII text executable, with CRLF line terminators
C:\> file --version
file-5.45
magic file from /usr/share/misc/magic
Same results with a minimal file created from scratch:
C:\> echo import re > testfile.py
C:\> echo import os >> testfile.py
C:\> dos2unix testfile.py
C:\> file testfile.py
testfile.py: ASCII text
C:\> isort - < C:\scratch\testfile.py | file -
/dev/stdin: ASCII text, with CRLF line terminators
On Linux (WSL Ubuntu using bash) it works:
$ isort - < /mnt/c/scratch/aletest.py | file -
/dev/stdin: Python script, ASCII text executable
$ isort --version | grep VERSION
VERSION 5.13.2
(I originally encountered the issue on v5 under Windows.)
So auto line ending detection is not working. So I tried to force it to use \n line endings. The docs say:
Line Ending
Forces line endings to the specified value. If not set, values will be guessed per-file.
Type: String
Default:
Config default:
Python & Config File Name: line_ending
CLI Flags:--le --line-ending
However, what values are valid? CRLF, \n, unix? There are many ways line endings are described, so it's not entirely clear which ones isort expects.
I think the correct value is the literal character at the end of the line: \n. But how do you specify that? I tried what seemed obvious but it didn't work and always uses CRLF:
C:\> isort --line-ending \n - < C:\scratch\testfile.py
import os\nimport re\n
C:\> isort --line-ending \\n - < C:\scratch\testfile.py
import os\\nimport re\\n
C:\> isort --line-ending "\n" - < C:\scratch\testfile.py
import os\nimport re\n
C:\> isort --line-ending "\\n" - < C:\scratch\testfile.py
import os\\nimport re\\n
So all of those options seem wrong.
On Win11 in cmd.exe. I'm using file from my git install (via scoop). I got isort via pip on Python 3.11.3.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Windows cmd.exe commands and trace the CLI handling for --line-ending and automatic line-ending detection. Check the option documentation for the accepted values. Done means LF input remains LF on Windows and the valid --line-ending syntax is clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100