"""
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 <info@intra2net.com>
"""
"""
+
+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):
"""
"""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 !
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))