Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
albu-diku committed Oct 29, 2024
1 parent f531944 commit ee22031
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ ifndef PY
endif

LOCAL_PYTHON_BIN = './envhelp/lpython'
LOCAL_DEPENDS = './envhelp/local.depends'

ifdef PYTHON_BIN
LOCAL_PYTHON_BIN = $(PYTHON_BIN)
Expand Down Expand Up @@ -43,7 +42,7 @@ endif
clean:
@rm -f ./envhelp/py2.imageid
@rm -f ./envhelp/py3.imageid
@rm -f $(LOCAL_DEPENDS)
@rm -f ./envhelp/local.depends

.PHONY: distclean
distclean: clean
Expand Down Expand Up @@ -86,11 +85,11 @@ ifeq ($(MIG_ENV),'local')
@echo "installing development dependencies"
@$(LOCAL_PYTHON_BIN) -m pip install -r local-requirements.txt
endif
@touch $(LOCAL_DEPENDS)
@touch ./envhelp/local.depends

./envhelp/venv/pyvenv.cfg:
@echo "provisioning environment"
@/usr/bin/env python3 -m venv ./envhelp/venv
@rm -f $(LOCAL_DEPENDS)
@rm -f ./envhelp/local.depends
@echo "upgrading venv pip as required for some dependencies"
@./envhelp/venv/bin/pip3 install --upgrade pip
10 changes: 4 additions & 6 deletions envhelp/dpython
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ if [ -z "${PY}" ]; then
fi

PYTHON_SUFFIX="py$PY"
DOCKER_FILE="$SCRIPT_BASE/docker/Dockerfile.$PYTHON_SUFFIX"
DOCKER_IMAGEID_FILE="$SCRIPT_BASE/$PYTHON_SUFFIX.imageid"
DOCKER_PYTHON_BIN="python$PY"

# NOTE: portable dynamic lookup with docker as default and fallback to podman
DOCKER_BIN=$(command -v docker || command -v podman || echo "")
DOCKER_BASE="$SCRIPT_BASE/docker"
DOCKER_FILE="$DOCKER_BASE/Dockerfile.$PYTHON_SUFFIX"
if [ -z "${DOCKER_BIN}" ]; then
echo "No docker binary found - cannot use for python $PY tests"
exit 1
Expand All @@ -57,7 +56,7 @@ PYTHONPATH='/usr/src/app'
MIG_ENV=${MIG_ENV:-'docker'}

# determine if the image has changed
echo -n "validating container.. "
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 "")
Expand All @@ -72,13 +71,12 @@ else
echo "no changes needed"
fi

echo "running with MIG_ENV='$MIG_ENV' under python $PY"
echo
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" $DOCKER_PYTHON_BIN $@
"$IMAGEID" python$PY $@
3 changes: 0 additions & 3 deletions envhelp/lpython
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,4 @@ PYTHONPATH=${PYTHONPATH:-"$MIG_BASE"}
# default any variables for local development
MIG_ENV=${MIG_ENV:-'local'}

echo "running with MIG_ENV='$MIG_ENV' under local python 3"
echo

PYTHONPATH="$PYTHONPATH" MIG_ENV="$MIG_ENV" "$PYTHON_BIN" "$@"
10 changes: 10 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def _print_identity():
import os
import sys
python_version_string = sys.version.split(' ')[0]
mig_env = os.environ['MIG_ENV']
print("running with MIG_ENV='%s' under Python %s" %
(mig_env, python_version_string))
print("")

_print_identity()

0 comments on commit ee22031

Please sign in to comment.