From 2f767d8966cf1159600fd3be72718e734f909413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Mon, 13 Feb 2023 20:46:01 +0100 Subject: [PATCH 1/4] Test installation and import also on local system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- Containerfile.tests | 9 ++++++--- entrypoint.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100755 entrypoint.sh diff --git a/Containerfile.tests b/Containerfile.tests index bf51aeb..a8104a6 100644 --- a/Containerfile.tests +++ b/Containerfile.tests @@ -1,12 +1,15 @@ ARG BASE_IMAGE FROM ${BASE_IMAGE} -WORKDIR /workdir +COPY entrypoint.sh /entrypoint.sh + +WORKDIR /rpm-shim COPY . . ARG INSTALL_DEPS_CMD RUN sh -c "${INSTALL_DEPS_CMD}" -RUN python3 -m pip install tox +RUN python3 -m pip install tox build -CMD ["tox", "--workdir", "/workdir"] +WORKDIR / +ENTRYPOINT ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..6672974 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# fail early +set -e + + +### test import in virtualenvs + +pushd /rpm-shim +tox +popd + + +### test import on local system + +PYTHON=python3 +PLATFORM_PYTHON=/usr/libexec/platform-python +if [ ! -x "${PYTHON}" -a -x "${PLATFORM_PYTHON}" ]; then + # fallback to platform-python + PYTHON="${PLATFORM_PYTHON}" +fi + +${PYTHON} -m build --wheel /rpm-shim +# failure to install is most likely caused by existing RPM bindings, consider it a success +${PYTHON} -m pip install /rpm-shim/dist/*.whl || exit 0 +${PYTHON} -c "import rpm" +${PYTHON} -m pip check From 9bb3282f8f4fe46b49d38178ecd7387ea8316846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Mon, 13 Feb 2023 20:46:39 +0100 Subject: [PATCH 2/4] Enable debug logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- entrypoint.sh | 2 +- tox.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 6672974..97ebd20 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -23,5 +23,5 @@ fi ${PYTHON} -m build --wheel /rpm-shim # failure to install is most likely caused by existing RPM bindings, consider it a success ${PYTHON} -m pip install /rpm-shim/dist/*.whl || exit 0 -${PYTHON} -c "import rpm" +${PYTHON} -c "import logging; logging.basicConfig(level=logging.DEBUG); import rpm" ${PYTHON} -m pip check diff --git a/tox.ini b/tox.ini index e7ec710..cde9f55 100644 --- a/tox.ini +++ b/tox.ini @@ -12,5 +12,5 @@ sitepackages = false deps = pip >= 19 setenv = PYTHONDONTWRITEBYTECODE=1 commands = - python -c "import rpm" + python -c "import logging; logging.basicConfig(level=logging.DEBUG); import rpm" python -m pip check From 993f989f4b13c5e631a8e3579825b23ac16b441d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Tue, 14 Feb 2023 18:17:33 +0100 Subject: [PATCH 3/4] Move test files to a subdirectory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- Makefile | 2 +- Containerfile.tests => tests/Containerfile | 2 +- entrypoint.sh => tests/entrypoint.sh | 4 ++-- tests/import.py | 18 ++++++++++++++++++ tox.ini | 2 +- 5 files changed, 23 insertions(+), 5 deletions(-) rename Containerfile.tests => tests/Containerfile (83%) rename entrypoint.sh => tests/entrypoint.sh (76%) create mode 100644 tests/import.py diff --git a/Makefile b/Makefile index 1f38712..0317183 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ CONTAINER_ENGINE ?= $(shell command -v podman 2> /dev/null || echo docker) test-image: $(CONTAINER_ENGINE) build --rm \ --tag $(TEST_IMAGE) \ - -f Containerfile.tests \ + -f tests/Containerfile \ --build-arg BASE_IMAGE=$(BASE_IMAGE) \ --build-arg INSTALL_DEPS_CMD="$(INSTALL_DEPS_CMD)" \ . diff --git a/Containerfile.tests b/tests/Containerfile similarity index 83% rename from Containerfile.tests rename to tests/Containerfile index a8104a6..ec9f496 100644 --- a/Containerfile.tests +++ b/tests/Containerfile @@ -1,7 +1,7 @@ ARG BASE_IMAGE FROM ${BASE_IMAGE} -COPY entrypoint.sh /entrypoint.sh +COPY tests/entrypoint.sh /entrypoint.sh WORKDIR /rpm-shim COPY . . diff --git a/entrypoint.sh b/tests/entrypoint.sh similarity index 76% rename from entrypoint.sh rename to tests/entrypoint.sh index 97ebd20..7187682 100755 --- a/entrypoint.sh +++ b/tests/entrypoint.sh @@ -22,6 +22,6 @@ fi ${PYTHON} -m build --wheel /rpm-shim # failure to install is most likely caused by existing RPM bindings, consider it a success -${PYTHON} -m pip install /rpm-shim/dist/*.whl || exit 0 -${PYTHON} -c "import logging; logging.basicConfig(level=logging.DEBUG); import rpm" +${PYTHON} -m pip install /rpm-shim/dist/*.whl || true +${PYTHON} /rpm-shim/tests/import.py ${PYTHON} -m pip check diff --git a/tests/import.py b/tests/import.py new file mode 100644 index 0000000..006c5d8 --- /dev/null +++ b/tests/import.py @@ -0,0 +1,18 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + +import logging + +# enable debug logging +logging.basicConfig(level=logging.DEBUG) + + +def test(): + import rpm + + # sanity check + print("RPM conf dir:", rpm.expandMacro("%getconfdir")) + + +if __name__ == "__main__": + test() diff --git a/tox.ini b/tox.ini index cde9f55..ee21c52 100644 --- a/tox.ini +++ b/tox.ini @@ -12,5 +12,5 @@ sitepackages = false deps = pip >= 19 setenv = PYTHONDONTWRITEBYTECODE=1 commands = - python -c "import logging; logging.basicConfig(level=logging.DEBUG); import rpm" + python tests/import.py python -m pip check From 940a5f211b7e2ec8297f575f8e4a9f76ee5705c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Tue, 14 Feb 2023 20:34:57 +0100 Subject: [PATCH 4/4] Fix tox configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit skipsdist prevents installing the shim in tox >= 4, and usedevelop is unnecessary and tox >= 4 emits warnings when it is enabled. Signed-off-by: Nikola Forró --- tox.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/tox.ini b/tox.ini index ee21c52..bc936b6 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,10 @@ [tox] envlist = py{36,37,38,39,310,311} skip_missing_interpreters = true -skipsdist = true isolated_build = true [testenv] recreate = true -usedevelop = true sitepackages = false # pip < 19 requires setup.py deps = pip >= 19