-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework python version handling associated testconfig path handling.
A previous revision fixed an immediate problem with test path handling but knowingly left some things on the table - in particular a split between container based handling of Python 2 and the local execution of Python 3 (meaning a potentially inconsistent version relative to what the project considers officially supported). Address this entirely: rework the default behaviour of `make test` to container based execution and use a consistent baseline Python 3. In order to continue to support rapid local iteration, provide a separate `make unittest` target which will execute the test suite locally and is also used as a mechanism to run other supporting tools. The clean use of containers necessitated various changes that make path arguments within the testconfig non-overlapping and better isolated. Adjust all paths generated within the test suite to be always from the base root instead of relative the output directory. Opt to patch the makeconfig generator rather than fiddle with generateconfs again. While here also add support for an environment variable overried that allows execution of the test suite against arbitrary python 3 versions.
- Loading branch information
Showing
18 changed files
with
352 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM python:3.9 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY requirements.txt local-requirements.txt ./ | ||
RUN pip install --no-cache-dir -r requirements.txt -r local-requirements.txt | ||
|
||
CMD [ "python", "--version" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ARG pyver | ||
FROM python:${pyver} | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY requirements.txt local-requirements.txt ./ | ||
RUN pip install --no-cache-dir -r requirements.txt -r local-requirements.txt | ||
|
||
CMD [ "python", "--version" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/bin/sh | ||
# | ||
# --- BEGIN_HEADER --- | ||
# | ||
# dpython - wrapper to invoke a containerised python | ||
# Copyright (C) 2003-2024 The MiG Project by the Science HPC Center at UCPH | ||
# | ||
# This file is part of MiG. | ||
# | ||
# MiG is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# MiG is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
# USA. | ||
# | ||
# --- END_HEADER --- | ||
# | ||
|
||
set -e | ||
|
||
SCRIPT_PATH=$(realpath "$0") | ||
SCRIPT_BASE=$(dirname -- "$SCRIPT_PATH") | ||
MIG_BASE=$(realpath "$SCRIPT_BASE/..") | ||
|
||
if [ -n "${PY}" ]; then | ||
PYVER="$PY" | ||
PYTHON_SUFFIX="py$PY" | ||
DOCKER_FILE_SUFFIX="$PYTHON_SUFFIX" | ||
elif [ -n "${PYVER}" ]; then | ||
PY=3 | ||
PYTHON_SUFFIX="pyver-$PYVER" | ||
DOCKER_FILE_SUFFIX="pyver" | ||
else | ||
echo "No python version specified - please supply a PY env var" | ||
exit 1 | ||
fi | ||
|
||
DOCKER_FILE="$SCRIPT_BASE/docker/Dockerfile.$DOCKER_FILE_SUFFIX" | ||
DOCKER_IMAGEID_FILE="$SCRIPT_BASE/$PYTHON_SUFFIX.imageid" | ||
|
||
# NOTE: portable dynamic lookup with docker as default and fallback to podman | ||
DOCKER_BIN=$(command -v docker || command -v podman || echo "") | ||
if [ -z "${DOCKER_BIN}" ]; then | ||
echo "No docker binary found - cannot use for python $PY tests" | ||
exit 1 | ||
fi | ||
|
||
# default PYTHONPATH such that directly executing files in the repo "just works" | ||
# NOTE: this is hard-coded to the mount point used within the container | ||
PYTHONPATH='/usr/src/app' | ||
|
||
# default any variables for container development | ||
MIG_ENV=${MIG_ENV:-'docker'} | ||
|
||
# determine if the image has changed | ||
echo -n "validating python $PY container.. " | ||
|
||
# load a previously written docker image id if present | ||
IMAGEID_STORED=$(cat "$DOCKER_IMAGEID_FILE" 2>/dev/null || echo "") | ||
|
||
IMAGEID=$(${DOCKER_BIN} build -f "$DOCKER_FILE" . -q --build-arg "pyver=$PYVER") | ||
if [ "$IMAGEID" != "$IMAGEID_STORED" ]; then | ||
echo "rebuilt for changes" | ||
|
||
# reset the image id so the next call finds no changes | ||
echo "$IMAGEID" > "$DOCKER_IMAGEID_FILE" | ||
else | ||
echo "no changes needed" | ||
fi | ||
|
||
echo "using image id $IMAGEID" | ||
|
||
# execute python2 within the image passing the supplied arguments | ||
|
||
${DOCKER_BIN} run -it --rm \ | ||
--mount "type=bind,source=$MIG_BASE,target=/usr/src/app" \ | ||
--env "PYTHONPATH=$PYTHONPATH" \ | ||
--env "MIG_ENV=$MIG_ENV" \ | ||
"$IMAGEID" python$PY $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/sh | ||
# | ||
# --- BEGIN_HEADER --- | ||
# | ||
# python3 - wrapper to invoke a local python3 virtual environment | ||
# Copyright (C) 2003-2024 The MiG Project by the Science HPC Center at UCPH | ||
# | ||
# This file is part of MiG. | ||
# | ||
# MiG is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# MiG is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
# USA. | ||
# | ||
# --- END_HEADER --- | ||
# | ||
|
||
set -e | ||
|
||
SCRIPT_PATH=$(realpath "$0") | ||
SCRIPT_BASE=$(dirname -- "$SCRIPT_PATH") | ||
MIG_BASE=$(realpath "$SCRIPT_BASE/..") | ||
|
||
PYTHON_BIN=${PYTHON_BIN:-"$SCRIPT_BASE/venv/bin/python3"} | ||
if [ ! -f "${PYTHON_BIN}" ]; then | ||
echo "No python binary found - perhaps the virtual env was not created" | ||
exit 1 | ||
fi | ||
|
||
# default PYTHONPATH such that directly executing files in the repo "just works" | ||
PYTHONPATH=${PYTHONPATH:-"$MIG_BASE"} | ||
|
||
# default any variables for local development | ||
MIG_ENV=${MIG_ENV:-'local'} | ||
|
||
PYTHONPATH="$PYTHONPATH" MIG_ENV="$MIG_ENV" "$PYTHON_BIN" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.