Skip to content

Ensure viable PYTHONPATH when executing environmentally configured python. #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion envhelp/python2
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ if [ -z "${DOCKER_BIN}" ]; then
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/app/src'

# default any variables for local development
MIG_ENV=${MIG_ENV:-'local'}

Expand All @@ -40,4 +44,8 @@ echo

# execute python2 within the image passing the supplied arguments

${DOCKER_BIN} run -it --rm --mount type=bind,source=.,target=/usr/src/app --env "MIG_ENV=$MIG_ENV" "$IMAGEID" python2 "$@"
${DOCKER_BIN} run -it --rm \
--mount type=bind,source=.,target=/usr/src/app \
--env "PYTHONPATH=$PYTHON_PATH" \
--env "MIG_ENV=$MIG_ENV" \
"$IMAGEID" python2 "$@"
6 changes: 5 additions & 1 deletion envhelp/python3
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ set -e

SCRIPT_PATH=$(realpath "$0")
SCRIPT_BASE=$(dirname -- "$SCRIPT_PATH")
MIG_BASE=$(realpath "$SCRIPT_BASE/..")
PYTHON3_BIN="$SCRIPT_BASE/venv/bin/python3"

if [ ! -f "${PYTHON3_BIN}" ]; then
echo "No python3 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'}

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

MIG_ENV="$MIG_ENV" "$PYTHON3_BIN" "$@"
PYTHONPATH="$PYTHONPATH" MIG_ENV="$MIG_ENV" "$PYTHON3_BIN" "$@"
Empty file added tests/__init__.py
Empty file.