Skip to content

Commit

Permalink
Check if python starts python3 (#6239)
Browse files Browse the repository at this point in the history
Problem: dev_tools/pypath does not work when python command does
not exist causing a failure in check/pytest (PYTHONPATH not set).

Solution: Require that python starts Python 3.
Bail out from the check scripts otherwise.
  • Loading branch information
pavoljuhas committed Aug 18, 2023
1 parent 95cb43f commit 6b44704
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion check/doctest
Expand Up @@ -18,6 +18,6 @@ thisdir="$(dirname "${BASH_SOURCE[0]}")" || exit $?
topdir="$(git -C "${thisdir}" rev-parse --show-toplevel)" || exit $?
cd "${topdir}" || exit $?

source dev_tools/pypath
source dev_tools/pypath || exit $?

python dev_tools/docs/run_doctest.py "$@"
2 changes: 1 addition & 1 deletion check/pytest
Expand Up @@ -20,7 +20,7 @@ cd "${topdir}" || exit $?
# (the last `-n` option wins)
PYTEST_ARGS=( "-n=auto" "$@" )

source dev_tools/pypath
source dev_tools/pypath || exit $?

pytest "${PYTEST_ARGS[@]}"
RESULT=$?
Expand Down
2 changes: 1 addition & 1 deletion check/pytest-and-incremental-coverage
Expand Up @@ -68,7 +68,7 @@ else
rev="${base}"
fi

source dev_tools/pypath
source dev_tools/pypath || exit $?

# Run tests while producing coverage files.
check/pytest --cov \
Expand Down
2 changes: 1 addition & 1 deletion check/pytest-changed-files
Expand Up @@ -76,6 +76,6 @@ if [ "${num_changed}" -eq 0 ]; then
exit 0
fi

source dev_tools/pypath
source dev_tools/pypath || exit $?

pytest "${rest[@]}" "${changed[@]}"
2 changes: 1 addition & 1 deletion check/pytest-changed-files-and-incremental-coverage
Expand Up @@ -87,7 +87,7 @@ if [ "${#changed_python_tests[@]}" -eq 0 ]; then
exit 0
fi

source dev_tools/pypath
source dev_tools/pypath || exit $?

# Run tests while producing coverage files.
check/pytest "${changed_python_tests[@]}" \
Expand Down
6 changes: 6 additions & 0 deletions dev_tools/pypath
Expand Up @@ -29,6 +29,12 @@ else
_PYPATH_BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
fi

if ! python --version | grep -q -F "Python 3."; then
echo "python command does not start Python 3" >&2
echo "Please use a virtual environment created for Python 3." >&2
return 2
fi

_PYPATH_PREFIX="${_PYPATH_BASE_DIR}$(
cd "${_PYPATH_BASE_DIR}" &&
env PYTHONPATH=. python dev_tools/modules.py list --mode folder |
Expand Down

0 comments on commit 6b44704

Please sign in to comment.