File size: 656 Bytes
9f0dcde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pathlib


HERE = pathlib.Path(__file__).parent.absolute()


def convert_lf():  # pragma: no cover
    """Convert line endings to LF"""
    crlf = b"\r\n"
    lf = b"\n"
    extensions = {".py", ".toml", ".lock", ".txt", ".yml", ".sh", ".md"}
    n = 0
    for fp in HERE.parent.glob("**/*"):
        if fp.suffix in extensions:
            with open(fp, "rb") as infile:
                content = infile.read()
            if crlf in content:
                content = content.replace(crlf, lf)
                with open(fp, "wb") as outfile:
                    outfile.write(content)
                n += 1
    print(f"{n} files converted to LF")