Allow specify py version for make_dist
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 28 Jan 2019 08:26:13 +0000 (09:26 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 7 Feb 2019 15:53:34 +0000 (16:53 +0100)
make_dist.py had assumed that py3.3 and py3.6 are installed on local machine.
Document that assumption and allow to deviate from it

make_dist.py

index d5df1a2..06b1e9b 100755 (executable)
@@ -1,13 +1,17 @@
 #!/usr/bin/env python3
 
 """
-Create rpm packages of pyi2ncommon for autotest (py3.6) and i2n system (py 3.3).
+Create rpm packages of pyi2ncommon for various python versions.
 
-Calls setup.py with different args. Add %check section to .spec file
+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.
 
-Accidentally stumbled of this: it appears that setting install-lib to
-/usr/lib/pythonVERSION/site-packages is translated by setup.py to installation
-requirement python(abi) = VERSION
+Calls setup.py with different args. Adds %check section to .spec file
+
+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
 
 .. codeauthor:: Intra2net AG <info@intra2net.com>
 """
@@ -75,6 +79,15 @@ def create_rpm(py_version):
     """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   !
@@ -149,7 +162,16 @@ def main():
 
     see module doc for more info
     """
-    for filename in (create_rpm('3.3'), create_rpm('3.6'), create_spec()):
+    if len(sys.argv) > 1:
+        versions = sys.argv[1:]
+    else:
+        versions = ['3.3', '3.6']
+    files_created = []
+    for version in versions:
+        files_created.append(create_rpm(version))
+    files_created.append(create_spec())
+
+    for filename in files_created:
         print('Created {}'.format(filename))
     return 0