Skip to content

Commit 41c43d4

Browse files
JasperB-TeamBluedupondje
authored andcommitted
ci: run python check after build
After the build is completed and all python files are generated, run python check. Python check runs pylint, pyflakes, isort and pycodestyle. This ensures a proper and uniform layout of python files. Signed-off-by: Jasper Berton <[email protected]>
1 parent 1dd6623 commit 41c43d4

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ jobs:
3030

3131
steps:
3232
- name: Install required PyPI packages
33-
run: ${{ matrix.pip-command }} install "ansible-lint>=6.0.0,<7.0.0"
33+
run: ${{ matrix.pip-command }} install ansible-lint pylint mock paramiko psycopg2-binary websockify websocket-client looseversion isort pycodestyle pyflakes
34+
35+
- name: Ensure required packages are available for linting
36+
run: dnf -y install otopi python3-ovirt-setup-lib python3-daemon
3437

3538
- name: Checkout sources
3639
uses: ovirt/checkout-action@main
@@ -39,6 +42,9 @@ jobs:
3942
run: |
4043
.automation/build-rpm.sh $ARTIFACTS_DIR
4144
45+
- name: Run python check
46+
run: build/python-check.sh
47+
4248
- name: Create DNF repository
4349
run: |
4450
createrepo_c $ARTIFACTS_DIR

.pylintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[MASTER]
2+
init-hook=
3+
import sys, pathlib;
4+
root = pathlib.Path().resolve();
5+
paths = [
6+
root / "packaging" / "pythonlib",
7+
root / "packaging" / "services" / "ovirt-engine",
8+
root / "packaging" / "services" / "ovirt-fence-kdump-listener",
9+
root / "packaging" / "services" / "ovirt-websocket-proxy",
10+
root / "packaging" / "services" / "ovirt-engine-notifier",
11+
root / "packaging" / "libexec" / "ovirt-vmconsole-proxy-helper"
12+
];
13+
[sys.path.insert(0, str(p)) for p in paths if str(p) not in sys.path]

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ RUN make ovirt-engine.spec
2323
RUN dnf -y builddep ovirt-engine.spec
2424

2525
# Install run deps
26-
RUN dnf -y install python3-daemon python3-otopi python3-psycopg2 python3-ovirt-setup-lib otopi-common initscripts-service bind-utils postgresql ovirt-engine-wildfly-overlay mailcap ansible-runner ansible-collection-ansible-posix ovirt-imageio-daemon novnc ovirt-engine-websocket-proxy
26+
RUN dnf -y install python3-daemon python3-otopi python3-psycopg2 python3-ovirt-setup-lib otopi-common initscripts-service bind-utils postgresql ovirt-engine-wildfly-overlay mailcap ansible-runner ansible-collection-ansible-posix ovirt-imageio-daemon novnc ovirt-engine-websocket-proxy python3-pip
27+
28+
# Install linting tools
29+
RUN pip install pylint pyflakes isort pycodestyle mock
2730

2831
# engine-setup needs the link to initctl
2932
RUN ln -s /usr/sbin/service /usr/bin/initctl

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ PACKAGE_NAME=ovirt-engine
3030
ENGINE_NAME=$(PACKAGE_NAME)
3131
MVN=mvn
3232
PYTHON=$(shell which python3 2> /dev/null)
33-
PYFLAKES=$(shell which pyflakes 2> /dev/null)
33+
PYFLAKES=pyflakes
3434
PY_VERSION=3
35-
PEP8=$(shell which pycodestyle-3 2> /dev/null)
35+
PEP8=pycodestyle
3636
ISORT=isort
37+
PYLINT=pylint
3738
PREFIX?=/usr/local
3839
LOCALSTATE_DIR=$(PREFIX)/var
3940
BIN_DIR=$(PREFIX)/bin
@@ -184,6 +185,7 @@ BUILD_TARGET=install
184185
-e "s|@PEP8@|$(PEP8)|g" \
185186
-e "s|@PYFLAKES@|$(PYFLAKES)|g" \
186187
-e "s|@ISORT@|$(ISORT)|g" \
188+
-e "s|@PYLINT@|$(PYLINT)|g" \
187189
-e "s|@DEVMODE@|$(BUILD_DEV)|g" \
188190
-e "s|@VMCONSOLE_SYSCONF_DIR@|$(VMCONSOLE_SYSCONF_DIR)|g" \
189191
-e "s|@VMCONSOLE_PKI_DIR@|$(VMCONSOLE_PKI_DIR)|g" \

build/python-check.sh.in

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#!/bin/sh -x
1+
#!/bin/sh
22

33
PEP8="@PEP8@"
44
PYFLAKES="@PYFLAKES@"
55
ISORT="@ISORT@"
6+
PYLINT="@PYLINT@"
67
SRCDIR="$(dirname "$0")/.."
78

89
cd "${SRCDIR}"
@@ -19,7 +20,7 @@ for exe in "${PYFLAKES}" "${PEP8}"; do
1920
echo "WARNING: tool '${exe}' is missing" >&2
2021
else
2122
if "${exe}" ${FILES}; then
22-
echo Passed check: "${exe}" ${FILES}
23+
echo Passed check: "${exe}"
2324
else
2425
echo ERROR: The following check failed:
2526
echo "${exe}" ${FILES}
@@ -28,11 +29,23 @@ for exe in "${PYFLAKES}" "${PEP8}"; do
2829
fi
2930
done
3031

32+
if ! which "${PYLINT}" > /dev/null 2>&1; then
33+
echo "WARNING: Pylint is missing" >&2
34+
else
35+
if "${PYLINT}" --errors-only ${FILES}; then
36+
echo Passed check: "${PYLINT}" --errors-only
37+
else
38+
echo ERROR: The following check failed:
39+
echo python3 -m "${PYLINT}" --errors-only ${FILES}
40+
ret=1
41+
fi
42+
fi
43+
3144
if ! which "${ISORT}" > /dev/null 2>&1; then
3245
echo "WARNING: tool '${ISORT}' is missing" >&2
3346
else
3447
if "${ISORT}" --check ${FILES}; then
35-
echo Passed check: "${ISORT}" --check ${FILES}
48+
echo Passed check: "${ISORT}" --check
3649
else
3750
echo ERROR: The following check failed:
3851
echo "${ISORT}" --check ${FILES}

0 commit comments

Comments
 (0)