From 198c21681c1aa39a928c87bef2da7732c6f5eb54 Mon Sep 17 00:00:00 2001 From: Jiri Kucera Date: Wed, 27 Nov 2019 18:21:22 +0100 Subject: [PATCH 1/5] molecule: Add SPDX identifier --- molecule/default/Dockerfile.j2 | 1 + molecule/default/molecule.yml | 1 + molecule/default/yamllint.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 index 0a60553..7e0b78d 100644 --- a/molecule/default/Dockerfile.j2 +++ b/molecule/default/Dockerfile.j2 @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: MIT # Molecule managed {% if item.registry is defined %} diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 066964a..86e9115 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: MIT --- dependency: name: galaxy diff --git a/molecule/default/yamllint.yml b/molecule/default/yamllint.yml index e00a5a9..49378c9 100644 --- a/molecule/default/yamllint.yml +++ b/molecule/default/yamllint.yml @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: MIT --- extends: default rules: From 6b241e707aae75f56e05e7f9da8c053378415315 Mon Sep 17 00:00:00 2001 From: Jiri Kucera Date: Wed, 27 Nov 2019 18:22:34 +0100 Subject: [PATCH 2/5] molecule/yamllint: Enable line-length check --- molecule/default/yamllint.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/molecule/default/yamllint.yml b/molecule/default/yamllint.yml index 49378c9..14e4519 100644 --- a/molecule/default/yamllint.yml +++ b/molecule/default/yamllint.yml @@ -8,6 +8,5 @@ rules: brackets: max-spaces-inside: 1 level: error - line-length: disable truthy: disable document-start: disable From 7145d894a492b0dc7801c2489b908fbdcf63625e Mon Sep 17 00:00:00 2001 From: Till Maas Date: Wed, 27 Nov 2019 18:36:45 +0100 Subject: [PATCH 3/5] tox: Support pylint extra requirements --- pylint_extra_requirements.txt | 3 +++ tox.ini | 1 + 2 files changed, 4 insertions(+) create mode 100644 pylint_extra_requirements.txt diff --git a/pylint_extra_requirements.txt b/pylint_extra_requirements.txt new file mode 100644 index 0000000..8d280fc --- /dev/null +++ b/pylint_extra_requirements.txt @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: MIT + +# Write extra requirements for running pylint here: diff --git a/tox.ini b/tox.ini index 39a1ad9..8b2b748 100644 --- a/tox.ini +++ b/tox.ini @@ -122,6 +122,7 @@ deps = colorama pylint>=1.8.4 ansible + -rpylint_extra_requirements.txt commands = {envpython} ./run_pylint.py --errors-only {posargs} From 213bd36bf33f0a37e9ada472312c8f85bf6b8b7b Mon Sep 17 00:00:00 2001 From: Till Maas Date: Wed, 27 Nov 2019 19:19:06 +0100 Subject: [PATCH 4/5] Travis: Add shell library --- .travis/utils.sh | 136 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 .travis/utils.sh diff --git a/.travis/utils.sh b/.travis/utils.sh new file mode 100644 index 0000000..3da971b --- /dev/null +++ b/.travis/utils.sh @@ -0,0 +1,136 @@ +# SPDX-License-Identifier: MIT +# +# Auxiliary functions and variables. +# +# Usage: . utils.sh + +# All variables prefixed with __lsr_ are internal. + +# Code that prints the version of Python interpreter to standard output; it +# should be compatible across Python 2 and Python 3, the version is printed as +# "{major}.{minor}". +__lsr_get_python_version_py=' +import sys + +sys.stdout.write("%s.%s\n" % sys.version_info[:2]) +' + +# Colors for lsr_banner, lsr_info, and lsr_error. +__lsr_color_reset='\e[0m' +__lsr_color_red='\e[31m' +__lsr_color_blue='\e[34m' +__lsr_color_yellow='\e[1;33m' + +## +# lsr_banner $1 [$2] +# +# $1 - banner text +# $2 - number of columns to occupy (default: 79) +# +# Print banner (in yellow) with $1 to stdout. +function lsr_banner() { + local maxlen=${2:-79} + local fillchar='_' + local text=" ${1} " + local fillsize=$(( ${maxlen} - ${#text} )) + local line1 + local line2 + + if [[ ${fillsize} -lt 0 ]]; then + maxlen=${#text} + fillsize=0 + fi + + line1=$(printf "%*s" ${maxlen} "" | tr " " "${fillchar}") + + if [[ $(( ${fillsize} % 2 )) -eq 1 ]]; then + text="${text} " + fi + + line2=$(printf "%*s" $(( ${fillsize} / 2 )) "" | tr " " "${fillchar}") + line2="${line2}${text}${line2}" + + echo -e "${__lsr_color_yellow}${line1}${__lsr_color_reset}" + echo -e "${__lsr_color_yellow}${line2}${__lsr_color_reset}" +} + +## +# lsr_info ARGS +# +# Print ARGS (in blue) to stdout. +function lsr_info() { + echo -e "${__lsr_color_blue}$*${__lsr_color_reset}" +} + +## +# lsr_error ARGS +# +# Print ARGS (in red) to stderr and exit with exit code 1. +function lsr_error() { + echo -e "${__lsr_color_red}$*${__lsr_color_reset}" >&2 + exit 1 +} + +## +# lsr_get_python_version $1 +# +# $1 - command or full path to Python interpreter +# +# If $1 is installed, return its version. +function lsr_get_python_version() { + if command -v $1 >/dev/null 2>&1; then + $1 -c "${__lsr_get_python_version_py}" + fi +} + +## +# lsr_compare_versions $1 $2 $3 +# +# $1 - version string (see notes below) +# $2 - binary operation (see TEST(1)) +# $3 - version string (see notes below) +# +# Exit with 0 if `$1 $2 $3`. +# +# Notes: +# A version string is of the format [:digit:] "." [:digit:]. +function lsr_compare_versions() { + if [[ $# -lt 3 ]]; then + return 1 + fi + + test ${1//./} $2 ${3//./} +} + +## +# lsr_check_python_version $1 $2 $3 +# +# $1 - command or full path to Python interpreter +# $2 - binary operation (see TEST(1)) +# $3 - version string in [:digit:] "." [:digit:] format. +# +# Exit with 0 if `version($1) $2 $3`. +function lsr_check_python_version() { + if [[ $# -lt 3 ]]; then + return 1 + fi + + lsr_compare_versions $(lsr_get_python_version $1) $2 $3 +} + +## +# lsr_compare_pythons $1 $2 $3 +# +# $1 - command or full path to Python interpreter +# $2 - binary operation (see TEST(1)) +# $3 - command or full path to Python interpreter +# +# Exit with 0 if `version($1) $2 version($3)`. +function lsr_compare_pythons() { + if [[ $# -lt 3 ]]; then + return 1 + fi + + lsr_compare_versions \ + $(lsr_get_python_version $1) $2 $(lsr_get_python_version $3) +} From 6cf9124ce20d8720cf093d6c447f1ef4f691e6c0 Mon Sep 17 00:00:00 2001 From: Till Maas Date: Wed, 27 Nov 2019 19:08:03 +0100 Subject: [PATCH 5/5] tox: Rename extra to custom --- .travis/config.sh | 9 ------- .travis/custom.sh | 28 ++++++++++++++++++++++ custom_requirements.txt | 4 ++++ tox.ini | 53 +++++++++++++---------------------------- 4 files changed, 48 insertions(+), 46 deletions(-) create mode 100755 .travis/custom.sh create mode 100644 custom_requirements.txt diff --git a/.travis/config.sh b/.travis/config.sh index 5394e86..b7aea8e 100644 --- a/.travis/config.sh +++ b/.travis/config.sh @@ -2,12 +2,3 @@ export LSR_MOLECULE_DEPS='-rmolecule_requirements.txt' LSR_EXTRA_PACKAGES='python3-selinux' - -case "${TRAVIS_PYTHON_VERSION}" in - 3.6|"") - # Set these also if we are running locally: - export LSR_TEXTRA_DEPS='PyYAML' - export LSR_TEXTRA_DIR='tests' - export LSR_TEXTRA_CMD='./ensure_non_running_provider.py' - ;; -esac diff --git a/.travis/custom.sh b/.travis/custom.sh new file mode 100755 index 0000000..115fc85 --- /dev/null +++ b/.travis/custom.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT + +# This script is executed with two arguments passed to it: +# +# $1 - path to environment python (python used inside virtual environment +# created by tox) +# $2 - path to system python (python 3.x installed on the system) + +set -e + +ME=$(basename $0) +SCRIPTDIR=$(readlink -f $(dirname $0)) +TOPDIR=$(readlink -f ${SCRIPTDIR}/..) + +# Include library and config: +. ${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 + (set -x; cd ${TOPDIR}/tests; ${ENVPYTHON} ./ensure_non_running_provider.py) +fi diff --git a/custom_requirements.txt b/custom_requirements.txt new file mode 100644 index 0000000..9f34ef0 --- /dev/null +++ b/custom_requirements.txt @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: MIT + +# Write requirements for running your custom commands in tox here: +PyYAML diff --git a/tox.ini b/tox.ini index 8b2b748..e99dc23 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = black, pylint, flake8, py{26,27,36,37,38}, - extra + custom skipsdist = true skip_missing_interpreters = true @@ -17,6 +17,7 @@ deps = py26: pytest [base] +system_python = /usr/bin/python3 passenv = * setenv = PYTHONPATH = {toxinidir}/library:{toxinidir}/module_utils @@ -24,6 +25,8 @@ setenv = changedir = {toxinidir}/tests covtarget = {toxinidir}/library --cov {toxinidir}/module_utils pytesttarget = . +whitelist_externals = + bash [testenv:py26] envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:2.6} @@ -197,39 +200,15 @@ commands = {[testenv:molecule_syntax]commands} {[testenv:molecule_test]commands} -# Here we provide a way how a role can add its custom command to be run. Such -# extra command is run at the end of each testenv run and is driven by -# environment variables. Involved environment variables are: -# -# LSR_TEXTRA_DEPS -# - contains dependency needed by commands to run smoothly; if more than -# one dependency is needed, use external file together with '-r' option -# (see PEP 508) -# -# LSR_TEXTRA_DIR -# - directory to which to cd -# -# LSR_TEXTRA_CMD -# - custom command to be run -# -# Example: `network` system role need to run `./tests/ensure_non_running_provider.py` -# to check for the existence of `*_provider.yml` playbooks. The script -# is run in Python 3.6. -# -# To make this possible, we add to `.travis/config.sh` a snippet: -# -# export LSR_TEXTRA_DEPS='PyYAML' -# export LSR_TEXTRA_DIR='tests' -# export LSR_TEXTRA_CMD='./ensure_non_running_provider.py' -# -[testenv:extra] -envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:extra} +[testenv:custom] +envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:custom} deps = - {env:LSR_TEXTRA_DEPS:} + -rcustom_requirements.txt passenv = * -changedir = {toxinidir}/{env:LSR_TEXTRA_DIR:.} +whitelist_externals = + {[base]whitelist_externals} commands = - {env:LSR_TEXTRA_CMD:python --version} + bash {toxinidir}/.travis/custom.sh {envpython} {[base]system_python} [pytest] addopts = -rxs @@ -248,9 +227,9 @@ max-line-length = 88 [travis] python = - 2.6: py26,extra - 2.7: py27,flake8,pylint,extra - 3.5: coveralls,molecule,extra - 3.6: py36,black,extra - 3.7: py37,extra - 3.8: py38,extra + 2.6: py26,custom + 2.7: py27,flake8,pylint,custom + 3.5: coveralls,molecule,custom + 3.6: py36,black,custom + 3.7: py37,custom + 3.8: py38,custom