Special case dib-python in dib-lint

It seems that on Xenial, it does not take much to confuse "file" and
it's mime guessing such that it thinks some files are not python.

"package-installs-v2" is a good example, since it has an interpreter
"dib-python" that "file" doesn't know about, and no extension.  While
looking at this, I've added emacs vars here so it opens in python
mode.

Change-Id: I01994b08c5ad8987925f1eec4062f5b6ee72eb8f
This commit is contained in:
Ian Wienand 2016-11-23 19:44:50 +11:00
parent 09cab0fa65
commit f15550f9fe
2 changed files with 12 additions and 2 deletions

View File

@ -83,10 +83,15 @@ for i in $(find elements -type f \
error "$i is not executable" error "$i is not executable"
fi fi
# Ensure 4 spaces indent are used # run flake8 over python files. note our "dib-python"
if [[ "$(file -b -k --mime-type $i)" =~ "text/x-python" ]]; then # interpreter can confuse the magic matching being done in
# "file" and make it think the file is not python;
# special-case it.
if [[ "$(file -b -k --mime-type $i)" =~ "text/x-python" ]] || \
[[ $firstline =~ "dib-python" ]]; then
flake8 $i || error "$i failed flake8" flake8 $i || error "$i failed flake8"
else else
# Ensure 4 spaces indent are used
if ! excluded indent ; then if ! excluded indent ; then
indent_regex='^\( \{4\}\)* \{1,3\}[^ ]' indent_regex='^\( \{4\}\)* \{1,3\}[^ ]'
if grep -q "$indent_regex" ${i}; then if grep -q "$indent_regex" ${i}; then

View File

@ -101,3 +101,8 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()
# Tell emacs to use python-mode
# Local variables:
# mode: python
# End: