summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMatthäus G. Chajdas <Anteru@users.noreply.github.com>2020-09-20 10:24:09 +0200
committerGitHub <noreply@github.com>2020-09-20 10:24:09 +0200
commit8aa2bc3d6c1bc65fbc6da9af8a588fcea3552e98 (patch)
tree7e51ff18fe940afc914aaa4326f4a9bb8fbdf5e6 /scripts
parent45b3dc6891c6ece14e0ea5e017624fef36c6beea (diff)
downloadpygments-git-8aa2bc3d6c1bc65fbc6da9af8a588fcea3552e98.tar.gz
Add a check for CR/LF in files. (#1547)
* Add a check for CR/LF in files. This can occur when checking out things on Windows, and it breaks the tarball. This adds a script to check for the presence of CR/LF which exits early if anything gets found. * Improve error checking. * Include the external folder and check that. * Include .bashcomp files. * Use the correct CR/LF on the checker itself. * Address review feedback. * Remove || true * Fix docs * Print the first offending file name
Diffstat (limited to 'scripts')
-rw-r--r--scripts/check_crlf.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/check_crlf.py b/scripts/check_crlf.py
new file mode 100644
index 00000000..14442d0e
--- /dev/null
+++ b/scripts/check_crlf.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+ Checker for line endings
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Make sure Python (.py) and Bash completition (.bashcomp) files do not
+ contain CR/LF newlines.
+
+ :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import sys
+import os
+
+if __name__ == '__main__':
+ for directory in sys.argv[1:]:
+ if not os.path.exists(directory):
+ continue
+
+ for root, dirs, files in os.walk(directory):
+ for filename in files:
+ if not filename.endswith('.py') and not filename.endswith('.bashcomp'):
+ continue
+
+ full_path = os.path.join(root, filename)
+ with open(full_path, 'rb') as f:
+ if b'\r\n' in f.read():
+ print('CR/LF found in', full_path)
+ sys.exit(1)
+
+ sys.exit(0)