From 7030e31159d6ee4fbab8ae015611a39cbcd62e2c Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Thu, 11 Jan 2018 22:26:39 -0500 Subject: [PATCH] Allow tox-install to handle base python ver Turns tox-install.sh into a proper macro allowing the user to choose which base Python version to use in the tox virtualenv. Issue: RT-50802 Change-Id: Iff578f4cfa39ce6b2540be45537931e6a3b48d22 Signed-off-by: Thanh Ha --- .jjb-test/expected-xml/gerrit-python-tox-verify-master | 16 +++++++++++++--- .jjb-test/expected-xml/gerrit-rtd-rtd-verify-master | 2 +- .jjb-test/expected-xml/github-python-tox-verify-master | 16 +++++++++++++--- .jjb-test/expected-xml/github-rtd-rtd-verify-master | 2 +- docs/jjb/lf-python-jobs.rst | 17 +++++++++++++++++ jjb/lf-python-jobs.yaml | 18 +++++++++++++++--- shell/tox-install.sh | 2 +- shell/tox-run.sh | 3 +++ 8 files changed, 64 insertions(+), 12 deletions(-) diff --git a/.jjb-test/expected-xml/gerrit-python-tox-verify-master b/.jjb-test/expected-xml/gerrit-python-tox-verify-master index c1d49569..30f27295 100644 --- a/.jjb-test/expected-xml/gerrit-python-tox-verify-master +++ b/.jjb-test/expected-xml/gerrit-python-tox-verify-master @@ -274,6 +274,11 @@ lftools --version # pipdeptree + + + PYTHON_VERSION=python3 + + #!/bin/bash # SPDX-License-Identifier: EPL-1.0 @@ -291,7 +296,7 @@ echo "---> tox-install.sh" # DO NOT set -u as virtualenv's activate script has unbound variables set -e -o pipefail -virtualenv --quiet "/tmp/v/tox" +virtualenv --quiet -p "$PYTHON_VERSION" "/tmp/v/tox" # shellcheck source=/tmp/v/tox/bin/activate disable=SC1091 source "/tmp/v/tox/bin/activate" pip install --quiet --upgrade pip @@ -300,8 +305,10 @@ pip install --quiet --upgrade argparse detox tox tox-pyenv echo "----> Pip Dependency Tree" pipdeptree - -#!/bin/bash + + + + #!/bin/bash # SPDX-License-Identifier: EPL-1.0 ############################################################################## # Copyright (c) 2017 The Linux Foundation and others. @@ -313,6 +320,9 @@ pipdeptree ############################################################################## echo "---> tox-run.sh" +# shellcheck source=/tmp/v/tox/bin/activate disable=SC1091 +source "/tmp/v/tox/bin/activate" + # Ensure we fail the job if any steps fail. # DO NOT set -u as virtualenv's activate script has unbound variables set -e -o pipefail diff --git a/.jjb-test/expected-xml/gerrit-rtd-rtd-verify-master b/.jjb-test/expected-xml/gerrit-rtd-rtd-verify-master index 0a4ba155..b47f5e3d 100644 --- a/.jjb-test/expected-xml/gerrit-rtd-rtd-verify-master +++ b/.jjb-test/expected-xml/gerrit-rtd-rtd-verify-master @@ -205,7 +205,7 @@ echo "---> tox-install.sh" # DO NOT set -u as virtualenv's activate script has unbound variables set -e -o pipefail -virtualenv --quiet "/tmp/v/tox" +virtualenv --quiet -p "$PYTHON_VERSION" "/tmp/v/tox" # shellcheck source=/tmp/v/tox/bin/activate disable=SC1091 source "/tmp/v/tox/bin/activate" pip install --quiet --upgrade pip diff --git a/.jjb-test/expected-xml/github-python-tox-verify-master b/.jjb-test/expected-xml/github-python-tox-verify-master index d04f71ea..38ac0dd2 100644 --- a/.jjb-test/expected-xml/github-python-tox-verify-master +++ b/.jjb-test/expected-xml/github-python-tox-verify-master @@ -236,6 +236,11 @@ lftools --version # pipdeptree + + + PYTHON_VERSION=python3 + + #!/bin/bash # SPDX-License-Identifier: EPL-1.0 @@ -253,7 +258,7 @@ echo "---> tox-install.sh" # DO NOT set -u as virtualenv's activate script has unbound variables set -e -o pipefail -virtualenv --quiet "/tmp/v/tox" +virtualenv --quiet -p "$PYTHON_VERSION" "/tmp/v/tox" # shellcheck source=/tmp/v/tox/bin/activate disable=SC1091 source "/tmp/v/tox/bin/activate" pip install --quiet --upgrade pip @@ -262,8 +267,10 @@ pip install --quiet --upgrade argparse detox tox tox-pyenv echo "----> Pip Dependency Tree" pipdeptree - -#!/bin/bash + + + + #!/bin/bash # SPDX-License-Identifier: EPL-1.0 ############################################################################## # Copyright (c) 2017 The Linux Foundation and others. @@ -275,6 +282,9 @@ pipdeptree ############################################################################## echo "---> tox-run.sh" +# shellcheck source=/tmp/v/tox/bin/activate disable=SC1091 +source "/tmp/v/tox/bin/activate" + # Ensure we fail the job if any steps fail. # DO NOT set -u as virtualenv's activate script has unbound variables set -e -o pipefail diff --git a/.jjb-test/expected-xml/github-rtd-rtd-verify-master b/.jjb-test/expected-xml/github-rtd-rtd-verify-master index 8a8f408d..cf393fbd 100644 --- a/.jjb-test/expected-xml/github-rtd-rtd-verify-master +++ b/.jjb-test/expected-xml/github-rtd-rtd-verify-master @@ -157,7 +157,7 @@ echo "---> tox-install.sh" # DO NOT set -u as virtualenv's activate script has unbound variables set -e -o pipefail -virtualenv --quiet "/tmp/v/tox" +virtualenv --quiet -p "$PYTHON_VERSION" "/tmp/v/tox" # shellcheck source=/tmp/v/tox/bin/activate disable=SC1091 source "/tmp/v/tox/bin/activate" pip install --quiet --upgrade pip diff --git a/docs/jjb/lf-python-jobs.rst b/docs/jjb/lf-python-jobs.rst index 624026db..a0477248 100644 --- a/docs/jjb/lf-python-jobs.rst +++ b/docs/jjb/lf-python-jobs.rst @@ -23,6 +23,21 @@ Jobs for Python projects using GitHub. - github-tox-verify + +Macros +====== + +lf-tox-install +-------------- + +Runs a shell script that installs tox in a Python virtualenv. + +:Required Parameters: + + :python-version: Base Python version to use in the virtualenv. For example + python2 or python3. + + Job Templates ============= @@ -49,6 +64,8 @@ Tox runner to verify a project :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7) :build-timeout: Timeout in seconds before aborting build. (default: 10) :git-url: URL clone project from. (default: $GIT_URL/$PROJECT) + :python-version: Version of Python to configure as a base in virtualenv. + (default: python3) :stream: Keyword representing a release code-name. Often the same as the branch. (default: master) :submodule-recursive: Whether to checkout submodules recursively. diff --git a/jjb/lf-python-jobs.yaml b/jjb/lf-python-jobs.yaml index 4011822f..81f681bc 100644 --- a/jjb/lf-python-jobs.yaml +++ b/jjb/lf-python-jobs.yaml @@ -17,6 +17,17 @@ jobs: - github-tox-verify +########## +# Macros # +########## + +- builder: + name: lf-infra-tox-install + builders: + - inject: + properties-content: 'PYTHON_VERSION={python-version}' + - shell: !include-raw-escape: ../shell/tox-install.sh + ############## # Tox Verify # ############## @@ -32,6 +43,7 @@ build-days-to-keep: 7 build-timeout: 10 git-url: '$GIT_URL/$GERRIT_PROJECT' + python-version: python3 stream: master submodule-recursive: true tox-dir: '' @@ -70,9 +82,9 @@ # Without running the install first the run in the publisher will fail # due to missing lftools because it gets installed into a tox venv. - ../shell/lftools-install.sh - - shell: !include-raw-escape: - - ../shell/tox-install.sh - - ../shell/tox-run.sh + - lf-infra-tox-install: + python-version: '{python-version}' + - shell: !include-raw-escape: ../shell/tox-run.sh publishers: - lf-infra-publish diff --git a/shell/tox-install.sh b/shell/tox-install.sh index f7f9a9c5..652043bd 100644 --- a/shell/tox-install.sh +++ b/shell/tox-install.sh @@ -14,7 +14,7 @@ echo "---> tox-install.sh" # DO NOT set -u as virtualenv's activate script has unbound variables set -e -o pipefail -virtualenv --quiet "/tmp/v/tox" +virtualenv --quiet -p "$PYTHON_VERSION" "/tmp/v/tox" # shellcheck source=/tmp/v/tox/bin/activate disable=SC1091 source "/tmp/v/tox/bin/activate" pip install --quiet --upgrade pip diff --git a/shell/tox-run.sh b/shell/tox-run.sh index 0eae0f18..dd676999 100644 --- a/shell/tox-run.sh +++ b/shell/tox-run.sh @@ -10,6 +10,9 @@ ############################################################################## echo "---> tox-run.sh" +# shellcheck source=/tmp/v/tox/bin/activate disable=SC1091 +source "/tmp/v/tox/bin/activate" + # Ensure we fail the job if any steps fail. # DO NOT set -u as virtualenv's activate script has unbound variables set -e -o pipefail -- 2.16.6