diff mbox series

[1/1] python: add check-python target

Message ID 20200714013026.9019-2-jsnow@redhat.com
State New
Headers show
Series [1/1] python: add check-python target | expand

Commit Message

John Snow July 14, 2020, 1:30 a.m. UTC
Move pylintrc and flake8 up to the root of the python folder where
they're the most useful. Add a requirements.cqa.txt file to house
the requirements necessary to build a venv sufficient for running
code quality analysis on the python folder. Add a makefile that
will build the venv and run the tests.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 Makefile                    |  1 +
 python/{qemu => }/.flake8   |  0
 python/Makefile.include     | 33 +++++++++++++++++++++++++++++++++
 python/{qemu => }/pylintrc  |  1 +
 python/requirements.cqa.txt |  3 +++
 5 files changed, 38 insertions(+)
 rename python/{qemu => }/.flake8 (100%)
 create mode 100644 python/Makefile.include
 rename python/{qemu => }/pylintrc (99%)
 create mode 100644 python/requirements.cqa.txt
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index b1b8a5a6d0..41808be392 100644
--- a/Makefile
+++ b/Makefile
@@ -478,6 +478,7 @@  dummy := $(call unnest-vars,, \
                 trace-obj-y)
 
 include $(SRC_PATH)/tests/Makefile.include
+include $(SRC_PATH)/python/Makefile.include
 
 all: $(DOCS) $(if $(BUILD_DOCS),sphinxdocs) $(TOOLS) $(HELPERS-y) recurse-all modules $(vhost-user-json-y)
 
diff --git a/python/qemu/.flake8 b/python/.flake8
similarity index 100%
rename from python/qemu/.flake8
rename to python/.flake8
diff --git a/python/Makefile.include b/python/Makefile.include
new file mode 100644
index 0000000000..917808e2f1
--- /dev/null
+++ b/python/Makefile.include
@@ -0,0 +1,33 @@ 
+# -*- Mode: makefile -*-
+
+PYLIB_VENV_DIR=$(BUILD_DIR)/venv/cqa
+PYLIB_VENV_REQ=$(SRC_PATH)/python/requirements.cqa.txt
+
+$(PYLIB_VENV_DIR): $(PYLIB_VENV_REQ)
+	$(call quiet-command, \
+	    $(PYTHON) -m venv $@, \
+	    VENV, $@)
+	$(call quiet-command, \
+	    $(PYLIB_VENV_DIR)/bin/python3 -m pip -q install -r $(PYLIB_VENV_REQ), \
+	    PIP, $(PYLIB_VENV_REQ))
+	$(call quiet-command, touch $@)
+
+pylib-venv: $(PYLIB_VENV_DIR)
+
+check-python: pylib-venv
+	$(call quiet-command, cd $(SRC_PATH)/python && \
+	    $(PYLIB_VENV_DIR)/bin/python3 -m flake8 qemu, \
+	    FLAKE8, \
+	    $(SRC_PATH)/python/qemu \
+	)
+	$(call quiet-command, cd $(SRC_PATH)/python && \
+	    $(PYLIB_VENV_DIR)/bin/python3 -m pylint qemu, \
+	    PYLINT, \
+	    $(SRC_PATH)/python/qemu \
+	)
+	$(call quiet-command, cd $(SRC_PATH)/python && \
+	    $(PYLIB_VENV_DIR)/bin/python3 -m mypy \
+	        --strict --no-error-summary qemu, \
+	    MYPY, \
+	    "--strict $(SRC_PATH)/python/qemu" \
+	)
diff --git a/python/qemu/pylintrc b/python/pylintrc
similarity index 99%
rename from python/qemu/pylintrc
rename to python/pylintrc
index 5d6ae7367d..65b4545a6b 100644
--- a/python/qemu/pylintrc
+++ b/python/pylintrc
@@ -16,6 +16,7 @@  disable=too-many-arguments,
         too-many-public-methods,
 
 [REPORTS]
+score=no
 
 [REFACTORING]
 
diff --git a/python/requirements.cqa.txt b/python/requirements.cqa.txt
new file mode 100644
index 0000000000..dbf45984bc
--- /dev/null
+++ b/python/requirements.cqa.txt
@@ -0,0 +1,3 @@ 
+pylint==2.5.3
+mypy==0.782
+flake8==3.8.3