1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3""" 4 Checker for line endings 5 ~~~~~~~~~~~~~~~~~~~~~~~~ 6 7 Make sure Python (.py) and Bash completition (.bashcomp) files do not 8 contain CR/LF newlines. 9 10 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. 11 :license: BSD, see LICENSE for details. 12""" 13 14import sys 15import os 16 17if __name__ == '__main__': 18 for directory in sys.argv[1:]: 19 if not os.path.exists(directory): 20 continue 21 22 for root, dirs, files in os.walk(directory): 23 for filename in files: 24 if not filename.endswith('.py') and not filename.endswith('.bashcomp'): 25 continue 26 27 full_path = os.path.join(root, filename) 28 with open(full_path, 'rb') as f: 29 if b'\r\n' in f.read(): 30 print('CR/LF found in', full_path) 31 sys.exit(1) 32 33 sys.exit(0) 34