Skip to contentSkip to conversation

scripts/run-flake8: run on Python scripts not ending with .py

PATCH In review Nicolas Iooss 2 participants 3 messages Jan 5, 2019 – Jan 9, 2019 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/run-flake8: run on Python scripts not ending with .py

When running flake8 on a directory, it does not analyze files without an extension, like semanage_migrate_store, mlscolor-test, etc. Use grep to find files with a Python shebang and build a list which is then given to flake8.

This commit is possible now that some clean-up patches have been applied, such as commit 69c56bd2f6e9 ("python/chcat: improve the code readability") and b7227aaec1da ("mcstrans: fix Python linter warnings on test scripts") and 3cb974d2d2a7 ("semanage_migrate_store: fix many Python linter warnings").

---
 scripts/run-flake8 | 5 +++++
 1 file changed, 5 insertions(+)
scripts/run-flake8 +5 -0
index 6ad029fa6852..24b1202fde99 100755
@@ -4,6 +4,11 @@
 # Run on the base directory if no argument has been given
 if [ $# -eq 0 ] ; then
     cd "$(dirname -- "$0")/.." || exit $?
+
+    # Run on both files ending with .py and Python files without extension
+    # shellcheck disable=SC2046
+    set -- $( (find . -name '*.py' ; grep --exclude-dir=.git -l -e '^#!\s*/usr/bin/python' -e '^#!/usr/bin/env python' -r .) | sort -u )
+    echo "Analyzing $# Python scripts"
 fi
 
 # Assign each ignore warning on a line, in order to ease testing enabling the warning again
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Nicolas Iooss

When running flake8 on a directory, it does not analyze files without an extension, like semanage_migrate_store, mlscolor-test, etc. Use grep to find files with a Python shebang and build a list which is then given to flake8.

Quoted 7 lines

This commit is possible now that some clean-up patches have been applied, such as commit 69c56bd2f6e9 ("python/chcat: improve the code readability") and b7227aaec1da ("mcstrans: fix Python linter warnings on test scripts") and 3cb974d2d2a7 ("semanage_migrate_store: fix many Python linter warnings").

https://github.com/SELinuxProject/selinux/pull/128

Quoted 20 lines
---
 scripts/run-flake8 | 5 +++++
 1 file changed, 5 insertions(+)
scripts/run-flake8 +5 -0
index 6ad029fa6852..24b1202fde99 100755
@@ -4,6 +4,11 @@
 # Run on the base directory if no argument has been given
 if [ $# -eq 0 ] ; then
     cd "$(dirname -- "$0")/.." || exit $?
+
+    # Run on both files ending with .py and Python files without extension
+    # shellcheck disable=SC2046
+    set -- $( (find . -name '*.py' ; grep --exclude-dir=.git -l -e '^#!\s*/usr/bin/python' -e '^#!/usr/bin/env python' -r .) | sort -u )
+    echo "Analyzing $# Python scripts"
 fi
 
 # Assign each ignore warning on a line, in order to ease testing enabling the warning again
#2 lore raw
Quoted 13 lines · Petr Lautrbach
Quoted 11 lines · Nicolas Iooss

When running flake8 on a directory, it does not analyze files without an extension, like semanage_migrate_store, mlscolor-test, etc. Use grep to find files with a Python shebang and build a list which is then given to flake8.

This commit is possible now that some clean-up patches have been applied, such as commit 69c56bd2f6e9 ("python/chcat: improve the code readability") and b7227aaec1da ("mcstrans: fix Python linter warnings on test scripts") and 3cb974d2d2a7 ("semanage_migrate_store: fix many Python linter warnings").

Quoted 5 lines
Quoted 1 line

https://github.com/SELinuxProject/selinux/pull/128

And it's merged now.

Quoted 21 lines
Quoted 21 lines
---
 scripts/run-flake8 | 5 +++++
 1 file changed, 5 insertions(+)
scripts/run-flake8 +5 -0
index 6ad029fa6852..24b1202fde99 100755
@@ -4,6 +4,11 @@
 # Run on the base directory if no argument has been given
 if [ $# -eq 0 ] ; then
     cd "$(dirname -- "$0")/.." || exit $?
+
+    # Run on both files ending with .py and Python files without extension
+    # shellcheck disable=SC2046
+    set -- $( (find . -name '*.py' ; grep --exclude-dir=.git -l -e '^#!\s*/usr/bin/python' -e '^#!/usr/bin/env python' -r .) | sort -u )
+    echo "Analyzing $# Python scripts"
 fi
 
 # Assign each ignore warning on a line, in order to ease testing enabling the warning again