From 783a19b74fe683bce8ba66cab051e06cf5070fa7 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Tue, 12 Feb 2019 10:20:54 +0100 Subject: [PATCH] Run unittests in make_dist.py; update doc --- make_dist.py | 61 +++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 44 insertions(+), 17 deletions(-) diff --git a/make_dist.py b/make_dist.py index cf4fb48..6b99299 100755 --- a/make_dist.py +++ b/make_dist.py @@ -3,17 +3,20 @@ """ Create rpm packages of pyi2ncommon for various python versions. -Per default try building for autotest (py3.6) and i2n system (py 3.3). Can -deviate from this by calling `./make_dist.py 3.4` (for example). All python -versions used must be installed on local machine. +Usage:: -Calls setup.py with different args. Adds %check section to .spec file + make_dist.py [RELEASE [PY_VERSION_1 [PY_VERSION_2 ...]]] -This script relies on one feature I accidentally stumbled over: it appears that -setting install-lib to /usr/lib/pythonVERSION/site-packages is translated by -setup.py to installation requirement python(abi) = VERSION +RELEASE defaults to current git commit hash, default versions to build for are +3.6 for avocado and 3.3 for i2n system. All python versions used must be +installed on local machine. + +Calls setup.py with different args. Adds %check section to .spec file. Runs +unittests first. -TODO: allow modification of release string from cmd line args (e.g. "testing") +This script relies on one feature I accidentally stumbled over: it appears that +setting install-lib to /usr/lib/python{VERSION}/site-packages is translated by +setup.py to installation requirement python(abi) = {VERSION} .. codeauthor:: Intra2net AG """ @@ -47,6 +50,37 @@ PYTHONPATH=./src:$PYTHONPATH && python3 -m unittest discover test """ + +def check_py_version(py_version): + """Test that python version is installed.""" + try: + result = call(['python{}'.format(py_version), '--version']) + except Exception: + result = 1 + if result != 0: + raise RuntimeError('Python version {} not installed, ' + 'run {} VERSION'.format(py_version, sys.argv[0])) + + +def run_unittests(py_version): + """Run unittests with given python version. Re-Run with LANG=C.""" + # Run twice: first with environment copied from call (env=None) and one + # in empoverished environment without unicode capability + for env in None, dict(LANG='C', PATH=os.environ['PATH']): + try: + print('Running unittests with python {} and env={}' + .format(py_version, env)) + result = call(['python{}'.format(py_version), '-m', 'unittest', + 'discover'], env=env) + except Exception as exc: + raise RuntimeError('Unittests with python {} and env={} failed. {}' + .format(py_version, env, exc)) + if result != 0: + raise RuntimeError('Unittests with python {} and env={} failed ' + '(command returned {}).' + .format(py_version, env, result)) + + def run_setup(command, cmd_line_args=None, install_options=None, need_zip35=False): """ @@ -85,15 +119,6 @@ def create_rpm(py_version, release): """Create rpm that will install pyi2ncommon for given python version.""" print('Creating RPM for python version {}'.format(py_version)) - # test that python version is installed - try: - result = call(['python{}'.format(py_version), '--version']) - except Exception: - result = 1 - if result != 0: - raise RuntimeError('Python version {} not installed, ' - 'run {} VERSION'.format(py_version, sys.argv[0])) - # define options for where to install library; # It appears this is automatically translated into requirement # python(abi) = version ! @@ -195,6 +220,8 @@ def main(): py_versions = sys.argv[2:] files_created = [] for py_version in py_versions: + check_py_version(py_version) + run_unittests(py_version) files_created.append(create_rpm(py_version, release)) files_created.append(create_spec(release)) -- 1.7.1