Switch to Python3
authorBart Van Assche <bvanassche@acm.org>
Sun, 7 Jun 2020 19:11:03 +0000 (12:11 -0700)
committerJens Axboe <axboe@kernel.dk>
Sun, 7 Jun 2020 23:30:41 +0000 (17:30 -0600)
Support for Python2.7 in Linux distributions is being phased out. As an
example, some Linux distributions do not provide Python2.7 versions of
some of the Python packages fio Python scripts relies on. Hence switch
to Python3. Most of the Python code changes in this patch have been
generated by running the Python scripts through 2to3, the Python2 to
Python3 converter from python.org.

Notes:
- Python is only used by fio test scripts and not by fio itself.
- Older versions of RHEL / CentOS 6 do not support Python3.
  Python3 binaries for RHEL 6 / CentOS 6 are available e.g. in the EPEL
  repository (https://fedoraproject.org/wiki/EPEL).

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
t/sgunmap-perf.py
t/sgunmap-test.py
tools/fio_jsonplus_clat2csv
tools/fiologparser.py
tools/hist/fio-histo-log-pctiles.py
tools/hist/fiologparser_hist.py
tools/hist/half-bins.py
tools/plot/fio2gnuplot

index fadbb85933e61b791b8d088c3064e127e49e064b..962d187da25b9ae8fe1d9eaed035f9045cab14e2 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.7
+#!/usr/bin/env python3
 #
 # sgunmap-test.py
 #
index f8f10ab38274dfc40fbfa829673e884783903279..4960a040ea34b43e0a8cf36e5f4e03091d397d01 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.7
+#!/usr/bin/env python3
 # Note: this script is python2 and python 3 compatible.
 #
 # sgunmap-test.py
index 9544ab747ce395759933d62eb1386744d42f3905..7f310fcc473cb7f6720b96a64bf17b0993896a8c 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.7
+#!/usr/bin/env python3
 # Note: this script is python2 and python3 compatible.
 
 """
index cc29f1c7bcbf5dea4bc73a0ce8ab7cb95a00c6ae..054f1f60784879023fcc31051379a892d8adbed1 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.7
+#!/usr/bin/env python3
 # Note: this script is python2 and python 3 compatible.
 #
 # fiologparser.py
@@ -18,6 +18,7 @@ from __future__ import absolute_import
 from __future__ import print_function
 import argparse
 import math
+from functools import reduce
 
 def parse_args():
     parser = argparse.ArgumentParser()
index f9df2a3dada8d48e0bf60bf7f2d4572f168213c7..08e7722d04fe1a854a2b0aa4edcc2a194e84904d 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # module to parse fio histogram log files, not using pandas
 # runs in python v2 or v3
@@ -24,6 +24,7 @@
 import sys, os, math, copy, time
 from copy import deepcopy
 import argparse
+from functools import reduce
 
 unittest2_imported = True
 try:
@@ -82,7 +83,7 @@ def parse_hist_file(logfn, buckets_per_interval, log_hist_msec):
         except ValueError as e:
             raise FioHistoLogExc('non-integer value %s' % exception_suffix(k+1, logfn))
 
-        neg_ints = list(filter( lambda tk : tk < 0, int_tokens ))
+        neg_ints = list([tk for tk in int_tokens if tk < 0])
         if len(neg_ints) > 0:
             raise FioHistoLogExc('negative integer value %s' % exception_suffix(k+1, logfn))
 
index 8910d5fa988161f581e4ba582ced3e898b22cda3..159454b15908b9bb2bfa7c46d67c60d47dbe78a5 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.7
+#!/usr/bin/env python3
 """ 
     Utility for converting *_clat_hist* files generated by fio into latency statistics.
     
@@ -124,7 +124,7 @@ def gen_output_columns(ctx):
         columns = ["end-time", "dir", "samples", "min", "avg", "median"]
     else:
         columns = ["end-time", "samples", "min", "avg", "median"]
-    columns.extend(list(map(lambda x: x+'%', strpercs)))
+    columns.extend(list([x+'%' for x in strpercs]))
     columns.append("max")
 
 def fmt_float_list(ctx, num=1):
@@ -339,7 +339,7 @@ def guess_max_from_bins(ctx, hist_cols):
     else:
         bins = [1216,1280,1344,1408,1472,1536,1600,1664]
     coarses = range(max_coarse + 1)
-    fncn = lambda z: list(map(lambda x: z/2**x if z % 2**x == 0 else -10, coarses))
+    fncn = lambda z: list([z/2**x if z % 2**x == 0 else -10 for x in coarses])
     
     arr = np.transpose(list(map(fncn, bins)))
     idx = np.where(arr == hist_cols)
@@ -470,10 +470,7 @@ def output_interval_data(ctx,directions):
 def main(ctx):
 
     if ctx.job_file:
-        try:
-            from configparser import SafeConfigParser, NoOptionError
-        except ImportError:
-            from ConfigParser import SafeConfigParser, NoOptionError
+        from configparser import SafeConfigParser, NoOptionError
 
         cp = SafeConfigParser(allow_no_value=True)
         with open(ctx.job_file, 'r') as fp:
index 1bba8ff74802dbe8cf93cef46c77ff352b358243..42af954002c2c2068788ef68e4d15dbdecf738c4 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.7
+#!/usr/bin/env python3
 """ Cut the number bins in half in fio histogram output. Example usage:
 
         $ half-bins.py -c 2 output_clat_hist.1.log > smaller_clat_hist.1.log
index 69aa791eb6864e76d3a59c8be90cbf712cdcf369..78ee82fb8025567c1724138ca60ad25a6a4a91b1 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.7
+#!/usr/bin/env python3
 # Note: this script is python2 and python3 compatible.
 #
 #  Copyright (C) 2013 eNovance SAS <licensing@enovance.com>