[libvirt] [PATCH] maint: Use pep8 to implement sc_prohibit_semicolon_at_eol_in_python

Shi Lei shi_lei at massclouds.com
Thu Sep 12 09:55:38 UTC 2019


Now sc_prohibit_semicolon_at_eol_in_python can't handle semicolon
within multiline strings(comments) properly.

I suggest that we could use pep8 to check python code style error, such
as 'statement ends with a semicolon'. In future, we could use '--select'
to introduce other rules.

Signed-off-by: Shi Lei <shi_lei at massclouds.com>
---
 cfg.mk       | 6 ++----
 configure.ac | 4 ++++
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index 42e1abf0..c8eaf74e 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -813,10 +813,8 @@ sc_require_enum_last_marker:
 
 # In Python files we don't want to end lines with a semicolon like in C
 sc_prohibit_semicolon_at_eol_in_python:
-	@prohibit='^[^#].*\;$$' \
-	in_vc_files='\.py$$' \
-	halt='python does not require to end lines with a semicolon' \
-	  $(_sc_search_regexp)
+	@$(VC_LIST_EXCEPT) | $(GREP) '\.py$$' | xargs $(PEP8) --select E703 \
+		| $(GREP) . && { exit 1; } || :
 
 # mymain() in test files should use return, not exit, for nicer output
 sc_prohibit_exit_in_tests:
diff --git a/configure.ac b/configure.ac
index bf9e7681..37fa9924 100644
--- a/configure.ac
+++ b/configure.ac
@@ -704,6 +704,10 @@ AC_PATH_PROGS([PYTHON], [python3 python2 python])
 if test -z "$PYTHON"; then
     AC_MSG_ERROR(['python3', 'python2' or 'python' binary is required to build libvirt])
 fi
+AC_PATH_PROG([PEP8], [pep8])
+if test -z "$PEP8"; then
+    AC_MSG_ERROR(['pep8' binary is required to check python code style])
+fi
 AC_PATH_PROG([PERL], [perl])
 if test -z "$PERL"; then
          AC_MSG_ERROR(['perl' binary is required to build libvirt])
-- 
2.17.1





More information about the libvir-list mailing list