Skip to content
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

Synchronize files from linux-system-roles/template #133

Closed
wants to merge 7 commits 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
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
---
dist: xenial
tyll marked this conversation as resolved.
Show resolved Hide resolved
language: python
env:
global:
- LSR_ANSIBLES='ansible==2.6.* ansible==2.7.* ansible==2.8.*'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this configured in travis.yml and not in config.sh? In case somone wants to run molecule outside of travis, this needs to be defined as well, doesn't it? This also affects the variable on the next line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.sh should contain only parts that may vary across repositories. Running molecule outside Travis can be performed via LSR_ANSIBLE_DEP=<ansible-dep> LSR_MSCENARIO=<molecule scenario> tox -e molecule (just tox -e molecule runs molecule with the newest Ansible Python package installed and with the default scenario). Furthermore, running molecule for all supported Ansible versions and for all supported scenarios outside of Travis by one command will be imho possible only by introducing a shell script that wraps tox command (this possibility is worth of discussion). Maybe it should be good to write a documentation for our Travis and tox based CI and put it to file named like TOX.INI.README.md.

- LSR_MSCENARIOS='default'
matrix:
include:
- python: 2.6
Expand All @@ -10,7 +14,7 @@ matrix:
- python: 3.5
- python: 3.6
- python: 3.7
- python: 3.7-dev
- python: 3.8
- python: 3.8-dev

services:
Expand Down
62 changes: 60 additions & 2 deletions .travis/config.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,62 @@
# SPDX-License-Identifier: MIT
export LSR_MOLECULE_DEPS='-rmolecule_requirements.txt'
#
# Use this file to specify custom configuration for a project. Generally, this
# involves the modification of the content of LSR_* environment variables, see
#
# * .travis/preinstall:
#
# - LSR_EXTRA_PACKAGES
#
# * .travis/runtox:
#
# - LSR_ANSIBLES
# - LSR_MSCENARIOS
#
# * .travis/runcoveralls.sh:
#
# - LSR_PUBLISH_COVERAGE
#
# Environment variables that not start with LSR_* but have influence on CI
# process:
#
# * run_pylint.py:
#
# - RUN_PYLINT_INCLUDE
# - RUN_PYLINT_EXCLUDE
# - RUN_PYLINT_DISABLED
#
# * .travis/runblack.sh:
#
# - RUN_BLACK_INCLUDE
# - RUN_BLACK_EXCLUDE
# - RUN_BLACK_DISABLED
#
# * .travis/runflake8.sh:
#
# - RUN_FLAKE8_DISABLED
#

LSR_EXTRA_PACKAGES='python3-selinux'
# Allow publishing coverage reports:
export LSR_PUBLISH_COVERAGE=yes

##
# lsr_runcoveralls_hook ARGS
#
# ARGS - see .travis/runcoveralls.sh
#
# Called from .travis/runcoveralls.sh.
function lsr_runcoveralls_hook() {
# Add custom commands here.
return 0
}

##
# lsr_runsyspycmd_hook ARGS
#
# ARGS - see .travis/runsyspycmd.sh
#
# Called from .travis/runsyspycmd.sh.
function lsr_runsyspycmd_hook() {
# Add custom commands here.
return 0
}
1 change: 0 additions & 1 deletion .travis/custom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ME=$(basename $0)
SCRIPTDIR=$(readlink -f $(dirname $0))
TOPDIR=$(readlink -f ${SCRIPTDIR}/..)

# Include library and config:
. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

Expand Down
13 changes: 0 additions & 13 deletions .travis/fix-coverage.sh

This file was deleted.

28 changes: 20 additions & 8 deletions .travis/preinstall
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

set -ex
# Install package specified by user in LSR_EXTRA_PACKAGES. Executed by Travis
# during before_install phase.
#
# LSR_EXTRA_PACKAGES, set by user in .travis/config.sh, is a space separated
# list of packages to be installed on the Travis build environment (Ubuntu).

SCRIPTDIR=$(dirname $0)
CONFIG=${SCRIPTDIR}/config.sh
set -e

if [[ -f ${CONFIG} ]]; then
. ${CONFIG}
SCRIPTDIR=$(readlink -f $(dirname $0))

. ${SCRIPTDIR}/utils.sh

# Add python3-selinux package (needed by Molecule on selinux enabled systems,
# because Molecule is using `copy` and `file` Ansible modules to setup the
# container).
if lsr_compare_pythons python -eq /usr/bin/python3; then
LSR_EXTRA_PACKAGES='python3-selinux'
fi

. ${SCRIPTDIR}/config.sh

# Install extra dependencies.
if [[ "${LSR_EXTRA_PACKAGES}" ]]; then
set -x
sudo apt-get update
for P in ${LSR_EXTRA_PACKAGES}; do
sudo apt-get install -y ${P} || :
done
sudo apt-get install -y ${LSR_EXTRA_PACKAGES}
fi
66 changes: 66 additions & 0 deletions .travis/runblack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

# Run black (the Python formatter). The first script argument is a path to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add the reason why we need this wrapper to the comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #145.

# Python interpreter, the rest of arguments are passed to black.

# Environment variables:
#
# RUN_BLACK_INCLUDE
# a regular expression specifying files to be included; can be overridden
# from command line by --include;
#
# RUN_BLACK_EXCLUDE
# a regular expression specifying files to be excluded; can be overridden
# from command line by --exclude;
#
# RUN_BLACK_DISABLED
# if set to an arbitrary non-empty value, black will be not executed

set -e

ME=$(basename $0)
SCRIPTDIR=$(readlink -f $(dirname $0))

. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

if [[ "${RUN_BLACK_DISABLED}" ]]; then
lsr_info "${ME}: black is disabled. Skipping."
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)/'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to run black for the python scripts in the tests dir as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python scripts in tests/ should be analyzed by black. The tests/roles part of regexp excludes directory containing symlinks.


INCLUDE_ARG=""
EXCLUDE_ARG=""
OTHER_ARGS=()

while [[ $# -gt 0 ]]; do
case "$1" in
--include)
shift
INCLUDE_ARG="$1"
;;
--exclude)
shift
EXCLUDE_ARG="$1"
;;
*)
OTHER_ARGS+=( "$1" )
;;
esac
shift
done

set -x
${ENVPYTHON} -m black \
--include "${INCLUDE_ARG:-${RUN_BLACK_INCLUDE:-${DEFAULT_INCLUDE}}}" \
--exclude "${EXCLUDE_ARG:-${RUN_BLACK_EXCLUDE:-${DEFAULT_EXCLUDE}}}" \
"${OTHER_ARGS[@]}"
63 changes: 63 additions & 0 deletions .travis/runcoveralls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

# Report coverage results using coveralls. The script is executed with these
# parameters:
#
# $1 - path to environment python
# $2 - path to system python
#
# coveralls is executed only if $1 coincides with $2 and $1's environment is
# stable, i.e. TRAVIS_PYTHON_VERSION is of the form [:digit:] "." [:digit:]
# (this prevents running coveralls more then once in the case if both X.Y and
# X.Y-dev coincides with system python which version is also X.Y). The results
# are reported only if LSR_PUBLISH_COVERAGE is non-empty.

set -e

ME=$(basename $0)
SCRIPTDIR=$(readlink -f $(dirname $0))
TOPDIR=$(readlink -f ${SCRIPTDIR}/..)

. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

# Run user defined hook from .travis/config.sh.
lsr_runcoveralls_hook "$@"

# Publish the results only if it is desired.
if [[ -z "${LSR_PUBLISH_COVERAGE}" ]]; then
lsr_info "${ME}: Publishing coverage report is not enabled. Skipping."
exit 0
fi

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

if lsr_compare_pythons ${ENVPYTHON} -ne ${SYSPYTHON}; then
lsr_info "${ME}:" \
"Environment Python has no access to system Python libraries. Skipping."
exit 0
fi

if [[ ! "${TRAVIS_PYTHON_VERSION}" =~ ^[[:digit:]]\.[[:digit:]]$ ]]; then
lsr_info "${ME}: Not stable environment. Skipping."
exit 0
fi

COVERALLSCMD=$(command -v coveralls)

# Fix coverage.
cat > ${TOPDIR}/.coveragerc <<EOF
[paths]
source =
.
${TOPDIR}
EOF
mv ${TOPDIR}/.coverage ${TOPDIR}/.coverage.merge || :
${ENVPYTHON} -m coverage combine --append ${TOPDIR} || :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tyll can you please review the Coveralls bits?


set -x
${ENVPYTHON} ${COVERALLSCMD}
31 changes: 31 additions & 0 deletions .travis/runflake8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

# Run flake8. The first script argument is a path to Python interpreter, the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add the reason why we need this wrapper to the comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #147.

# rest of arguments are passed to flake8.

# Environment variables:
#
# RUN_FLAKE8_DISABLED
# if set to an arbitrary non-empty value, flake8 will be not executed

set -e

ME=$(basename $0)
SCRIPTDIR=$(readlink -f $(dirname $0))

. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

if [[ "${RUN_FLAKE8_DISABLED}" ]]; then
lsr_info "${ME}: flake8 is disabled. Skipping."
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 "$@"
54 changes: 54 additions & 0 deletions .travis/runpytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

# Wrapper around pytest. First argument is a path to environment python, the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add the reason why we need this wrapper to the comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #144.

# rest of arguments are passed to pytest.

set -e

ME=$(basename $0)
SCRIPTDIR=$(readlink -f $(dirname $0))
TOPDIR=$(readlink -f ${SCRIPTDIR}/..)

. ${SCRIPTDIR}/utils.sh

if [[ ! -d ${TOPDIR}/tests/unit ]]; then
lsr_info "${ME}: No unit tests found. Skipping."
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

# Filter out coverage options if there is nothing to be analyzed with coverage.
while [[ $# -gt 0 ]]; do
case "$1" in
--cov=*)
if [[ "${1:6}" && -d "${1:6}" ]]; then
USE_COV=yes
PYTEST_OPTS+=( "$1" )
fi
;;
--cov*|--no-cov*)
PYTEST_OPTS+=( "$1" )
;;
*)
PYTEST_OPTS+=( "$1" )
PYTEST_OPTS_NOCOV+=( "$1" )
;;
esac
shift
done

if [[ "${USE_COV}" == "no" ]]; then
PYTEST_OPTS=( "${PYTEST_OPTS_NOCOV[@]}" )
fi

set -x
${ENVPYTHON} -m pytest "${PYTEST_OPTS[@]}"
Loading