Skip to content

Commit

Permalink
use python instead of envpython
Browse files Browse the repository at this point in the history
also enable travis 3.8-dev testing
  • Loading branch information
richm committed Apr 1, 2020
1 parent b5ae538 commit 56d0d76
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 67 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ matrix:
- python: 3.6
- python: 3.7
- python: 3.8
- python: 3.8-dev

services:
- docker
Expand Down
7 changes: 1 addition & 6 deletions .travis/custom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ TOPDIR=$(readlink -f ${SCRIPTDIR}/..)
. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

# Sanitize arguments (see https://github.com/tox-dev/tox/issues/1463):
ENVPYTHON=$(readlink -f $1)
SYSPYTHON=$(readlink -f $2)
shift 2

# Write your custom commands here that should be run when `tox -e custom`:
if [[ -z "${TRAVIS}" ]] || lsr_check_python_version ${ENVPYTHON} -eq '3.6'; then
if [[ -z "${TRAVIS}" ]] || lsr_check_python_version python -eq '3.6'; then
(set -x; cd ${TOPDIR}/tests; ${ENVPYTHON} ./ensure_non_running_provider.py)
fi
10 changes: 2 additions & 8 deletions .travis/runblack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# is to get a user the opportunity to control black from config.sh via setting
# environment variables.

# The first script argument is a path to Python interpreter, the rest of
# arguments are passed to black.
# The given command line arguments are passed to black.

# Environment variables:
#
Expand Down Expand Up @@ -34,11 +33,6 @@ if [[ "${RUN_BLACK_DISABLED}" ]]; then
exit 0
fi

# Sanitize path in case if running within tox (see
# https://github.com/tox-dev/tox/issues/1463):
ENVPYTHON=$(readlink -f $1)
shift

DEFAULT_INCLUDE='^[^.].*\.py$'
DEFAULT_EXCLUDE='/(\.[^.].*|tests/roles)/'

Expand All @@ -64,7 +58,7 @@ while [[ $# -gt 0 ]]; do
done

set -x
${ENVPYTHON} -m black \
python -m black \
--include "${INCLUDE_ARG:-${RUN_BLACK_INCLUDE:-${DEFAULT_INCLUDE}}}" \
--exclude "${EXCLUDE_ARG:-${RUN_BLACK_EXCLUDE:-${DEFAULT_EXCLUDE}}}" \
"${OTHER_ARGS[@]}"
10 changes: 2 additions & 8 deletions .travis/runflake8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
# A shell wrapper around flake8. The purpose of this wrapper is to get to user
# an opportunity to disable running flake8 via config.sh.

# The first script argument is a path to Python interpreter, the rest of
# arguments are passed to flake8.
# The given command line arguments are passed to flake8.

# Environment variables:
#
Expand All @@ -25,10 +24,5 @@ if [[ "${RUN_FLAKE8_DISABLED}" ]]; then
exit 0
fi

# Sanitize path in case if running within tox (see
# https://github.com/tox-dev/tox/issues/1463):
ENVPYTHON=$(readlink -f $1)
shift

set -x
${ENVPYTHON} -m flake8 "$@"
python -m flake8 "$@"
10 changes: 2 additions & 8 deletions .travis/runpylint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
# which set them by including config.sh). Now, they take effect also when
# running tox locally.

# First argument to the script is a path to environment python, the rest of
# arguments are passed to custom_pylint.py.
# The given command line arguments are passed to custom_pylint.py.

set -e

Expand All @@ -20,10 +19,5 @@ SCRIPTDIR=$(readlink -f $(dirname $0))

. ${SCRIPTDIR}/config.sh

# Sanitize path in case if running within tox (see
# https://github.com/tox-dev/tox/issues/1463):
ENVPYTHON=$(readlink -f $1)
shift

set -x
${ENVPYTHON} ${SCRIPTDIR}/custom_pylint.py "$@"
python ${SCRIPTDIR}/custom_pylint.py "$@"
10 changes: 2 additions & 8 deletions .travis/runpytest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
# running pytest if there are no unit tests and filters out --cov*/--no-cov*
# arguments if there is nothing to be analyzed with coverage.

# First argument to the script is a path to environment python, the rest of
# arguments are passed to pytest.
# The given command line arguments are passed to pytest.

set -e

Expand All @@ -24,11 +23,6 @@ if [[ ! -d ${TOPDIR}/tests/unit ]]; then
exit 0
fi

# Sanitize path in case if running within tox (see
# https://github.com/tox-dev/tox/issues/1463):
ENVPYTHON=$(readlink -f $1)
shift

PYTEST_OPTS=()
PYTEST_OPTS_NOCOV=()
USE_COV=no
Expand Down Expand Up @@ -58,4 +52,4 @@ if [[ "${USE_COV}" == "no" ]]; then
fi

set -x
${ENVPYTHON} -m pytest "${PYTEST_OPTS[@]}"
python -m pytest "${PYTEST_OPTS[@]}"
15 changes: 4 additions & 11 deletions .travis/runsyspycmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
# to system python libraries, especially C bindings. The script is run with
# these arguments:
#
# $1 - path to environment python
# $2 - path to system python
# $3 - command runnable in Python (should be present in $PATH)
# ${@:4} - arguments passed to $3
# $1 - command runnable in Python (should be present in $PATH)
# ${@:2} - arguments passed to $1

set -e

Expand All @@ -19,12 +17,7 @@ TOPDIR=$(readlink -f ${SCRIPTDIR}/..)
. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

# Sanitize arguments (see https://github.com/tox-dev/tox/issues/1463):
ENVPYTHON=$(readlink -f $1)
SYSPYTHON=$(readlink -f $2)
shift 2

if ! lsr_venv_python_matches_system_python ${ENVPYTHON} ${SYSPYTHON}; then
if ! lsr_venv_python_matches_system_python ; then
lsr_info "${ME}: ${1:-<missing command>}:" \
"Environment Python has no access to system Python libraries. Skipping."
exit 0
Expand All @@ -34,4 +27,4 @@ COMMAND=$(command -v $1)
shift

set -x
${ENVPYTHON} ${COMMAND} "$@"
python ${COMMAND} "$@"
22 changes: 20 additions & 2 deletions .travis/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,33 @@ function lsr_compare_pythons() {
$(lsr_get_python_version $1) $2 $(lsr_get_python_version $3)
}

##
# lsr_get_system_python
#
# Return the system python, or /usr/bin/python3 if nothing
# else can be found in a standard location.
function lsr_get_system_python() {
local syspython=$(command -pv python3)
if [[ -z "$syspython" ]]; then
syspython=$(command -pv python)
fi
if [[ -z "$syspython" ]]; then
syspython=$(command -pv python2)
fi
echo ${syspython:-/usr/bin/python3}
}

##
# lsr_venv_python_matches_system_python [$1] [$2]
#
# $1 - command or full path to venv Python interpreter (default: python)
# $2 - command or full path to the system Python interpreter
# (default: /usr/bin/python3)
# (default: system python as determined by lsr_get_system_python())
#
# Exit with 0 if virtual environment Python version matches the system Python
# version.
function lsr_venv_python_matches_system_python() {
lsr_compare_pythons ${1:-python} -eq ${2:-/usr/bin/python3}
local syspython="${2:-$(lsr_get_system_python)}"

lsr_compare_pythons ${1:-python} -eq $syspython
}
30 changes: 14 additions & 16 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ changedir = {[base]changedir}
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {[base]runpytest} {envpython} \
bash {[base]runpytest} \
--durations=5 \
{[base]covtargets} \
--cov-report=html:htmlcov-py26 \
Expand All @@ -61,7 +61,7 @@ changedir = {[base]changedir}
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {[base]runpytest} {envpython} \
bash {[base]runpytest} \
--durations=5 \
{[base]covtargets} \
--cov-report=html:htmlcov-py27 \
Expand All @@ -79,7 +79,7 @@ changedir = {[base]changedir}
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {[base]runpytest} {envpython} \
bash {[base]runpytest} \
--durations=5 \
{[base]covtargets} \
--cov-report=html:htmlcov-py36 \
Expand All @@ -97,7 +97,7 @@ changedir = {[base]changedir}
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {[base]runpytest} {envpython} \
bash {[base]runpytest} \
--durations=5 \
{[base]covtargets} \
--cov-report=html:htmlcov-py37 \
Expand All @@ -115,7 +115,7 @@ changedir = {[base]changedir}
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {[base]runpytest} {envpython} \
bash {[base]runpytest} \
--durations=5 \
{[base]covtargets} \
--cov-report=html:htmlcov-py38 \
Expand All @@ -132,7 +132,7 @@ deps =
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {toxinidir}/.travis/runblack.sh {envpython} --check --diff .
bash {toxinidir}/.travis/runblack.sh --check --diff .

[testenv:pylint]
envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:2.7}
Expand All @@ -148,7 +148,7 @@ deps =
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {toxinidir}/.travis/runpylint.sh {envpython} --errors-only {posargs}
bash {toxinidir}/.travis/runpylint.sh --errors-only {posargs}

[testenv:flake8]
envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:2.7}
Expand All @@ -159,7 +159,7 @@ deps =
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {toxinidir}/.travis/runflake8.sh {envpython} --statistics {posargs} .
bash {toxinidir}/.travis/runflake8.sh --exclude=.venv,.tox --statistics {posargs} .

[testenv:yamllint]
deps = yamllint
Expand Down Expand Up @@ -192,10 +192,8 @@ deps =
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {[molecule_common]runsyspycmd} {envpython} {[base]system_python} \
molecule --version
bash {[molecule_common]runsyspycmd} {envpython} {[base]system_python} \
ansible --version
bash {[molecule_common]runsyspycmd} molecule --version
bash {[molecule_common]runsyspycmd} ansible --version

[testenv:molecule_lint]
envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:molecule}
Expand All @@ -204,7 +202,7 @@ deps =
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {[molecule_common]runsyspycmd} {envpython} {[base]system_python} \
bash {[molecule_common]runsyspycmd} \
molecule lint -s {env:LSR_MSCENARIO:default} {posargs}

[testenv:molecule_syntax]
Expand All @@ -214,7 +212,7 @@ deps =
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {[molecule_common]runsyspycmd} {envpython} {[base]system_python} \
bash {[molecule_common]runsyspycmd} \
molecule syntax -s {env:LSR_MSCENARIO:default} {posargs}

[testenv:molecule_test]
Expand All @@ -224,7 +222,7 @@ deps =
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {[molecule_common]runsyspycmd} {envpython} {[base]system_python} \
bash {[molecule_common]runsyspycmd} \
molecule test -s {env:LSR_MSCENARIO:default} {posargs}

[testenv:molecule]
Expand All @@ -247,7 +245,7 @@ passenv = *
whitelist_externals =
{[base]whitelist_externals}
commands =
bash {toxinidir}/.travis/custom.sh {envpython} {[base]system_python}
bash {toxinidir}/.travis/custom.sh

[pytest]
addopts = -rxs
Expand Down

0 comments on commit 56d0d76

Please sign in to comment.